// File: /workspace/github_c_makefile_star2_O2/chgzm[P]minic/generator.c
// Function: process_declaration
static void process_declaration(const DeclarationNode* node) {
    Type* type = NULL;
    for (int i = 0; i < node->decl_specifier_nodes->size; ++i) {
        const DeclSpecifierNode* decl_specifier_node = node->decl_specifier_nodes->elements[i];
        const TypeSpecifierNode* type_specifier_node = decl_specifier_node->type_specifier_node;
        if (type_specifier_node == NULL) {
            continue;
        }

        type = process_type_specifier_in_local(type_specifier_node);
        break;
    }

    // add local-variable to list
    for (int j = 0; j < node->init_declarator_nodes->size; ++j) {
        LocalVar* lv = malloc(sizeof(LocalVar));
        lv->type     = type;

        const InitDeclaratorNode* init_declarator_node = node->init_declarator_nodes->elements[j];
        const DeclaratorNode* declarator_node  = init_declarator_node->declarator_node;

        const PointerNode* pointer_node = declarator_node->pointer_node;
        if (pointer_node != NULL) {
            lv->type->ptr_count = pointer_node->count;
            lv->type->size      = 8;
        } else {
            lv->type->size = lv->type->type_size;
        }

        const DirectDeclaratorNode* direct_declarator_node = declarator_node->direct_declarator_node;
        const ConditionalExprNode*  conditional_expr_node  = direct_declarator_node->conditional_expr_node;
        if (conditional_expr_node == NULL) {
            lv->type->array_size = 0;
            current_offset += lv->type->size;
        } else {
            lv->type->array_size = get_array_size_from_constant_expr(conditional_expr_node);
            current_offset += (lv->type->array_size * lv->type->size);

        }
        lv->offset = align_offset(current_offset, lv->type->size);

        const DirectDeclaratorNode* ident_node = get_identifier_direct_declarator(direct_declarator_node);
        lv->name = strdup(ident_node->identifier);
        vector_push_back(localvar_list, lv);

        if (init_declarator_node->initializer_node != NULL) {
            const InitializerNode* initializer_node = init_declarator_node->initializer_node;
            printf("  lea rax, [rbp-%d]\n", lv->offset);
            printf("  push rax\n");

            if (initializer_node->assign_expr_node != NULL) {
                process_assign_expr(initializer_node->assign_expr_node);
            }

            printf("  pop rdi\n");
            printf("  pop rax\n");
            if (lv->type->size == 1) {
                printf("  mov [rax], dil\n");
            } else {
                printf("  mov [rax], rdi\n");
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, (%rsp)
movq (%rdi), %rax
movl 0x8(%rax), %ecx
xorl %r14d, %r14d
testl %ecx, %ecx
cmovlel %r14d, %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x2f71
movq (%rax), %rsi
movq (%rsi,%rdx,8), %rsi
movq (%rsi), %rdi
incq %rdx
testq %rdi, %rdi
je 0x2f52
callq 0x2e58
movq %rax, %r14
xorl %r15d, %r15d
movq (%rsp), %rax
movq 0x8(%rax), %rbx
movslq 0x8(%rbx), %rax
cmpq %rax, %r15
jge 0x30a1
pushq $0x18
popq %rdi
callq 0x1100
movq %rax, %r13
movq %r14, (%rax)
movq (%rbx), %rax
movq (%rax,%r15,8), %r12
movq (%r12), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x2fb5
movl (%rcx), %ecx
movl %ecx, 0x10(%r14)
pushq $0x8
popq %rbx
jmp 0x2fb9
movl 0x4(%r14), %ebx
movl %ebx, 0x8(%r14)
movq 0x8(%rax), %rbp
movq 0x18(%rbp), %rdi
testq %rdi, %rdi
je 0x2fda
callq 0x2a89
movl %eax, %ecx
movl %eax, 0xc(%r14)
imull %ebx, %ecx
jmp 0x2fe1
andl $0x0, 0xc(%r14)
movl %ebx, %ecx
addl 0xb161(%rip), %ecx      # 0xe148
movl %ecx, 0xb15b(%rip)      # 0xe148
cmpl $0x1, %ebx
je 0x3006
movl %ecx, %eax
cltd
pushq $0x8
popq %rsi
idivl %esi
movl %ecx, %eax
subl %edx, %eax
addl $0x8, %eax
testl %edx, %edx
cmovnel %eax, %ecx
movl %ecx, 0x14(%r13)
movq %rbp, %rdi
callq 0x2abe
movq (%rax), %rdi
callq 0x1190
movq %rax, 0x8(%r13)
movq 0xb11b(%rip), %rdi      # 0xe140
movq %r13, %rsi
callq 0x8167
movq 0x8(%r12), %rbx
testq %rbx, %rbx
je 0x3099
movl 0x14(%r13), %esi
leaq 0x65e2(%rip), %rdi      # 0x9624
xorl %eax, %eax
callq 0x10a0
leaq 0x68e5(%rip), %rdi      # 0x9935
callq 0x1070
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x3062
callq 0x3608
leaq 0x68c2(%rip), %rdi      # 0x992b
callq 0x1070
leaq 0x68da(%rip), %rdi      # 0x994f
callq 0x1070
movq (%r13), %rax
cmpl $0x1, 0x8(%rax)
leaq 0x67da(%rip), %rdi      # 0x9863
leaq 0x66a9(%rip), %rax      # 0x9739
cmoveq %rax, %rdi
callq 0x1070
incq %r15
jmp 0x2f74
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq