// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
movb $0x0, -0x12(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x8904(%rip), %rdx      # 0x123e0
callq 0x2140
movl %eax, -0x18(%rbp)
cmpl $-0x1, %eax
je 0x9b23
movl -0x18(%rbp), %eax
movl %eax, -0x54(%rbp)
subl $0x64, %eax
je 0x9b00
jmp 0x9af6
movl -0x54(%rbp), %eax
subl $0x69, %eax
je 0x9b06
jmp 0x9b0c
movb $0x1, -0x11(%rbp)
jmp 0x9b21
movb $0x1, -0x12(%rbp)
jmp 0x9b21
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x96a4(%rip), %rdi      # 0x131be
movb $0x0, %al
callq 0xfb50
jmp 0x9ace
movq -0x10(%rbp), %rax
movq 0xd4aa(%rip), %rcx      # 0x16fd8
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x953e(%rip), %rdi      # 0x1307a
movb $0x0, %al
callq 0xfa70
movq %rax, %rdi
callq 0x20a0
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0xd47e(%rip), %rcx      # 0x16fd8
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x9512(%rip), %rdi      # 0x1307a
movb $0x0, %al
callq 0xfa70
movq %rax, %rdi
callq 0x2100
movq -0x60(%rbp), %rsi
movq %rax, %rdx
leaq 0x84d7(%rip), %rdi      # 0x1205c
movb $0x0, %al
callq 0xfa70
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0xedc0
movq %rax, -0x28(%rbp)
testb $0x1, -0x11(%rbp)
je 0x9bd6
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x9bc8
movq -0x30(%rbp), %rdi
callq 0xfed0
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x9bab
leaq 0x9a6d(%rip), %rdi      # 0x1363c
movb $0x0, %al
callq 0xfc00
movq -0x20(%rbp), %rsi
leaq 0x9499(%rip), %rdi      # 0x1307a
movb $0x0, %al
callq 0xfa70
movq %rax, %rdi
callq 0x20a0
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x23c0
movq %rax, -0x28(%rbp)
testb $0x1, -0x11(%rbp)
je 0x9c39
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x9c2b
movq -0x38(%rbp), %rdi
callq 0xfed0
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x9c0e
leaq 0x9a0a(%rip), %rdi      # 0x1363c
movb $0x0, %al
callq 0xfc00
movq -0x28(%rbp), %rdi
callq 0xa150
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0xd900
testb $0x1, -0x11(%rbp)
je 0x9c95
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rcx), %rcx
cmpq 0x10(%rcx), %rax
jae 0x9c93
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x10fe0
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x9c5d
jmp 0x9c95
testb $0x1, -0x12(%rbp)
je 0x9cf0
movq -0x40(%rbp), %rdi
callq 0x56b0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x9a30
movq %rax, %rsi
leaq 0x996b(%rip), %rdi      # 0x13626
movb $0x0, %al
callq 0xfc00
movq -0x50(%rbp), %rdi
callq 0xd4f0
movq -0x50(%rbp), %rdi
callq 0x9a30
movq %rax, %rsi
leaq 0x9948(%rip), %rdi      # 0x13626
movb $0x0, %al
callq 0xfc00
movq -0x50(%rbp), %rdi
callq 0x7740
jmp 0x9cf9
movq -0x40(%rbp), %rdi
callq 0x3000
xorl %eax, %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)