// File: /workspace/github_c_makefile_star2_O2/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 0x34c8
leaq 0x97be(%rip), %rcx      # 0x11238
movq %rax, (%rcx)
leaq 0x97a4(%rip), %rbx      # 0x11228
leaq 0x97bd(%rip), %r13      # 0x11248
leaq 0x97be(%rip), %r15      # 0x11250
movq (%rbx), %rax
cmpl $0x41, (%rax)
je 0x7d29
andq $0x0, (%r13)
andq $0x0, (%r15)
andl $0x0, 0x97ca(%rip)      # 0x11278
movl (%rax), %ebp
cmpl $0x40, %ebp
je 0x7ac3
cmpl $0x42, %ebp
jne 0x7b06
movq 0x8(%rax), %rax
movq %rax, (%rbx)
jmp 0x7a92
movq 0x8(%rax), %rax
movq %rax, (%rbx)
pushq $0x1
popq %rdi
callq 0x651c
movq %rax, %r14
movq 0x8(%rax), %rdi
testq %rdi, %rdi
jne 0x7af3
movq (%rbx), %rdi
leaq 0x3881(%rip), %rsi      # 0xb369
xorl %eax, %eax
callq 0x48b3
movq 0x8(%r14), %rdi
movq 0x10(%r14), %rsi
callq 0x5d04
pushq $0x1c
popq %rdi
callq 0x5a46
jmp 0x7a92
cmpl $0x3f, %ebp
jne 0x7b12
movq 0x8(%rax), %rax
movq %rax, (%rbx)
xorl %edi, %edi
callq 0x651c
movq %rax, %r15
movq 0x8(%rax), %r12
movq 0x10(%rax), %r14
testq %r12, %r12
je 0x7b75
movq %r14, %rdi
callq 0x91a6
movq (%rbx), %r13
testb %al, %al
je 0x7bc5
movl (%r13), %eax
cmpl $0x1f, %eax
je 0x7cc5
cmpl $0x1c, %eax
leaq 0x96fd(%rip), %r15      # 0x11250
jne 0x7ba8
movq 0x8(%r13), %rax
movq %rax, (%rbx)
movq %r12, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x5c1e
leaq 0x96d8(%rip), %r13      # 0x11248
jmp 0x7a92
movq %r14, %rdi
callq 0x91ad
testb %al, %al
jne 0x7cb8
movq %r14, %rdi
callq 0x91b4
testb %al, %al
jne 0x7cb8
movq (%rbx), %rdi
leaq 0x3a42(%rip), %rsi      # 0xb5e1
xorl %eax, %eax
callq 0x48b3
jmp 0x7b29
movq %r13, %rdi
leaq 0x389c(%rip), %rsi      # 0xb44e
xorl %eax, %eax
callq 0x48b3
leaq 0x9688(%rip), %r13      # 0x11248
jmp 0x7a92
movq %r12, %rdi
callq 0x5bed
testq %rax, %rax
je 0x7c10
movq %rax, %r15
cmpq $0x0, 0x18(%rax)
je 0x7bed
movq %r12, %rdi
leaq 0x3b7b(%rip), %rsi      # 0xb761
xorl %eax, %eax
callq 0x48b3
movq 0x10(%r15), %rdi
movq %r14, %rsi
callq 0x9431
testb %al, %al
jne 0x7c1e
movq %r12, %rdi
leaq 0x3b7f(%rip), %rsi      # 0xb786
xorl %eax, %eax
callq 0x48b3
jmp 0x7c1e
movq %r12, %rdi
movq %r14, %rsi
callq 0x5bb8
movq %rax, %r15
cmpl $0x3f, %ebp
sete 0x20(%r15)
movq (%rbx), %rax
cmpl $0xd, (%rax)
jne 0x7c58
movq 0x8(%rax), %rax
movq %rax, (%rbx)
cmpl $0x3f, %ebp
jne 0x7c4b
movq %r13, %rdi
leaq 0x3b55(%rip), %rsi      # 0xb799
xorl %eax, %eax
callq 0x48b3
movq 0x10(%r15), %rdi
callq 0x7022
movq %rax, 0x18(%r15)
movq 0x10(%r15), %rdi
callq 0x91d5
testb %al, %al
leaq 0x95de(%rip), %r13      # 0x11248
je 0x7cb8
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0x7c8c
cmpl $0x2, (%rdi)
jne 0x7caa
movq 0x10(%r15), %rax
cmpl $0x0, 0x10(%rax)
jne 0x7cb8
movl 0x38(%rdi), %ecx
movl %ecx, 0x10(%rax)
jmp 0x7cb8
movq 0x10(%r15), %rax
cmpl $0x0, 0x10(%rax)
jne 0x7cb8
movq 0x8(%r15), %rdi
leaq 0x2d91(%rip), %rsi      # 0xaa32
xorl %eax, %eax
callq 0x48b3
jmp 0x7cb8
leaq 0x3b14(%rip), %rsi      # 0xb7c5
xorl %eax, %eax
callq 0x4a9e
pushq $0x1c
popq %rdi
callq 0x5a46
jmp 0x7a8b
movq %r15, %rdi
callq 0x7882
movq %rax, %r14
leaq 0x9529(%rip), %rax      # 0x11200
cmpb $0x1, (%rax)
jne 0x7d12
leaq 0x953d(%rip), %r15      # 0x11220
movq (%r15), %rcx
leaq 0x302a(%rip), %rdi      # 0xad17
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
callq 0x1190
movq %r14, %rdi
callq 0x36e0
movq (%r15), %rsi
pushq $0xa
popq %rdi
callq 0x10c0
xorl %eax, %eax
callq 0x4201
leaq 0x951f(%rip), %rax      # 0x11238
movq (%rax), %rdi
movq %r14, %rsi
callq 0x34f6
jmp 0x7a84
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq