// File: /workspace/github_c_makefile_star2_O2/orangeduck[P]mpc/mpc.c
// Function: mpc_ast_traverse_next
mpc_ast_t *mpc_ast_traverse_next(mpc_ast_trav_t **trav) {
  mpc_ast_trav_t *n_trav, *to_free;
  mpc_ast_t *ret = NULL;
  int cchild;

  /* The end of traversal was reached */
  if(*trav == NULL) return NULL;

  switch((*trav)->order) {
    case mpc_ast_trav_order_pre:
      ret = (*trav)->curr_node;

      /* If there aren't any more children, go up */
      while(*trav != NULL &&
        (*trav)->curr_child >= (*trav)->curr_node->children_num)
      {
        to_free = *trav;
        *trav = (*trav)->parent;
        free(to_free);
      }

      /* If trav is NULL, the end was reached */
      if(*trav == NULL) {
        break;
      }

      /* Go to next child */
      n_trav = malloc(sizeof(mpc_ast_trav_t));

      cchild = (*trav)->curr_child;
      n_trav->curr_node = (*trav)->curr_node->children[cchild];
      n_trav->parent = *trav;
      n_trav->curr_child = 0;
      n_trav->order = (*trav)->order;

      (*trav)->curr_child++;
      *trav = n_trav;

      break;

    case mpc_ast_trav_order_post:
      ret = (*trav)->curr_node;

      /* Move up tree to the parent If the parent doesn't have any more nodes,
       * then this is the current node. If it does, move down to its left most
       * child. Also, free the previous traversal node */
      to_free = *trav;
      *trav = (*trav)->parent;
      free(to_free);

      if(*trav == NULL)
        break;

      /* Next child */
      (*trav)->curr_child++;

      /* If there aren't any more children, this is the next node */
      if((*trav)->curr_child >= (*trav)->curr_node->children_num) {
        break;
      }

      /* If there are still more children, find the leftmost child from this
       * node */
      while((*trav)->curr_node->children_num > 0) {
        n_trav = malloc(sizeof(mpc_ast_trav_t));

        cchild = (*trav)->curr_child;
        n_trav->curr_node = (*trav)->curr_node->children[cchild];
        n_trav->parent = *trav;
        n_trav->curr_child = 0;
        n_trav->order = (*trav)->order;

        *trav = n_trav;
      }

    default:
      /* Unreachable, but compiler complaints */
      break;
  }

  return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq (%rdi), %r15
testq %r15, %r15
je 0x942f
movq %rdi, %r14
movl 0x14(%r15), %eax
cmpl $0x1, %eax
je 0x9443
testl %eax, %eax
jne 0x942f
movq (%r15), %rbx
testq %r15, %r15
je 0x9431
movslq 0x10(%r15), %r12
movq (%r15), %r13
cmpl 0x30(%r13), %r12d
jl 0x94af
movq 0x8(%r15), %rax
movq %rax, (%r14)
movq %r15, %rdi
callq 0x4880
movq (%r14), %r15
jmp 0x9405
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %rbx
movq 0x8(%r15), %rax
movq %rax, (%r14)
movq %r15, %rdi
callq 0x4880
movq (%r14), %r12
testq %r12, %r12
je 0x9431
movslq 0x10(%r12), %rbp
incq %rbp
movl %ebp, 0x10(%r12)
movq (%r12), %r13
movl 0x30(%r13), %ecx
cmpl %ecx, %ebp
jge 0x9431
pushq $0x18
popq %r15
testl %ecx, %ecx
jle 0x9431
movq %r15, %rdi
callq 0x45a0
movq 0x38(%r13), %rcx
movq (%rcx,%rbp,8), %r13
movq %r13, (%rax)
movq %r12, 0x8(%rax)
andl $0x0, 0x10(%rax)
movl 0x14(%r12), %ecx
movl %ecx, 0x14(%rax)
movq %rax, (%r14)
movl 0x30(%r13), %ecx
xorl %ebp, %ebp
movq %rax, %r12
jmp 0x947a
pushq $0x18
popq %rdi
callq 0x45a0
movq 0x38(%r13), %rcx
movq (%rcx,%r12,8), %rcx
movq %rcx, (%rax)
movq %r15, 0x8(%rax)
andl $0x0, 0x10(%rax)
movl 0x14(%r15), %ecx
movl %ecx, 0x14(%rax)
leal 0x1(%r12), %ecx
movl %ecx, 0x10(%r15)
movq %rax, (%r14)
jmp 0x9431