// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movq (%rdi), %rdi
testq %rdi, %rdi
je 0xa1c2
movl 0x14(%rdi), %eax
cmpl $0x1, %eax
je 0xa1d3
testl %eax, %eax
jne 0xa1c2
movq (%rdi), %rbx
movq (%r14), %r15
testq %r15, %r15
sete %al
je 0xa1c4
movl 0x10(%r15), %ecx
movq (%r15), %rdx
cmpl 0x30(%rdx), %ecx
jl 0xa24a
movq 0x8(%r15), %rax
movq %rax, (%r14)
movq %r15, %rdi
callq 0x4580
jmp 0xa196
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq (%rdi), %rbx
movq 0x8(%rdi), %rax
movq %rax, (%r14)
callq 0x4580
movq (%r14), %rax
testq %rax, %rax
je 0xa1c4
movl 0x10(%rax), %ecx
incl %ecx
movl %ecx, 0x10(%rax)
movq (%rax), %rax
cmpl 0x30(%rax), %ecx
jge 0xa1c4
movq (%r14), %r15
movq (%r15), %r12
cmpl $0x0, 0x30(%r12)
jle 0xa1c4
movl $0x18, %edi
callq 0x43a0
movslq 0x10(%r15), %rcx
movq 0x38(%r12), %rdx
movq (%rdx,%rcx,8), %rcx
movq %rcx, (%rax)
movq %r15, 0x8(%rax)
movl $0x0, 0x10(%rax)
movl 0x14(%r15), %ecx
movl %ecx, 0x14(%rax)
movq %rax, (%r14)
movq (%rax), %r12
cmpl $0x0, 0x30(%r12)
movq %rax, %r15
jg 0xa208
jmp 0xa1c4
testb %al, %al
jne 0xa1c4
movl $0x18, %edi
callq 0x43a0
movslq 0x10(%r15), %rcx
movq (%r15), %rdx
movq 0x38(%rdx), %rdx
movq (%rdx,%rcx,8), %rcx
movq %rcx, (%rax)
movq %r15, 0x8(%rax)
movl $0x0, 0x10(%rax)
movl 0x14(%r15), %ecx
movl %ecx, 0x14(%rax)
incl 0x10(%r15)
movq %rax, (%r14)
jmp 0xa1c4