// File: /workspace/github_c_makefile_star2_O1/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 0x11eef(%rip), %rax     # 0x13288
movl $0x5, (%rax)
leaq 0x11f22(%rip), %rax     # 0x132c8
movl $0x6, (%rax)
leaq 0x11f55(%rip), %rax     # 0x13308
movl $0x3, (%rax)
leaq 0x11f88(%rip), %rax     # 0x13348
movl $0x4, (%rax)
leaq 0x11fbb(%rip), %rax     # 0x13388
movl $0x7, (%rax)
leaq 0x11fee(%rip), %rax     # 0x133c8
movl $0x8, (%rax)
leaq 0x12021(%rip), %rax     # 0x13408
movl $0x1, (%rax)
leaq 0x12054(%rip), %rax     # 0x13448
movl $0x2, (%rax)
leaq 0x12087(%rip), %rax     # 0x13488
andl $0x0, (%rax)
pushq $0x1
popq %rdi
pushq $0x30
popq %rsi
callq 0x10d0
movq %rax, %r14
andl $0x0, (%rax)
leaq 0xb11f(%rip), %rax      # 0xc53b
movq %rax, 0x20(%r14)
movl $0x12, 0x28(%r14)
xorl %eax, %eax
callq 0xadb0
movq %rax, %rdi
callq 0xae04
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x6400
movq 0x10(%rax), %rax
movb $0x1, 0x38(%rax)
movq 0x11dbd(%rip), %rsi     # 0x13210
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x97ad
xorl %eax, %eax
callq 0x9366
xorl %eax, %eax
callq 0x3f34
movq %rax, 0x11da5(%rip)     # 0x13218
xorl %eax, %eax
callq 0x8e19
leaq 0x11d7f(%rip), %rax     # 0x13200
cmpb $0x1, (%rax)
jne 0x14cb
movq 0x11d93(%rip), %rdi     # 0x13220
movq 0x11d94(%rip), %rsi     # 0x13228
callq 0x403f
xorl %eax, %eax
callq 0x4caa
xorl %eax, %eax
callq 0x4d2d
xorl %eax, %eax
callq 0x4da7
xorl %eax, %eax
callq 0x4e7c
xorl %eax, %eax
callq 0x4fd5
movq 0x11d5d(%rip), %rsi     # 0x13220
pushq $0xa
popq %rdi
callq 0x10c0
movq 0x11d4e(%rip), %rcx     # 0x13220
leaq 0xbc14(%rip), %rdi      # 0xd0ed
pushq $0x18
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x1190
movq 0x11d32(%rip), %rcx     # 0x13220
leaq 0xbc11(%rip), %rdi      # 0xd106
pushq $0x7
popq %rsi
movq %rbx, %rdx
callq 0x1190
movq 0x11d29(%rip), %r15     # 0x13230
testq %r15, %r15
je 0x156e
leaq 0xbbfb(%rip), %rbx      # 0xd10e
leaq 0xac7a(%rip), %r14      # 0xc194
cmpb $0x0, 0x20(%r15)
jne 0x1566
movq 0x11cf8(%rip), %rdi     # 0x13220
movq 0x8(%r15), %rax
movl 0x28(%rax), %edx
movq 0x20(%rax), %rcx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10f0
movq 0x11cdc(%rip), %rdi     # 0x13220
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 0x3b80
movq (%r15), %r15
testq %r15, %r15
jne 0x151a
movq 0x11ca3(%rip), %rdi     # 0x13218
callq 0x3f62
testl %eax, %eax
jle 0x1631
pushq $0x1
popq %r12
leaq 0xbba9(%rip), %r13      # 0xd136
pushq $0x2
popq %rbp
leaq 0xb501(%rip), %rbx      # 0xca98
xorl %r14d, %r14d
movq 0x11c77(%rip), %rax     # 0x13218
movq (%rax), %rax
movq (%rax,%r14,8), %r15
movq 0x11c71(%rip), %rdi     # 0x13220
movl 0x28(%r15), %edx
leaq 0xbb63(%rip), %rsi      # 0xd11d
xorl %eax, %eax
callq 0x10f0
movq 0x11c58(%rip), %rcx     # 0x13220
leaq 0xb4be(%rip), %rdi      # 0xca8d
pushq $0xa
popq %rsi
movq %r12, %rdx
callq 0x1190
movq 0x50(%r15), %r15
testq %r15, %r15
je 0x1602
movq 0x11c36(%rip), %rdi     # 0x13220
movl 0x28(%r15), %edx
movq 0x20(%r15), %rcx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10f0
movq 0x8(%r15), %r15
jmp 0x15de
movq 0x11c17(%rip), %rcx     # 0x13220
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x1190
incq %r14
movq 0x11bf7(%rip), %rdi     # 0x13218
callq 0x3f62
cltq
cmpq %rax, %r14
jl 0x159a
movq 0x11be8(%rip), %rsi     # 0x13220
pushq $0xa
popq %rdi
callq 0x10c0
movq 0x11bc1(%rip), %r15     # 0x13208
testq %r15, %r15
setne %al
leaq 0x11bac(%rip), %rcx     # 0x13200
andb (%rcx), %al
cmpb $0x1, %al
jne 0x1691
leaq 0xbac6(%rip), %rbx      # 0xd127
movl 0x20(%r15), %ebp
movq 0x8(%r15), %r14
movq %r14, %rdi
callq 0x1090
movq 0x11ba8(%rip), %rdi     # 0x13220
movq %rbx, %rsi
movl %ebp, %edx
movl %eax, %ecx
movq %r14, %r8
xorl %eax, %eax
callq 0x10f0
movq (%r15), %r15
testq %r15, %r15
jne 0x1661
movq 0x11b88(%rip), %rcx     # 0x13220
leaq 0xba9a(%rip), %rdi      # 0xd139
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x1190
movq 0x11b87(%rip), %rdi     # 0x13238
callq 0x3f62
testl %eax, %eax
jle 0x1701
movl %eax, %r15d
leaq 0xba4a(%rip), %rbx      # 0xd10e
xorl %r12d, %r12d
movq 0x11b6a(%rip), %rax     # 0x13238
movq (%rax), %rax
movq (%rax,%r12,8), %r14
movq 0x11b44(%rip), %rdi     # 0x13220
movq 0x50(%r14), %rax
movl 0x28(%rax), %edx
movq 0x20(%rax), %rcx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10f0
movq %r14, %rdi
callq 0x29c8
incq %r12
cmpq %r12, %r15
jne 0x16c7
movq 0x118f0(%rip), %rax     # 0x12ff8
movq (%rax), %rcx
leaq 0xba2f(%rip), %rdi      # 0xd141
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