// File: /workspace/github_c_makefile_star2_O1/takoeight0821[P]hoc_nyan/src/main.c
// Function: main
int main(int argc, char** argv)
{
  bool dump = false;
  bool use_ir = false;

  int opt;
  while ((opt = getopt(argc, argv, "di")) != -1) {
    switch (opt) {
    case 'd':
      dump = true;
      break;
    case 'i':
      use_ir = true;
      break;
    default:
      error("Usage: %s [-d] [-i] filename\n", argv[0]);
    }
  }

  char* path = format("%s/%s", dirname(format("%s", argv[optind])), basename(format("%s", argv[optind])));

  Token* tokens = lex(path);

  if (dump) {
    for (Token* t = tokens; t != NULL; t = t->next) {
      dump_token(t);
    }
    eprintf("\n");
  }

  tokens = preprocess(dirname(format("%s", path)), tokens);

  if (dump) {
    for (Token* t = tokens; t != NULL; t = t->next) {
      dump_token(t);
    }
    eprintf("\n");
  }

  Program* prog = parse(tokens);
  sema(prog);

  if (dump) {
    for (size_t i = 0; i < prog->funcs->length; i++) {
      dump_function(prog->funcs->ptr[i]);
    }
  }

  if (use_ir) {
    IProgram* iprog = gen_ir(prog);
    eprintf("%s\n", show_iprog(iprog));
    alloc_regs(iprog);
    eprintf("%s\n", show_iprog(iprog));
    gen_x86(iprog);
  } else {
    emit_x86(prog);
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl %edi, %ebp
xorl %r12d, %r12d
leaq 0x4974(%rip), %r14      # 0xe40a
xorl %r13d, %r13d
movl %r13d, %ecx
movl %ecx, %r13d
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2160
movb $0x1, %cl
cmpl $0x64, %eax
je 0x9a9c
cmpl $-0x1, %eax
je 0x9ac6
cmpl $0x69, %eax
jne 0x9c54
movb $0x1, %r12b
jmp 0x9a99
movq 0x950b(%rip), %rbp      # 0x12fd8
movslq (%rbp), %rax
movq (%rbx,%rax,8), %rsi
leaq 0x558e(%rip), %r14      # 0xf06a
movq %r14, %rdi
xorl %eax, %eax
callq 0xd7f2
movq %rax, %rdi
callq 0x20b0
movq %rax, %r15
movslq (%rbp), %rax
movq (%rbx,%rax,8), %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0xd7f2
movq %rax, %rdi
callq 0x2120
leaq 0x454a(%rip), %rdi      # 0xe05c
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0xd7f2
movq %rax, %r14
movq %rax, %rdi
callq 0xce5d
movq %rax, %rbx
testb $0x1, %r13b
je 0x9b59
testq %rbx, %rbx
je 0x9b4b
movq %rbx, %r15
movq %r15, %rdi
callq 0xda5d
movq (%r15), %r15
testq %r15, %r15
jne 0x9b3b
leaq 0x596e(%rip), %rdi      # 0xf4c0
xorl %eax, %eax
callq 0x21b0
leaq 0x550a(%rip), %rdi      # 0xf06a
movq %r14, %rsi
xorl %eax, %eax
callq 0xd7f2
movq %rax, %rdi
callq 0x20b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3120
movq %rax, %rbx
testb $0x1, %r13b
je 0x9bac
testq %rbx, %rbx
je 0x9b9e
movq %rbx, %r14
movq %r14, %rdi
callq 0xda5d
movq (%r14), %r14
testq %r14, %r14
jne 0x9b8e
leaq 0x591b(%rip), %rdi      # 0xf4c0
xorl %eax, %eax
callq 0x21b0
movq %rbx, %rdi
callq 0x9f1c
movq %rax, %rbx
movq %rax, %rdi
callq 0xc5bc
testb $0x1, %r13b
je 0x9bea
movq (%rbx), %rax
cmpq $0x0, 0x10(%rax)
je 0x9bea
xorl %r14d, %r14d
movq (%rax), %rax
movq (%rax,%r14,8), %rdi
callq 0x2ec0
incq %r14
movq (%rbx), %rax
cmpq 0x10(%rax), %r14
jb 0x9bd2
movq %rbx, %rdi
testb $0x1, %r12b
je 0x9c3e
callq 0x5f32
movq %rax, %rbx
movq %rax, %rdi
callq 0x9a2e
leaq 0x58a0(%rip), %r14      # 0xf4aa
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x21b0
movq %rbx, %rdi
callq 0xc359
movq %rbx, %rdi
callq 0x9a2e
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x21b0
movq %rbx, %rdi
callq 0x7bfc
jmp 0x9c43
callq 0x39f0
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rsi
leaq 0x5550(%rip), %rdi      # 0xf1ae
xorl %eax, %eax
callq 0xd8b8
nopl (%rax)