// File: /workspace/github_c_makefile_star2_O3/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 0xa082
movq %rdi, %r14
movl 0x14(%r15), %eax
cmpl $0x1, %eax
je 0xa096
testl %eax, %eax
jne 0xa082
movq (%r15), %rbx
movslq 0x10(%r15), %r12
movq (%r15), %r13
cmpl 0x30(%r13), %r12d
jl 0xa113
movq 0x8(%r15), %rax
movq %rax, (%r14)
movq %r15, %rdi
callq 0x4580
movq (%r14), %r15
testq %r15, %r15
jne 0xa058
jmp 0xa084
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 0x4580
movq (%r14), %r15
testq %r15, %r15
je 0xa084
movslq 0x10(%r15), %r13
incq %r13
movl %r13d, 0x10(%r15)
movq (%r15), %r12
movl 0x30(%r12), %eax
cmpl %eax, %r13d
setge %cl
testl %eax, %eax
setle %al
orb %cl, %al
jne 0xa084
movl 0x14(%r15), %ebp
movl $0x18, %edi
callq 0x43a0
movq 0x38(%r12), %rcx
movq (%rcx,%r13,8), %r12
movq %r12, (%rax)
movq %r15, 0x8(%rax)
movl $0x0, 0x10(%rax)
movl %ebp, 0x14(%rax)
movq %rax, (%r14)
cmpl $0x0, 0x30(%r12)
movl $0x0, %r13d
movq %rax, %r15
jg 0xa0d6
jmp 0xa084
movl $0x18, %edi
callq 0x43a0
movq 0x38(%r13), %rcx
movq (%rcx,%r12,8), %rcx
movq %rcx, (%rax)
movq %r15, 0x8(%rax)
movl $0x0, 0x10(%rax)
movl 0x14(%r15), %ecx
movl %ecx, 0x14(%rax)
leal 0x1(%r12), %ecx
movl %ecx, 0x10(%r15)
movq %rax, (%r14)
jmp 0xa084