// File: /workspace/github_c_makefile_star2_O1/masyagin1998[P]GCI/src/bytecode-generator/bytecode-generator.c
// Function: variable_ast_bytecode_generate_inner
static enum BYTECODE_GENERATOR_CODES variable_ast_bytecode_generate_inner(bytecode_generator_type_t bc_gen, const struct VARIABLE_AST*ast, int is_set_op)
{
    int idx = local_variable_index(bc_gen, ast->ident->ident);

    if (idx == -1) {
        set_bytecode_generator_error(bc_gen, ast->line, ast->pos, BYTECODE_GENERATOR_NO_LOCAL_VARIABLE);
        return BYTECODE_GENERATOR_NO_LOCAL_VARIABLE;
    }

    if (ast->parts_len == 0) {
        PUSH_BACK(bc_gen->bc->op_codes, is_set_op ? BC_OP_SET_LOCAL : BC_OP_GET_LOCAL);
        PUSH_BACK(bc_gen->bc->op_codes, idx);        
    } else {
        size_t i;
        size_t count = 0;

        /* Generate code for array indexes. */
        for (i = 0; i < ast->parts_len; i++) {
            if (ast->parts[i]->type == AST_VARIABLE_PART_TYPE_INDEX) {
                count++;
                logical_or_expr_ast_bytecode_generate(bc_gen, ast->parts[i]->index);
            }
        }
        
        PUSH_BACK(bc_gen->bc->op_codes, is_set_op ? BC_OP_SET_HEAP : BC_OP_GET_HEAP);
        PUSH_BACK(bc_gen->bc->op_codes, idx);
        PUSH_BACK(bc_gen->bc->op_codes, ast->parts_len);

        for (i = 0; i < ast->parts_len; i++) {
            if (ast->parts[i]->type == AST_VARIABLE_PART_TYPE_FIELD) {
                struct CONSTANT cnst = create_constant_from_fieldref(ast->parts[i]->field->ident);
                PUSH_BACK(bc_gen->bc->op_codes, BC_OBJECT_FIELD);
                PUSH_BACK(bc_gen->bc->op_codes, constant_pool_push_back(bc_gen->bc, cnst));   
            } else if (ast->parts[i]->type == AST_VARIABLE_PART_TYPE_INDEX) {
                PUSH_BACK(bc_gen->bc->op_codes, BC_ARRAY_INDEX);
                count--;
                PUSH_BACK(bc_gen->bc->op_codes, count);
            } else {
                fprintf(stderr, "Invalid VARIALE_PART_TYPE: %d\n", ast->parts[i]->type);
                exit(EXIT_FAILURE);        
            }
        }   
    }
    
    return BYTECODE_GENERATOR_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rsi
callq 0xc1b6
cmpl $-0x1, %eax
je 0xd01f
movl %eax, %ebp
cmpq $0x0, 0x10(%r14)
je 0xd039
cmpq $0x0, 0x10(%r14)
je 0xd07d
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x8(%r14), %rax
movq (%rax,%r13,8), %rax
cmpl $0x1, 0x8(%rax)
jne 0xd014
incq %r12
movq (%rax), %rsi
movq %rbx, %rdi
callq 0xc1f9
incq %r13
cmpq 0x10(%r14), %r13
jb 0xcff8
jmp 0xd080
movups 0x18(%r14), %xmm0
movups %xmm0, 0x40(%rbx)
movl $0xffffffff, 0x58(%rbx) # imm = 0xFFFFFFFF
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xd4dc
movq 0x8(%rbx), %r14
movq 0x10(%r14), %rsi
cmpq %rsi, 0x8(%r14)
jne 0xd453
testq %rsi, %rsi
je 0xd435
leaq (%rsi,%rsi), %rax
movq %rax, 0x10(%r14)
movq (%r14), %rdi
shlq $0x4, %rsi
callq 0x1160
movq 0x8(%rbx), %rdi
movq %rax, (%rdi)
testq %rax, %rax
jne 0xd453
callq 0x3992
xorl %r12d, %r12d
movq 0x8(%rbx), %r13
movq 0x10(%r13), %rsi
cmpq %rsi, 0x8(%r13)
jne 0xd0d8
testq %rsi, %rsi
je 0xd0b9
leaq (%rsi,%rsi), %rax
movq %rax, 0x10(%r13)
movq (%r13), %rdi
shlq $0x4, %rsi
callq 0x1160
movq 0x8(%rbx), %rdi
movq %rax, (%rdi)
testq %rax, %rax
jne 0xd0d8
callq 0x3690
movq $0x1, 0x10(%r13)
movl $0x8, %edi
callq 0x1130
movq %rax, (%r13)
testq %rax, %rax
je 0xd518
cmpl $0x1, %r15d
movl $0x9, %eax
sbbq $0x0, %rax
movq 0x8(%rbx), %r15
movq (%r15), %rdi
movq 0x8(%r15), %rcx
movq %rax, (%rdi,%rcx,8)
movq 0x8(%r15), %rax
movq 0x10(%r15), %rsi
incq %rax
movq %rax, 0x8(%r15)
cmpq %rsi, %rax
jne 0xd14d
testq %rsi, %rsi
je 0xd12f
leaq (%rsi,%rsi), %rax
movq %rax, 0x10(%r15)
shlq $0x4, %rsi
callq 0x1160
movq 0x8(%rbx), %rdi
movq %rax, (%rdi)
testq %rax, %rax
jne 0xd14d
callq 0x36c8
movq $0x1, 0x10(%r15)
movl $0x8, %edi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xd51d
movslq %ebp, %rax
movq 0x8(%rbx), %r15
movq (%r15), %rdi
movq 0x8(%r15), %rcx
movq %rax, (%rdi,%rcx,8)
movq 0x8(%r15), %rax
movq 0x10(%r15), %rsi
incq %rax
movq %rax, 0x8(%r15)
cmpq %rsi, %rax
jne 0xd1b8
testq %rsi, %rsi
je 0xd19a
leaq (%rsi,%rsi), %rax
movq %rax, 0x10(%r15)
shlq $0x4, %rsi
callq 0x1160
movq 0x8(%rbx), %rdi
movq %rax, (%rdi)
testq %rax, %rax
jne 0xd1b8
callq 0x3700
movq $0x1, 0x10(%r15)
movl $0x8, %edi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xd522
movq 0x10(%r14), %rax
movq 0x8(%rbx), %rcx
movq (%rcx), %rdx
movq 0x8(%rcx), %rsi
movq %rax, (%rdx,%rsi,8)
incq 0x8(%rcx)
cmpq $0x0, 0x10(%r14)
je 0xd4da
xorl %r13d, %r13d
leaq 0x30(%rsp), %r15
movq 0x8(%r14), %rax
movq (%rax,%r13,8), %rcx
movl 0x8(%rcx), %edi
cmpl $0x1, %edi
je 0xd271
testl %edi, %edi
jne 0xd4eb
movq (%rax,%r13,8), %rax
movq (%rax), %rsi
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x50(%rsp)
movl $0x20, %edx
movq %r15, %rdi
callq 0x1040
movl $0x2, 0x50(%rsp)
movq 0x8(%rbx), %rbp
movq 0x10(%rbp), %rsi
cmpq %rsi, 0x8(%rbp)
jne 0xd343
testq %rsi, %rsi
je 0xd324
leaq (%rsi,%rsi), %rax
movq %rax, 0x10(%rbp)
movq (%rbp), %rdi
shlq $0x4, %rsi
callq 0x1160
movq 0x8(%rbx), %rdi
movq %rax, (%rdi)
testq %rax, %rax
jne 0xd343
jmp 0xd4f0
movq 0x8(%rbx), %rbp
movq 0x10(%rbp), %rsi
cmpq %rsi, 0x8(%rbp)
jne 0xd2c9
testq %rsi, %rsi
je 0xd2aa
leaq (%rsi,%rsi), %rax
movq %rax, 0x10(%rbp)
movq (%rbp), %rdi
shlq $0x4, %rsi
callq 0x1160
movq 0x8(%rbx), %rdi
movq %rax, (%rdi)
testq %rax, %rax
jne 0xd2c9
jmp 0xd4fa
movq $0x1, 0x10(%rbp)
movl $0x8, %edi
callq 0x1130
movq %rax, (%rbp)
testq %rax, %rax
je 0xd513
movq 0x8(%rbx), %rbp
movq (%rbp), %rdi
movq 0x8(%rbp), %rax
movq $0x0, (%rdi,%rax,8)
movq 0x8(%rbp), %rax
movq 0x10(%rbp), %rsi
incq %rax
movq %rax, 0x8(%rbp)
cmpq %rsi, %rax
jne 0xd3b1
testq %rsi, %rsi
je 0xd392
leaq (%rsi,%rsi), %rax
movq %rax, 0x10(%rbp)
shlq $0x4, %rsi
callq 0x1160
movq 0x8(%rbx), %rdi
movq %rax, (%rdi)
testq %rax, %rax
jne 0xd3b1
jmp 0xd4ff
movq $0x1, 0x10(%rbp)
movl $0x8, %edi
callq 0x1130
movq %rax, (%rbp)
testq %rax, %rax
je 0xd509
movq 0x8(%rbx), %rbp
movq (%rbp), %rdi
movq 0x8(%rbp), %rax
movq $0x1, (%rdi,%rax,8)
movq 0x8(%rbp), %rax
movq 0x10(%rbp), %rsi
incq %rax
movq %rax, 0x8(%rbp)
cmpq %rsi, %rax
jne 0xd3e8
testq %rsi, %rsi
je 0xd3c9
leaq (%rsi,%rsi), %rax
movq %rax, 0x10(%rbp)
shlq $0x4, %rsi
callq 0x1160
movq 0x8(%rbx), %rdi
movq %rax, (%rdi)
testq %rax, %rax
jne 0xd3e8
jmp 0xd4f5
movq $0x1, 0x10(%rbp)
movl $0x8, %edi
callq 0x1130
movq %rax, (%rbp)
testq %rax, %rax
je 0xd50e
decq %r12
movq 0x8(%rbx), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rdx
movq %r12, (%rcx,%rdx,8)
incq 0x8(%rax)
jmp 0xd423
movq $0x1, 0x10(%rbp)
movl $0x8, %edi
callq 0x1130
movq %rax, (%rbp)
testq %rax, %rax
je 0xd504
movq 0x8(%rbx), %rdi
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0xc2cf
cltq
movq 0x8(%rbx), %rcx
movq (%rcx), %rdx
movq 0x8(%rcx), %rsi
movq %rax, (%rdx,%rsi,8)
incq 0x8(%rcx)
incq %r13
cmpq 0x10(%r14), %r13
jb 0xd1e2
jmp 0xd4da
movq $0x1, 0x10(%r14)
movl $0x8, %edi
callq 0x1130
movq %rax, (%r14)
testq %rax, %rax
je 0xd527
cmpl $0x1, %r15d
movl $0x4, %eax
sbbq $0x0, %rax
movq 0x8(%rbx), %r14
movq (%r14), %rdi
movq 0x8(%r14), %rcx
movq %rax, (%rdi,%rcx,8)
movq 0x8(%r14), %rax
movq 0x10(%r14), %rsi
incq %rax
movq %rax, 0x8(%r14)
cmpq %rsi, %rax
jne 0xd4c4
testq %rsi, %rsi
je 0xd4aa
leaq (%rsi,%rsi), %rax
movq %rax, 0x10(%r14)
shlq $0x4, %rsi
callq 0x1160
movq 0x8(%rbx), %rdi
movq %rax, (%rdi)
testq %rax, %rax
jne 0xd4c4
callq 0x39ca
movq $0x1, 0x10(%r14)
movl $0x8, %edi
callq 0x1130
movq %rax, (%r14)
testq %rax, %rax
je 0xd52c
movslq %ebp, %rax
movq 0x8(%rbx), %rcx
movq (%rcx), %rdx
movq 0x8(%rcx), %rsi
movq %rax, (%rdx,%rsi,8)
incq 0x8(%rcx)
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x38dc
callq 0x380a
callq 0x3842
callq 0x3738
callq 0x3770
callq 0x387a
callq 0x38ab
callq 0x37a8
callq 0x37d9
callq 0x3961
callq 0x3930
callq 0x38ff
callq 0x3a33
callq 0x3a02