// File: /workspace/github_c_makefile_star2_O3/sisshiki1969[P]monocc/src/parse.c
// Function: parse_program
void parse_program() {
  ext_declarations = vec_new();
  while (!at_eof()) {
    locals = NULL;
    scope = NULL;
    switch_level = 0;
    Node *decl;
    if (consume_if(TK_MACRO)) continue;
    if (consume_if(TK_TYPEDEF)) {
      MemberInfo *ty_ident = parse_decl(true);
      if (!ty_ident->ident) error_at_token(token, "Expected identifier.");
      new_typedef(ty_ident->ident, ty_ident->type);
      expect(TK_SEMI);
      continue;
    }
    bool is_extern = false;
    if (consume_if(TK_EXTERN)) {
      is_extern = true;
    }
    MemberInfo *ty_ident = parse_decl(false);
    Token *ident = ty_ident->ident;
    Type *type = ty_ident->type;
    if (!ident) {
      if (is_struct(type) || is_enum(type)) {
        // struct XXX { ... };
        expect(TK_SEMI);
        continue;
      } else
        // error for "int;"
        error_at_token(token, "Expected an identifier.");
    }

    if (!is_func(type)) {
      // gloval var declaration
      Token *op_token = token;
      Global *gvar = find_gvar(ident);
      if (gvar) {
        if (gvar->body)
          error_at_token(ident, "Reinitialization of global variable.");
        if (!is_identical_type(gvar->type, type))
          error_at_token(ident, "Conflicting types.");
      } else
        gvar = new_gvar(ident, type);
      gvar->is_extern = is_extern;
      if (consume_if(TK_ASSIGN)) {
        if (is_extern)
          error_at_token(op_token,
                         "Can not initialize variables with 'extern'.");
        gvar->body = parse_initializer(gvar->type);
      }
      if (is_array_of_char(gvar->type)) {
        if (!gvar->body) {
          // char s[];
          if (gvar->type->array_size == 0)
            error_at_token(gvar->token, "Incomplete type is not allowed.");
        } else if (gvar->body->kind == ND_STR) {
          // char s[] = "...";
          if (gvar->type->array_size == 0)
            gvar->type->array_size = gvar->body->offset;
        } else
          error_at_node(gvar->body, "Parse error: Unsupported initializer.");
      }
      expect(TK_SEMI);
      continue;
    } else if (consume_if(TK_SEMI)) {
      // function declaration
      Function *func = new_func(ident, type, NULL);
      continue;
    } else if (peek(TK_OP_BRACE)) {
      // function definition

      decl = parse_func_definition(ty_ident);
      if (verbose) {
        fprintf(output, "// ");
        print_node(decl);
        fprintf(output, "\n");
        print_locals();
      }
      vec_push(ext_declarations, decl);
    } else
      error_at_token(token, "Unexpected token.");
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
xorl %eax, %eax
callq 0x3f0c
leaq 0xa4ce(%rip), %rcx      # 0x13238
movq %rax, (%rcx)
leaq 0xa4b4(%rip), %rbx      # 0x13228
movq (%rbx), %rax
cmpl $0x41, (%rax)
jne 0x8d8b
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa4b6(%rip), %r12      # 0x13248
xorl %r13d, %r13d
leaq 0xa4b4(%rip), %rbp      # 0x13250
movq %r13, (%r12)
movq %r13, (%rbp)
movl $0x0, 0xa4ca(%rip)      # 0x13278
movl (%rax), %r14d
cmpl $0x40, %r14d
je 0x8dca
cmpl $0x42, %r14d
jne 0x8e4e
movq 0x8(%rax), %rax
jmp 0x8f1a
movq 0x8(%rax), %rax
movq %rax, (%rbx)
movl $0x1, %edi
callq 0x7095
movq %rax, %r15
movq 0x8(%rax), %r14
testq %r14, %r14
jne 0x8e01
movq (%rbx), %rdi
leaq 0x4590(%rip), %rsi      # 0xd381
xorl %eax, %eax
callq 0x52cd
movq 0x8(%r15), %r14
testq %r14, %r14
je 0x8e2c
movq 0x10(%r15), %r15
movl $0x1, %edi
movl $0x18, %esi
callq 0x10d0
leaq 0xa445(%rip), %rdx      # 0x13260
movq (%rdx), %rcx
movq %rcx, (%rax)
movq %r14, 0x10(%rax)
movq %r15, 0x8(%rax)
movq %rax, (%rdx)
movq (%rbx), %rdi
cmpl $0x1c, (%rdi)
je 0x8f16
leaq 0x4627(%rip), %rsi      # 0xd466
xorl %eax, %eax
callq 0x52cd
movq (%rbx), %rdi
jmp 0x8f16
cmpl $0x3f, %r14d
jne 0x8e5b
movq 0x8(%rax), %rax
movq %rax, (%rbx)
xorl %edi, %edi
callq 0x7095
movq %rax, %r15
movq 0x8(%rax), %r13
movq 0x10(%rax), %rbp
testq %r13, %r13
je 0x8ed7
movq %rbp, %rdi
callq 0xad82
movq (%rbx), %r12
testb %al, %al
je 0x8f2e
movl (%r12), %eax
cmpl $0x1f, %eax
je 0x9030
cmpl $0x1c, %eax
jne 0x9097
movq 0x8(%r12), %rax
movq %rax, (%rbx)
movl $0x1, %edi
movl $0x28, %esi
callq 0x10d0
leaq 0xa3af(%rip), %rdx      # 0x13268
movq (%rdx), %rcx
movq %rcx, (%rax)
movq %r13, 0x8(%rax)
movq %rbp, 0x10(%rax)
movq $0x0, 0x18(%rax)
movq %rax, (%rdx)
jmp 0x90a8
movq %rbp, %rdi
callq 0xad89
testb %al, %al
jne 0x8ef3
movq %rbp, %rdi
callq 0xad90
testb %al, %al
je 0x90be
movq (%rbx), %rdi
cmpl $0x1c, (%rdi)
je 0x8f0c
leaq 0x4564(%rip), %rsi      # 0xd466
xorl %eax, %eax
callq 0x52cd
movq (%rbx), %rdi
xorl %r13d, %r13d
leaq 0xa33a(%rip), %rbp      # 0x13250
movq 0x8(%rdi), %rax
movq %rax, (%rbx)
movq (%rbx), %rax
cmpl $0x41, (%rax)
jne 0x8d9c
jmp 0x8d7c
movq %r13, %rdi
callq 0x6364
testq %rax, %rax
je 0x8f79
movq %rax, %r15
cmpq $0x0, 0x18(%rax)
je 0x8f56
movq %r13, %rdi
leaq 0x482a(%rip), %rsi      # 0xd779
xorl %eax, %eax
callq 0x52cd
movq 0x10(%r15), %rdi
movq %rbp, %rsi
callq 0xb045
testb %al, %al
jne 0x8fa3
movq %r13, %rdi
leaq 0x482e(%rip), %rsi      # 0xd79e
xorl %eax, %eax
callq 0x52cd
jmp 0x8fa3
movl $0x1, %edi
movl $0x28, %esi
callq 0x10d0
movq %rax, %r15
leaq 0xa29e(%rip), %rcx      # 0x13230
movq (%rcx), %rax
movq %rax, (%r15)
movq %r13, 0x8(%r15)
movq %rbp, 0x10(%r15)
movq %r15, (%rcx)
xorl %r13d, %r13d
leaq 0xa2a3(%rip), %rbp      # 0x13250
cmpl $0x3f, %r14d
sete 0x20(%r15)
movq (%rbx), %rax
cmpl $0xd, (%rax)
jne 0x8fe9
movq 0x8(%rax), %rax
movq %rax, (%rbx)
cmpl $0x3f, %r14d
jne 0x8fdc
movq %r12, %rdi
leaq 0x47dc(%rip), %rsi      # 0xd7b1
xorl %eax, %eax
callq 0x52cd
movq 0x10(%r15), %rdi
callq 0x7f73
movq %rax, 0x18(%r15)
movq 0x10(%r15), %rdi
callq 0xadb1
testb %al, %al
leaq 0xa24d(%rip), %r12      # 0x13248
je 0x8e2c
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0x90d4
cmpl $0x2, (%rdi)
jne 0x90f9
movq 0x10(%r15), %rax
cmpl $0x0, 0x10(%rax)
jne 0x8e2c
movl 0x38(%rdi), %ecx
movl %ecx, 0x10(%rax)
jmp 0x8e2c
movq %r15, %rdi
callq 0x8a88
movq %rax, %r15
leaq 0xa1be(%rip), %rax      # 0x13200
cmpb $0x1, (%rax)
jne 0x9083
leaq 0xa1d2(%rip), %r14      # 0x13220
movq (%r14), %rcx
movl $0x3, %esi
movl $0x1, %edx
leaq 0x3cb5(%rip), %rdi      # 0xcd17
callq 0x1190
movq %r15, %rdi
callq 0x408c
movq (%r14), %rsi
movl $0xa, %edi
callq 0x10c0
xorl %eax, %eax
callq 0x4c0c
leaq 0xa1ae(%rip), %rax      # 0x13238
movq (%rax), %rdi
movq %r15, %rsi
callq 0x3f3e
jmp 0x90a8
movq %r12, %rdi
leaq 0x43c5(%rip), %rsi      # 0xd466
xorl %eax, %eax
callq 0x52cd
leaq 0xa199(%rip), %r12      # 0x13248
xorl %r13d, %r13d
leaq 0xa197(%rip), %rbp      # 0x13250
jmp 0x8f1d
movq (%rbx), %rdi
leaq 0x4531(%rip), %rsi      # 0xd5f9
xorl %eax, %eax
callq 0x52cd
jmp 0x8e72
movq 0x10(%r15), %rax
cmpl $0x0, 0x10(%rax)
jne 0x8e2c
movq 0x8(%r15), %rdi
leaq 0x3945(%rip), %rsi      # 0xca32
xorl %eax, %eax
callq 0x52cd
jmp 0x8e2c
leaq 0x46dd(%rip), %rsi      # 0xd7dd
xorl %eax, %eax
callq 0x5502
jmp 0x8e2c