// File: /workspace/github_c_makefile_star2_O3/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 0x4a0c(%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 0x9a04
cmpl $-0x1, %eax
je 0x9a2e
cmpl $0x69, %eax
jne 0x9bbc
movb $0x1, %r12b
jmp 0x9a01
movq 0x95a3(%rip), %rbp      # 0x12fd8
movslq (%rbp), %rax
movq (%rbx,%rax,8), %rsi
leaq 0x55fe(%rip), %r14      # 0xf042
movq %r14, %rdi
xorl %eax, %eax
callq 0xd86a
movq %rax, %rdi
callq 0x20b0
movq %rax, %r15
movslq (%rbp), %rax
movq (%rbx,%rax,8), %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0xd86a
movq %rax, %rdi
callq 0x2120
leaq 0x45e2(%rip), %rdi      # 0xe05c
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0xd86a
movq %rax, %r14
movq %rax, %rdi
callq 0xcd11
movq %rax, %rbx
testb $0x1, %r13b
je 0x9ac1
testq %rbx, %rbx
je 0x9ab3
movq %rbx, %r15
movq %r15, %rdi
callq 0xdacd
movq (%r15), %r15
testq %r15, %r15
jne 0x9aa3
leaq 0x59e2(%rip), %rdi      # 0xf49c
xorl %eax, %eax
callq 0x21b0
leaq 0x557a(%rip), %rdi      # 0xf042
movq %r14, %rsi
xorl %eax, %eax
callq 0xd86a
movq %rax, %rdi
callq 0x20b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x311c
movq %rax, %rbx
testb $0x1, %r13b
je 0x9b14
testq %rbx, %rbx
je 0x9b06
movq %rbx, %r14
movq %r14, %rdi
callq 0xdacd
movq (%r14), %r14
testq %r14, %r14
jne 0x9af6
leaq 0x598f(%rip), %rdi      # 0xf49c
xorl %eax, %eax
callq 0x21b0
movq %rbx, %rdi
callq 0x9e40
movq %rax, %rbx
movq %rax, %rdi
callq 0xc428
testb $0x1, %r13b
je 0x9b52
movq (%rbx), %rax
cmpq $0x0, 0x10(%rax)
je 0x9b52
xorl %r14d, %r14d
movq (%rax), %rax
movq (%rax,%r14,8), %rdi
callq 0x2ec0
incq %r14
movq (%rbx), %rax
cmpq 0x10(%rax), %r14
jb 0x9b3a
movq %rbx, %rdi
testb $0x1, %r12b
je 0x9ba6
callq 0x5f18
movq %rax, %rbx
movq %rax, %rdi
callq 0x9997
leaq 0x5914(%rip), %r14      # 0xf486
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x21b0
movq %rbx, %rdi
callq 0xc1d9
movq %rbx, %rdi
callq 0x9997
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x21b0
movq %rbx, %rdi
callq 0x7b60
jmp 0x9bab
callq 0x3a20
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rsi
leaq 0x55c0(%rip), %rdi      # 0xf186
xorl %eax, %eax
callq 0xd930
nopl (%rax)