// File: /workspace/github_c_makefile_star2_O1/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 0x3f34
leaq 0xa406(%rip), %rcx      # 0x13238
movq %rax, (%rcx)
leaq 0xa3ec(%rip), %rbx      # 0x13228
movq (%rbx), %rax
cmpl $0x41, (%rax)
je 0x91bf
leaq 0xa3f9(%rip), %rbp      # 0x13248
xorl %r12d, %r12d
leaq 0xa3f7(%rip), %r13      # 0x13250
movq %r12, (%rbp)
movq %r12, (%r13)
movl $0x0, 0xa40d(%rip)      # 0x13278
cmpl $0x42, (%rax)
je 0x91ac
movq (%rbx), %rax
cmpl $0x40, (%rax)
jne 0x8ee5
movq 0x8(%rax), %rax
movq %rax, (%rbx)
movl $0x1, %edi
callq 0x70e6
movq %rax, %r15
cmpq $0x0, 0x8(%rax)
jne 0x8ea8
movq (%rbx), %rdi
leaq 0x44a4(%rip), %rsi      # 0xd345
xorl %eax, %eax
callq 0x52f9
movq 0x8(%r15), %r14
testq %r14, %r14
je 0x9193
movq 0x10(%r15), %r15
movl $0x1, %edi
movl $0x18, %esi
callq 0x10d0
leaq 0xa391(%rip), %rdx      # 0x13260
movq (%rdx), %rcx
movq %rcx, (%rax)
movq %r14, 0x10(%rax)
movq %r15, 0x8(%rax)
movq %rax, (%rdx)
jmp 0x9193
movq (%rbx), %rax
movl (%rax), %r14d
cmpl $0x3f, %r14d
jne 0x8ef8
movq 0x8(%rax), %rax
movq %rax, (%rbx)
xorl %edi, %edi
callq 0x70e6
movq %rax, %r15
movq 0x8(%rax), %r13
movq 0x10(%rax), %r12
testq %r13, %r13
je 0x8f67
movq %r12, %rdi
callq 0xaeae
movq (%rbx), %rbp
testb %al, %al
je 0x8fa8
cmpl $0x1c, (%rbp)
jne 0x8ffe
movq 0x8(%rbp), %rax
movq %rax, (%rbx)
movl $0x1, %edi
movl $0x28, %esi
callq 0x10d0
leaq 0xa31f(%rip), %rdx      # 0x13268
movq (%rdx), %rcx
movq %rcx, (%rax)
movq %r13, 0x8(%rax)
movq %r12, 0x10(%rax)
movq $0x0, 0x18(%rax)
movq %rax, (%rdx)
jmp 0x9154
movq %r12, %rdi
callq 0xaeb5
testb %al, %al
jne 0x8f83
movq %r12, %rdi
callq 0xaebc
testb %al, %al
je 0x9130
movq (%rbx), %rdi
cmpl $0x1c, (%rdi)
je 0x8f99
leaq 0x4498(%rip), %rsi      # 0xd42a
xorl %eax, %eax
callq 0x52f9
movq (%rbx), %rax
movq 0x8(%rax), %rax
movq %rax, (%rbx)
jmp 0x915b
movq %r13, %rdi
callq 0x63ba
testq %rax, %rax
je 0x9088
movq %rax, %r15
cmpq $0x0, 0x18(%rax)
je 0x8fd4
movq %r13, %rdi
leaq 0x4770(%rip), %rsi      # 0xd73d
xorl %eax, %eax
callq 0x52f9
movq 0x10(%r15), %rdi
movq %r12, %rsi
callq 0xb16a
testb %al, %al
jne 0x90b2
movq %r13, %rdi
leaq 0x4770(%rip), %rsi      # 0xd762
xorl %eax, %eax
callq 0x52f9
jmp 0x90b2
movq (%rbx), %rdi
cmpl $0x1f, (%rdi)
jne 0x9146
movq %r15, %rdi
callq 0x8b4a
movq %rax, %r15
leaq 0xa1e4(%rip), %rax      # 0x13200
cmpb $0x1, (%rax)
leaq 0xa222(%rip), %rbp      # 0x13248
movl $0x0, %r12d
leaq 0xa21d(%rip), %r13      # 0x13250
jne 0x9071
leaq 0xa1e4(%rip), %r14      # 0x13220
movq (%r14), %rcx
movl $0x3, %esi
movl $0x1, %edx
leaq 0x3cc7(%rip), %rdi      # 0xcd17
callq 0x1190
movq %r15, %rdi
callq 0x40b0
movq (%r14), %rsi
movl $0xa, %edi
callq 0x10c0
xorl %eax, %eax
callq 0x4c32
leaq 0xa1c0(%rip), %rax      # 0x13238
movq (%rax), %rdi
movq %r15, %rsi
callq 0x3f66
jmp 0x91b3
movl $0x1, %edi
movl $0x28, %esi
callq 0x10d0
movq %rax, %r15
leaq 0xa18f(%rip), %rcx      # 0x13230
movq (%rcx), %rax
movq %rax, (%r15)
movq %r13, 0x8(%r15)
movq %r12, 0x10(%r15)
movq %r15, (%rcx)
xorl %r12d, %r12d
leaq 0xa194(%rip), %r13      # 0x13250
cmpl $0x3f, %r14d
sete 0x20(%r15)
movq (%rbx), %rax
cmpl $0xd, (%rax)
jne 0x90f8
movq 0x8(%rax), %rax
movq %rax, (%rbx)
cmpl $0x3f, %r14d
jne 0x90eb
movq %rbp, %rdi
leaq 0x4691(%rip), %rsi      # 0xd775
xorl %eax, %eax
callq 0x52f9
movq 0x10(%r15), %rdi
callq 0x8077
movq %rax, 0x18(%r15)
movq 0x10(%r15), %rdi
callq 0xaedd
testb %al, %al
leaq 0xa13e(%rip), %rbp      # 0x13248
je 0x9193
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0x9167
cmpl $0x2, (%rdi)
jne 0x9185
movq 0x10(%r15), %rax
cmpl $0x0, 0x10(%rax)
jne 0x9193
movl 0x38(%rdi), %ecx
movl %ecx, 0x10(%rax)
jmp 0x9193
movq (%rbx), %rdi
leaq 0x4483(%rip), %rsi      # 0xd5bd
xorl %eax, %eax
callq 0x52f9
jmp 0x8f0f
leaq 0x42dd(%rip), %rsi      # 0xd42a
xorl %eax, %eax
callq 0x52f9
leaq 0xa0ed(%rip), %rbp      # 0x13248
xorl %r12d, %r12d
leaq 0xa0eb(%rip), %r13      # 0x13250
jmp 0x91b3
movq 0x10(%r15), %rax
cmpl $0x0, 0x10(%rax)
jne 0x9193
movq 0x8(%r15), %rdi
leaq 0x38b6(%rip), %rsi      # 0xca32
xorl %eax, %eax
callq 0x52f9
jmp 0x9193
leaq 0x4615(%rip), %rsi      # 0xd7a1
xorl %eax, %eax
callq 0x552e
movq (%rbx), %rdi
cmpl $0x1c, (%rdi)
je 0x91a9
leaq 0x4288(%rip), %rsi      # 0xd42a
xorl %eax, %eax
callq 0x52f9
movq (%rbx), %rax
movq 0x8(%rax), %rax
movq %rax, (%rbx)
movq (%rbx), %rax
cmpl $0x41, (%rax)
jne 0x8e59
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop