// File: /workspace/github_c_makefile_star2_O1/orangeduck[P]mpc/mpc.c
// Function: mpc_copy
mpc_parser_t *mpc_copy(mpc_parser_t *a) {
  int i = 0;
  mpc_parser_t *p;

  if (a->retained) { return a; }

  p = mpc_undefined();
  p->retained = a->retained;
  p->type = a->type;
  p->data = a->data;

  if (a->name) {
    p->name = malloc(strlen(a->name)+1);
    strcpy(p->name, a->name);
  }

  switch (a->type) {

    case MPC_TYPE_FAIL:
      p->data.fail.m = malloc(strlen(a->data.fail.m)+1);
      strcpy(p->data.fail.m, a->data.fail.m);
    break;

    case MPC_TYPE_ONEOF:
    case MPC_TYPE_NONEOF:
    case MPC_TYPE_STRING:
      p->data.string.x = malloc(strlen(a->data.string.x)+1);
      strcpy(p->data.string.x, a->data.string.x);
      break;

    case MPC_TYPE_APPLY:    p->data.apply.x    = mpc_copy(a->data.apply.x);    break;
    case MPC_TYPE_APPLY_TO: p->data.apply_to.x = mpc_copy(a->data.apply_to.x); break;
    case MPC_TYPE_PREDICT:  p->data.predict.x  = mpc_copy(a->data.predict.x);  break;

    case MPC_TYPE_MAYBE:
    case MPC_TYPE_NOT:
      p->data.not.x = mpc_copy(a->data.not.x);
      break;

    case MPC_TYPE_EXPECT:
      p->data.expect.x = mpc_copy(a->data.expect.x);
      p->data.expect.m = malloc(strlen(a->data.expect.m)+1);
      strcpy(p->data.expect.m, a->data.expect.m);
      break;

    case MPC_TYPE_MANY:
    case MPC_TYPE_MANY1:
    case MPC_TYPE_COUNT:
      p->data.repeat.x = mpc_copy(a->data.repeat.x);
      break;

    case MPC_TYPE_SEPBY1:
      p->data.sepby1.x   = mpc_copy(a->data.sepby1.x);
      p->data.sepby1.sep = mpc_copy(a->data.sepby1.sep);
      break;

    case MPC_TYPE_OR:
      p->data.or.xs = malloc(a->data.or.n * sizeof(mpc_parser_t*));
      for (i = 0; i < a->data.or.n; i++) {
        p->data.or.xs[i] = mpc_copy(a->data.or.xs[i]);
      }
    break;
    case MPC_TYPE_AND:
      p->data.and.xs = malloc(a->data.and.n * sizeof(mpc_parser_t*));
      for (i = 0; i < a->data.and.n; i++) {
        p->data.and.xs[i] = mpc_copy(a->data.and.xs[i]);
      }
      if (a->data.and.n > 0) {
          p->data.and.dxs = malloc((a->data.and.n-1) * sizeof(mpc_dtor_t));
          for (i = 0; i < a->data.and.n-1; i++) {
            p->data.and.dxs[i] = a->data.and.dxs[i];
          }
      }
    break;

    case MPC_TYPE_CHECK:
      p->data.check.x      = mpc_copy(a->data.check.x);
      p->data.check.e      = malloc(strlen(a->data.check.e)+1);
      strcpy(p->data.check.e, a->data.check.e);
      break;
    case MPC_TYPE_CHECK_WITH:
      p->data.check_with.x = mpc_copy(a->data.check_with.x);
      p->data.check_with.e = malloc(strlen(a->data.check_with.e)+1);
      strcpy(p->data.check_with.e, a->data.check_with.e);
      break;

    default: break;
  }


  return p;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movb 0x31(%rdi), %bpl
testb %bpl, %bpl
je 0x61fd
movq %r14, %rbx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
movl $0x38, %esi
callq 0x4280
movq %rax, %r15
movq %rax, %rbx
movb $0x0, 0x30(%rax)
movq $0x0, (%rax)
movb %bpl, 0x31(%rax)
movzbl 0x30(%r14), %ebp
movb %bpl, 0x30(%rax)
movq 0x28(%r14), %rax
movq %rax, 0x28(%r15)
movups 0x8(%r14), %xmm0
movups 0x18(%r14), %xmm1
movups %xmm1, 0x18(%r15)
movups %xmm0, 0x8(%r15)
movq (%r14), %r12
testq %r12, %r12
je 0x626d
movq %r12, %rdi
callq 0x4120
leaq 0x1(%rax), %rdi
callq 0x43a0
movq %rax, (%rbx)
movq %rax, %rdi
movq %r12, %rsi
callq 0x40b0
addl $-0x2, %ebp
cmpl $0x1b, %ebp
ja 0x61eb
addq $0x8, %r15
leaq 0x8(%r14), %r13
leaq 0x7e98(%rip), %rax      # 0xe120
movslq (%rax,%rbp,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq (%r13), %rdi
callq 0x4430
movq %rax, (%r15)
jmp 0x61eb
movq (%r13), %r14
movq %r14, %rdi
callq 0x4120
leaq 0x1(%rax), %rdi
callq 0x43a0
movq %rax, (%r15)
movq %rax, %rdi
movq %r14, %rsi
callq 0x40b0
jmp 0x61eb
movq 0x18(%r14), %rdi
callq 0x4430
movq %rax, 0x18(%rbx)
jmp 0x61eb
movslq (%r13), %r15
leaq (,%r15,8), %rdi
callq 0x43a0
movq %rax, 0x18(%rbx)
testq %r15, %r15
jle 0x6318
movq %rax, %r12
xorl %ebp, %ebp
movq 0x18(%r14), %rax
movq (%rax,%rbp,8), %rdi
callq 0x4430
movq %rax, (%r12,%rbp,8)
incq %rbp
movslq 0x8(%r14), %r15
cmpq %r15, %rbp
jl 0x62fb
testl %r15d, %r15d
jle 0x61eb
decl %r15d
shlq $0x3, %r15
movq %r15, %rdi
callq 0x43a0
movq %rax, 0x20(%rbx)
cmpl $0x2, (%r13)
jl 0x61eb
movq 0x20(%r14), %rcx
movl 0x8(%r14), %esi
cmpl $0x3, %esi
movl $0x2, %edx
cmovgel %esi, %edx
decl %edx
xorl %esi, %esi
movq (%rcx,%rsi,8), %rdi
movq %rdi, (%rax,%rsi,8)
incq %rsi
cmpq %rsi, %rdx
jne 0x6356
jmp 0x61eb
movq 0x8(%r14), %rdi
callq 0x4430
movq %rax, 0x8(%rbx)
movq 0x20(%r14), %r14
movq %r14, %rdi
callq 0x4120
leaq 0x1(%rax), %rdi
callq 0x43a0
movq %rax, 0x20(%rbx)
jmp 0x62ba
movq 0x8(%r14), %rdi
callq 0x4430
movq %rax, 0x8(%rbx)
movq 0x10(%r14), %r14
movq %r14, %rdi
callq 0x4120
leaq 0x1(%rax), %rdi
callq 0x43a0
movq %rax, 0x10(%rbx)
jmp 0x62ba
movq 0x18(%r14), %rdi
callq 0x4430
movq %rax, 0x18(%rbx)
movq 0x20(%r14), %rdi
callq 0x4430
movq %rax, 0x20(%rbx)
jmp 0x61eb
movq 0x8(%r14), %rdi
callq 0x4430
movq %rax, 0x8(%rbx)
movq 0x28(%r14), %r14
movq %r14, %rdi
callq 0x4120
leaq 0x1(%rax), %rdi
callq 0x43a0
movq %rax, 0x28(%rbx)
jmp 0x62ba
movslq (%r13), %r12
leaq (,%r12,8), %rdi
callq 0x43a0
movq %rax, 0x10(%rbx)
testq %r12, %r12
jle 0x61eb
movq %rax, %r15
xorl %r12d, %r12d
movq 0x10(%r14), %rax
movq (%rax,%r12,8), %rdi
callq 0x4430
movq %rax, (%r15,%r12,8)
incq %r12
movslq 0x8(%r14), %rax
cmpq %rax, %r12
jl 0x642f
jmp 0x61eb