// File: /workspace/github_c_makefile_star2_O2/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 0x4ff0(%rip), %r14      # 0xc40a
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 0x7420
cmpl $-0x1, %eax
je 0x744a
cmpl $0x69, %eax
jne 0x75ca
movb $0x1, %r12b
jmp 0x741d
movq 0xab87(%rip), %rbp      # 0x11fd8
movslq (%rbp), %rax
movq (%rbx,%rax,8), %rsi
leaq 0x5c0a(%rip), %r14      # 0xd06a
movq %r14, %rdi
xorl %eax, %eax
callq 0xa84a
movq %rax, %rdi
callq 0x20b0
movq %rax, %r15
movslq (%rbp), %rax
movq (%rbx,%rax,8), %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0xa84a
movq %rax, %rdi
callq 0x2120
leaq 0x4bc6(%rip), %rdi      # 0xc05c
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0xa84a
movq %rax, %r14
movq %rax, %rdi
callq 0xa132
movq %rax, %rbx
testb $0x1, %r13b
je 0x74da
movq %rbx, %r15
testq %r15, %r15
je 0x74cc
movq %r15, %rdi
callq 0xab3a
movq (%r15), %r15
jmp 0x74ba
leaq 0x5fed(%rip), %rdi      # 0xd4c0
xorl %eax, %eax
callq 0xa9a6
leaq 0x5b89(%rip), %rdi      # 0xd06a
movq %r14, %rsi
xorl %eax, %eax
callq 0xa84a
movq %rax, %rdi
callq 0x20b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2334
movq %rax, %rbx
testb $0x1, %r13b
je 0x752a
movq %rbx, %r14
testq %r14, %r14
je 0x751c
movq %r14, %rdi
callq 0xab3a
movq (%r14), %r14
jmp 0x750a
leaq 0x5f9d(%rip), %rdi      # 0xd4c0
xorl %eax, %eax
callq 0xa9a6
movq %rbx, %rdi
callq 0x77b0
movq %rax, %rbx
movq %rax, %rdi
callq 0x98bc
testb $0x1, %r13b
je 0x7560
xorl %r14d, %r14d
movq (%rbx), %rax
cmpq 0x10(%rax), %r14
jae 0x7560
movq (%rax), %rax
movq (%rax,%r14,8), %rdi
callq 0xb27a
incq %r14
jmp 0x7546
movq %rbx, %rdi
testb $0x1, %r12b
je 0x75b4
callq 0x49f2
movq %rax, %rbx
movq %rax, %rdi
callq 0x73b9
leaq 0x5f2a(%rip), %r14      # 0xd4aa
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa9a6
movq %rbx, %rdi
callq 0x96c0
movq %rbx, %rdi
callq 0x73b9
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa9a6
movq %rbx, %rdi
callq 0x5d28
jmp 0x75b9
callq 0x2af8
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rsi
leaq 0x5bda(%rip), %rdi      # 0xd1ae
xorl %eax, %eax
callq 0xa90e
nop