// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0x428e
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x4274
jmp 0x4283
movq -0x28(%rbp), %rdi
callq 0x4010
movq %rax, -0x10(%rbp)
jmp 0x428e
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x423b
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0x44a4
movl $0x18, %edi
callq 0x10f0
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x4316
movq -0x50(%rbp), %rax
movl (%rax), %ecx
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x10(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl $0x8, 0x8(%rax)
jmp 0x432a
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %ecx
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x8(%rax)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x436f
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl $0x0, 0xc(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %eax
addl 0x10e09(%rip), %eax     # 0x15170
movl %eax, 0x10e03(%rip)     # 0x15170
jmp 0x43a5
movq -0x60(%rbp), %rdi
callq 0x3660
movl %eax, %ecx
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl 0xc(%rax), %eax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
imull 0x8(%rcx), %eax
addl 0x10dd1(%rip), %eax     # 0x15170
movl %eax, 0x10dcb(%rip)     # 0x15170
movl 0x10dc5(%rip), %edi     # 0x15170
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %esi
callq 0x4570
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x58(%rbp), %rdi
callq 0x36b0
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %rdi
callq 0x1170
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq 0x10d7a(%rip), %rdi     # 0x15168
movq -0x38(%rbp), %rsi
callq 0xe610
movq -0x40(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x4494
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rax
movl 0x14(%rax), %esi
leaq 0xb298(%rip), %rdi      # 0xf6b8
movb $0x0, %al
callq 0x1090
leaq 0xb29f(%rip), %rdi      # 0xf6cd
movb $0x0, %al
callq 0x1090
movq -0x70(%rbp), %rax
cmpq $0x0, (%rax)
je 0x444b
movq -0x70(%rbp), %rax
movq (%rax), %rdi
callq 0x45c0
leaq 0xb287(%rip), %rdi      # 0xf6d9
movb $0x0, %al
callq 0x1090
leaq 0xb284(%rip), %rdi      # 0xf6e4
movb $0x0, %al
callq 0x1090
movq -0x38(%rbp), %rax
movq (%rax), %rax
cmpl $0x1, 0x8(%rax)
jne 0x4484
leaq 0xb274(%rip), %rdi      # 0xf6ef
movb $0x0, %al
callq 0x1090
jmp 0x4492
leaq 0xb276(%rip), %rdi      # 0xf701
movb $0x0, %al
callq 0x1090
jmp 0x4494
jmp 0x4496
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x4295
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)