// File: /workspace/github_c_makefile_star2_O0/ryvnf[P]czc/codegen.c
// Function: decl_pass
void decl_pass(struct ast *ast)
{
    size_t n_extern_defs;
    struct ast **extern_defs = ast_asts(ast, &n_extern_defs);

    for (size_t i = 0; i < n_extern_defs; ++i) {
        struct ast *extern_def = extern_defs[i];
        struct ast *loc;
        bool is_defined = false;

        switch (extern_def->tag) {
            case TYPE_DEF: {
                loc = extern_def;
                const char *name = ast_s(ast_ast(loc, 0));
                struct type *type = scope_get_type(current_scope, name);
                struct ast *def_type_ast = ast_ast(loc, 1);
                scope_add_typesym(current_scope, name, sym_new(loc));

                if (def_type_ast != NULL) {
                    struct type *def_type = type_from_ast(def_type_ast);

                    if (type != NULL && !type_equals(type, def_type))
                        fatal(extern_def->loc, "%s is redefined as a different type", name);

                    type_del(def_type);
                }

                continue;
            }
            case ASGN_EXPR:
            case FUNC_DEF:
                is_defined = true;
                loc = ast_ast(extern_def, 0);
                break;
            case ALIAS_DEF:
            case DECL: {
                loc = extern_def;
                break;
            }
            case SOURCE_FILE:
                decl_pass(extern_def);
                continue;
            case ALREADY_INCLUDED:
                continue;
            default:
                bug("%s should not be here", ast_tag_name(extern_def->tag));
        }
        const char *name = ast_s(ast_ast(loc, 0));
        struct sym *sym = scope_get_sym(current_scope, name);

        bool redecl = false;

        if (sym != NULL) {
            if (sym->tag == DECL_SYM && loc->tag == DECL) {
                struct decl_sym *decl_sym = (struct decl_sym *)sym;

                if (is_defined && decl_sym->is_defined)
                    fatal(extern_def->loc, "%s is redefined", name);

                struct type *type = type_from_ast(ast_ast(loc, 1));

                if (!type_equals(type, ((struct decl_sym *)sym)->type))
                    fatal(extern_def->loc, "%s is declared as different type", name);

                type_del(type);
            } else {
                fatal(extern_def->loc, "%s is redefined", name);
            }
            redecl = true;
        }

        struct sym *new_sym = sym_new(loc);

        if (is_defined)
            ((struct decl_sym *)new_sym)->is_defined = true;

        if (!redecl)
            scope_add_sym(current_scope, name, new_sym);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x2ad0
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x5eef
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movb $0x0, -0x31(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x8c(%rbp)
subl $0x7, %eax
je 0x5d7a
jmp 0x5c01
movl -0x8c(%rbp), %eax
subl $0x4000, %eax           # imm = 0x4000
je 0x5d62
jmp 0x5c14
movl -0x8c(%rbp), %eax
subl $0x4001, %eax           # imm = 0x4001
je 0x5d4b
jmp 0x5c27
movl -0x8c(%rbp), %eax
subl $0x4002, %eax           # imm = 0x4002
je 0x5c72
jmp 0x5c36
movl -0x8c(%rbp), %eax
subl $0x4003, %eax           # imm = 0x4003
je 0x5d62
jmp 0x5c49
movl -0x8c(%rbp), %eax
subl $0x4220, %eax           # imm = 0x4220
je 0x5d4b
jmp 0x5c5c
movl -0x8c(%rbp), %eax
subl $0x4502, %eax           # imm = 0x4502
je 0x5d6c
jmp 0x5d7f
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2a40
movq %rax, %rdi
callq 0x27f0
movq %rax, -0x40(%rbp)
leaq 0x1413e(%rip), %rax     # 0x19dd8
movq (%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0xf690
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0x2a40
movq %rax, -0x50(%rbp)
leaq 0x14115(%rip), %rax     # 0x19dd8
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x30(%rbp), %rdi
callq 0xf9b0
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq %rax, %rdx
callq 0xf580
cmpq $0x0, -0x50(%rbp)
je 0x5d46
movq -0x50(%rbp), %rdi
callq 0x10600
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x5d3d
movq -0x48(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x10c90
testb $0x1, %al
jne 0x5d3d
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x40(%rbp), %rdx
leaq 0xc914(%rip), %rsi      # 0x1264a
movb $0x0, %al
callq 0x6610
movq -0x58(%rbp), %rdi
callq 0x10f50
jmp 0x5ede
movb $0x1, -0x31(%rbp)
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2a40
movq %rax, -0x30(%rbp)
jmp 0x5d9b
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x5d9b
movq -0x28(%rbp), %rdi
callq 0x5ba0
jmp 0x5ede
jmp 0x5ede
movq -0x28(%rbp), %rax
movl (%rax), %edi
callq 0x2b70
movq %rax, %rsi
leaq 0xc8da(%rip), %rdi      # 0x1266e
movb $0x0, %al
callq 0x6510
movq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2a40
movq %rax, %rdi
callq 0x27f0
movq %rax, -0x60(%rbp)
leaq 0x1401d(%rip), %rax     # 0x19dd8
movq (%rax), %rdi
movq -0x60(%rbp), %rsi
callq 0xf5b0
movq %rax, -0x68(%rbp)
movb $0x0, -0x69(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x5e9b
movq -0x68(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x5e7d
movq -0x30(%rbp), %rax
cmpl $0x4000, (%rax)         # imm = 0x4000
jne 0x5e7d
movq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
testb $0x1, -0x31(%rbp)
je 0x5e29
movq -0x78(%rbp), %rax
testb $0x1, 0x20(%rax)
je 0x5e29
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x60(%rbp), %rdx
leaq 0xc862(%rip), %rsi      # 0x12684
movb $0x0, %al
callq 0x6610
movq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0x2a40
movq %rax, %rdi
callq 0x10600
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
movq -0x68(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x10c90
testb $0x1, %al
jne 0x5e72
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x60(%rbp), %rdx
leaq 0xc829(%rip), %rsi      # 0x12694
movb $0x0, %al
callq 0x6610
movq -0x80(%rbp), %rdi
callq 0x10f50
jmp 0x5e97
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x60(%rbp), %rdx
leaq 0xc7f4(%rip), %rsi      # 0x12684
movb $0x0, %al
callq 0x6610
movb $0x1, -0x69(%rbp)
movq -0x30(%rbp), %rdi
callq 0xf9b0
movq %rax, -0x88(%rbp)
testb $0x1, -0x31(%rbp)
je 0x5ebc
movq -0x88(%rbp), %rax
movb $0x1, 0x20(%rax)
testb $0x1, -0x69(%rbp)
jne 0x5edc
leaq 0x13f0f(%rip), %rax     # 0x19dd8
movq (%rax), %rdi
movq -0x60(%rbp), %rsi
movq -0x88(%rbp), %rdx
callq 0xf550
jmp 0x5ede
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x5bc8
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)