yin parser CHANGE parse augments separately and last

It has advantages for its resolution.
diff --git a/src/parser_yin.c b/src/parser_yin.c
index 47e8fed..1a0eab8 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -4469,7 +4469,7 @@
 {
     struct ly_ctx *ctx = module->ctx;
     struct lys_submodule *submodule = (struct lys_submodule *)module;
-    struct lyxml_elem *next, *child, *child2, root, grps;
+    struct lyxml_elem *next, *child, *child2, root, grps, augs;
     struct lys_node *node = NULL;
     const char *value;
     int i, r;
@@ -4480,6 +4480,7 @@
     /* init */
     memset(&root, 0, sizeof root);
     memset(&grps, 0, sizeof grps);
+    memset(&augs, 0, sizeof augs);
 
     /*
      * in the first run, we process elements with cardinality of 1 or 0..1 and
@@ -4567,6 +4568,10 @@
             c_inc++;
         } else if (!strcmp(child->name, "augment")) {
             c_aug++;
+            /* keep augments separated, processed last */
+            lyxml_unlink_elem(module->ctx, child, 1);
+            lyxml_add_child(module->ctx, &augs, child);
+
         } else if (!strcmp(child->name, "feature")) {
             c_ftrs++;
         } else if (!strcmp(child->name, "deviation")) {
@@ -4706,8 +4711,8 @@
         module->deviation = calloc(c_dev, sizeof *module->deviation);
     }
 
-    /* middle part - process nodes with cardinality of 0..n except the data nodes */
-    LY_TREE_FOR(yin->child, child) {
+    /* middle part - process nodes with cardinality of 0..n except the data nodes and augments */
+    LY_TREE_FOR_SAFE(yin->child, next, child) {
         if (!strcmp(child->name, "import")) {
             r = fill_yin_import(module, child, &module->imp[module->imp_size]);
             module->imp_size++;
@@ -4722,6 +4727,8 @@
                     goto error;
                 }
             }
+            lyxml_free_elem(ctx, child);
+
         } else if (!strcmp(child->name, "include")) {
             r = fill_yin_include(module, child, &module->inc[module->inc_size]);
             module->inc_size++;
@@ -4737,6 +4744,8 @@
                     goto error;
                 }
             }
+            lyxml_free_elem(ctx, child);
+
         } else if (!strcmp(child->name, "revision")) {
             GETVAL(value, child, "date");
             if (check_date(value, LOGLINE(child))) {
@@ -4798,6 +4807,8 @@
             }
 
             module->rev_size++;
+            lyxml_free_elem(ctx, child);
+
         } else if (!strcmp(child->name, "typedef")) {
             r = fill_yin_typedef(module, NULL, child, &module->tpdf[module->tpdf_size], unres);
             module->tpdf_size++;
@@ -4805,6 +4816,8 @@
             if (r) {
                 goto error;
             }
+            lyxml_free_elem(ctx, child);
+
         } else if (!strcmp(child->name, "identity")) {
             r = fill_yin_identity(module, child, &module->ident[module->ident_size], unres);
             module->ident_size++;
@@ -4812,6 +4825,8 @@
             if (r) {
                 goto error;
             }
+            lyxml_free_elem(ctx, child);
+
         } else if (!strcmp(child->name, "feature")) {
             r = fill_yin_feature(module, child, &module->features[module->features_size], unres);
             module->features_size++;
@@ -4819,16 +4834,8 @@
             if (r) {
                 goto error;
             }
-        } else if (!strcmp(child->name, "augment")) {
-            r = fill_yin_augment(module, NULL, child, &module->augment[module->augment_size], unres);
-            module->augment_size++;
+            lyxml_free_elem(ctx, child);
 
-            if (r) {
-                goto error;
-            }
-
-            /* node is reconnected into the augment, so we have to skip its free at the end of the loop */
-            continue;
         } else if (!strcmp(child->name, "deviation")) {
             r = fill_yin_deviation(module, child, &module->deviation[module->deviation_size]);
             module->deviation_size++;
@@ -4836,6 +4843,8 @@
             if (r) {
                 goto error;
             }
+            lyxml_free_elem(ctx, child);
+
         }
     }
 
@@ -4880,7 +4889,16 @@
         lyxml_free_elem(ctx, child);
     }
 
+    /* ... and finally augments (last, so we can augment our data, for instance) */
+    LY_TREE_FOR_SAFE(augs.child, next, child) {
+        r = fill_yin_augment(module, NULL, child, &module->augment[module->augment_size], unres);
+        module->augment_size++;
 
+        if (r) {
+            goto error;
+        }
+        lyxml_free_elem(ctx, child);
+    }
 
     return EXIT_SUCCESS;
 
@@ -4892,6 +4910,8 @@
     while (grps.child) {
         lyxml_free_elem(module->ctx, grps.child);
     }
+    while (augs.child) {
+        lyxml_free_elem(module->ctx, augs.child);
     }
 
     free(unres->item);