// File: /workspace/github_c_makefile_star2_O2/sisshiki1969[P]monocc/src/monocc.c
// Function: compile
void compile(char *file) {
  ty_int.ty = INT;
  ty_uint.ty = UINT;
  ty_short.ty = SHORT;
  ty_ushort.ty = USHORT;
  ty_long.ty = LONG;
  ty_ulong.ty = ULONG;
  ty_char.ty = CHAR;
  ty_bool.ty = BOOL;
  ty_void.ty = VOID;

  char *s = "__builtin_va_start";
  Token *t = create_token(TK_IDENT, s, strlen(s));
  Function *f = new_func(t, new_type_func(new_type_void()), NULL);
  f->type->variadic = true;

  tokenize(file, source_text, true);
  pp();

  strings = vec_new();
  parse_program();
  if (verbose) {
    print_tokens(output, token);

    print_globals();
    print_funcs();
    print_strings();
    print_structs();
    print_typedefs();
    fprintf(output, "\n");
  }

  fprintf(output, "\t.intel_syntax noprefix\n");

  fprintf(output, "\t.data\n");
  Global *global = globals;

  for (; global; global = global->next) {
    if (global->is_extern) {
      continue;
    }
    fprintf(output, "\t.global %.*s\n", global->token->len, global->token->str);
    fprintf(output, "%.*s:\n", global->token->len, global->token->str);
    emit_global(global->type, global->body);
  };

  int i = 0;
  while (i < vec_len(strings)) {
    Node *node = strings->data[i];
    fprintf(output, ".LS%06d:\n", node->str_id);
    fprintf(output, "\t.string \"");
    for (Token *t = node->token; t; t = t->next) {
      fprintf(output, "%.*s", t->len, t->str);
    }
    fprintf(output, "\"\n");
    i++;
  }
  fprintf(output, "\n");
  if (verbose) {
    for (FileInfo *fi = file_informations; fi; fi = fi->next) {
      int no = fi->no;
      char *name = fi->file_name;
      int len = strlen(name);
      fprintf(output, "\t.file %d \"%.*s\"\n", no, len, name);
    }
  }

  fprintf(output, "\t.text\n");

  int len = vec_len(ext_declarations);
  for (int i = 0; i < len; i++) {
    Node *node = ext_declarations->data[i];
    fprintf(output, "\t.global %.*s\n", node->token->len, node->token->str);
    gen_stmt(node);
  }
  fprintf(stderr, "monocc: compile complete\n");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0xc5d5(%rip), %rax      # 0x11288
movl $0x5, (%rax)
leaq 0xc608(%rip), %rax      # 0x112c8
movl $0x6, (%rax)
leaq 0xc63b(%rip), %rax      # 0x11308
movl $0x3, (%rax)
leaq 0xc66e(%rip), %rax      # 0x11348
movl $0x4, (%rax)
leaq 0xc6a1(%rip), %rax      # 0x11388
movl $0x7, (%rax)
leaq 0xc6d4(%rip), %rax      # 0x113c8
movl $0x8, (%rax)
leaq 0xc707(%rip), %rax      # 0x11408
movl $0x1, (%rax)
leaq 0xc73a(%rip), %rax      # 0x11448
movl $0x2, (%rax)
leaq 0xc76d(%rip), %rax      # 0x11488
andl $0x0, (%rax)
leaq 0x5816(%rip), %rsi      # 0xa53b
pushq $0x12
popq %rdx
xorl %edi, %edi
callq 0x4c7a
movq %rax, %r14
xorl %eax, %eax
callq 0x90c4
movq %rax, %rdi
callq 0x9110
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x5c1e
movq 0x10(%rax), %rax
movb $0x1, 0x38(%rax)
movq 0xc4b3(%rip), %rsi      # 0x11210
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x82ae
xorl %eax, %eax
callq 0x7ede
xorl %eax, %eax
callq 0x34c8
movq %rax, 0xc49b(%rip)      # 0x11218
xorl %eax, %eax
callq 0x7a61
leaq 0xc475(%rip), %rax      # 0x11200
cmpb $0x1, (%rax)
jne 0x4dd5
movq 0xc489(%rip), %rdi      # 0x11220
movq 0xc48a(%rip), %rsi      # 0x11228
callq 0x366c
xorl %eax, %eax
callq 0x4271
xorl %eax, %eax
callq 0x42f4
xorl %eax, %eax
callq 0x436e
xorl %eax, %eax
callq 0x4427
xorl %eax, %eax
callq 0x456e
movq 0xc453(%rip), %rsi      # 0x11220
pushq $0xa
popq %rdi
callq 0x10c0
movq 0xc444(%rip), %rcx      # 0x11220
leaq 0x630a(%rip), %rdi      # 0xb0ed
pushq $0x18
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x1190
movq 0xc428(%rip), %rcx      # 0x11220
leaq 0x6307(%rip), %rdi      # 0xb106
pushq $0x7
popq %rsi
movq %rbx, %rdx
callq 0x1190
leaq 0xc41f(%rip), %r15      # 0x11230
leaq 0x62f6(%rip), %rbx      # 0xb10e
leaq 0x5375(%rip), %r14      # 0xa194
movq (%r15), %r15
testq %r15, %r15
je 0x4e75
cmpb $0x0, 0x20(%r15)
jne 0x4e1f
movq 0xc3eb(%rip), %rdi      # 0x11220
movq 0x8(%r15), %rax
movl 0x28(%rax), %edx
movq 0x20(%rax), %rcx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10f0
movq 0xc3cf(%rip), %rdi      # 0x11220
movq 0x8(%r15), %rax
movl 0x28(%rax), %edx
movq 0x20(%rax), %rcx
movq %r14, %rsi
xorl %eax, %eax
callq 0x10f0
movq 0x10(%r15), %rdi
movq 0x18(%r15), %rsi
callq 0x3144
jmp 0x4e1f
pushq $0x1
popq %r12
leaq 0x62b6(%rip), %r13      # 0xb136
pushq $0x2
popq %rbp
leaq 0x5c0e(%rip), %rbx      # 0xaa98
xorl %r14d, %r14d
movq 0xc384(%rip), %rdi      # 0x11218
callq 0x34f2
cltq
cmpq %rax, %r14
jge 0x4f2b
movq 0xc36d(%rip), %rax      # 0x11218
movq (%rax), %rax
movq (%rax,%r14,8), %r15
movq 0xc367(%rip), %rdi      # 0x11220
movl 0x28(%r15), %edx
leaq 0x6259(%rip), %rsi      # 0xb11d
xorl %eax, %eax
callq 0x10f0
movq 0xc34e(%rip), %rcx      # 0x11220
leaq 0x5bb4(%rip), %rdi      # 0xaa8d
pushq $0xa
popq %rsi
movq %r12, %rdx
callq 0x1190
addq $0x50, %r15
movq (%r15), %r15
movq 0xc32e(%rip), %rax      # 0x11220
testq %r15, %r15
je 0x4f12
movl 0x28(%r15), %edx
movq 0x20(%r15), %rcx
movq %rax, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10f0
addq $0x8, %r15
jmp 0x4ee8
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %rax, %rcx
callq 0x1190
incq %r14
jmp 0x4e8d
movq 0xc2ee(%rip), %rsi      # 0x11220
pushq $0xa
popq %rdi
callq 0x10c0
leaq 0xc2bf(%rip), %rax      # 0x11200
cmpb $0x1, (%rax)
jne 0x4f86
leaq 0xc2bb(%rip), %r15      # 0x11208
leaq 0x61d3(%rip), %rbx      # 0xb127
movq (%r15), %r15
testq %r15, %r15
je 0x4f86
movl 0x20(%r15), %ebp
movq 0x8(%r15), %r14
movq %r14, %rdi
callq 0x1090
movq 0xc2ad(%rip), %rdi      # 0x11220
movq %rbx, %rsi
movl %ebp, %edx
movl %eax, %ecx
movq %r14, %r8
xorl %eax, %eax
callq 0x10f0
jmp 0x4f54
movq 0xc293(%rip), %rcx      # 0x11220
leaq 0x61a5(%rip), %rdi      # 0xb139
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x1190
movq 0xc292(%rip), %rdi      # 0x11238
callq 0x34f2
movl %eax, %ebx
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
leaq 0x6153(%rip), %r14      # 0xb10e
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x4ffa
movq 0xc26e(%rip), %rax      # 0x11238
movq (%rax), %rax
movq (%rax,%r12,8), %r15
movq 0xc248(%rip), %rdi      # 0x11220
movq 0x50(%r15), %rax
movl 0x28(%rax), %edx
movq 0x20(%rax), %rcx
movq %r14, %rsi
xorl %eax, %eax
callq 0x10f0
movq %r15, %rdi
callq 0x2196
incq %r12
jmp 0x4fbe
movq 0xbff7(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x6136(%rip), %rdi      # 0xb141
pushq $0x19
popq %rsi
pushq $0x1
popq %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1190