// File: /workspace/github_c_makefile_star2_O3/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, %r12d
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rsi
callq 0xbe20
cmpl $-0x1, %eax
je 0xcd44
movl %eax, %ebp
movq 0x10(%r14), %rax
testq %rax, %rax
je 0xcd5e
xorl %r13d, %r13d
xorl %r15d, %r15d
movq 0x8(%r14), %rcx
movq (%rcx,%r15,8), %rcx
cmpl $0x1, 0x8(%rcx)
jne 0xccf4
incq %r13
movq (%rcx), %rsi
movq %rbx, %rdi
callq 0xbe63
movq 0x10(%r14), %rax
incq %r15
cmpq %rax, %r15
jb 0xccd4
movq 0x8(%rbx), %r15
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
jne 0xcda2
testq %rsi, %rsi
je 0xcdaf
leaq (%rsi,%rsi), %rax
movq %rax, 0x10(%r15)
movq (%r15), %rdi
shlq $0x4, %rsi
callq 0x1160
movq 0x8(%rbx), %r15
movq %rax, (%r15)
testq %rax, %rax
je 0xd1d0
movq 0x8(%r15), %rsi
jmp 0xcdcf
movups 0x18(%r14), %xmm0
movups %xmm0, 0x40(%rbx)
movl $0xffffffff, 0x58(%rbx) # imm = 0xFFFFFFFF
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xd188
movq 0x8(%rbx), %r14
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
jne 0xcda7
testq %rsi, %rsi
je 0xd0eb
leaq (%rsi,%rsi), %rax
movq %rax, 0x10(%r14)
movq (%r14), %rdi
shlq $0x4, %rsi
callq 0x1160
movq 0x8(%rbx), %r14
movq %rax, (%r14)
testq %rax, %rax
je 0xd1e8
movq 0x8(%r14), %rsi
jmp 0xd10b
movq (%r15), %rax
jmp 0xcdcf
movq (%r14), %rax
jmp 0xd10b
movq $0x1, 0x10(%r15)
movl $0x8, %edi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xd1f0
xorl %esi, %esi
cmpl $0x1, %r12d
movl $0x9, %ecx
sbbq $0x0, %rcx
movq %rcx, (%rax,%rsi,8)
movq 0x8(%r15), %rsi
incq %rsi
movq %rsi, 0x8(%r15)
cmpq 0x10(%r15), %rsi
jne 0xce40
testq %rsi, %rsi
je 0xce20
leaq (%rsi,%rsi), %rcx
movq %rcx, 0x10(%r15)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x1160
movq 0x8(%rbx), %r15
movq %rax, (%r15)
testq %rax, %rax
je 0xd1d8
movq 0x8(%r15), %rsi
jmp 0xce40
movq $0x1, 0x10(%r15)
movl $0x8, %edi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xd1f5
xorl %esi, %esi
movslq %ebp, %rcx
movq %rcx, (%rax,%rsi,8)
movq 0x8(%r15), %rsi
incq %rsi
movq %rsi, 0x8(%r15)
cmpq 0x10(%r15), %rsi
jne 0xcea7
testq %rsi, %rsi
je 0xce87
leaq (%rsi,%rsi), %rcx
movq %rcx, 0x10(%r15)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x1160
movq 0x8(%rbx), %r15
movq %rax, (%r15)
testq %rax, %rax
je 0xd1e0
movq 0x8(%r15), %rsi
jmp 0xcea7
movq $0x1, 0x10(%r15)
movl $0x8, %edi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xd202
xorl %esi, %esi
movq 0x10(%r14), %rcx
movq %rcx, (%rax,%rsi,8)
incq 0x8(%r15)
testq %rcx, %rcx
je 0xd186
xorl %ebp, %ebp
leaq 0x30(%rsp), %r12
movq 0x8(%r14), %rax
movq (%rax,%rbp,8), %rax
movl 0x8(%rax), %edi
cmpl $0x1, %edi
je 0xcf3c
testl %edi, %edi
jne 0xd197
movq (%rax), %rsi
movq $0x0, 0x50(%rsp)
movl $0x20, %edx
movq %r12, %rdi
callq 0x1040
movl $0x2, 0x50(%rsp)
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
jne 0xcf7a
testq %rsi, %rsi
je 0xcff5
leaq (%rsi,%rsi), %rax
movq %rax, 0x10(%r15)
movq (%r15), %rdi
shlq $0x4, %rsi
callq 0x1160
movq 0x8(%rbx), %r15
movq %rax, (%r15)
testq %rax, %rax
je 0xd19c
movq 0x8(%r15), %rsi
jmp 0xd015
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
jne 0xcf75
testq %rsi, %rsi
je 0xcf82
leaq (%rsi,%rsi), %rax
movq %rax, 0x10(%r15)
movq (%r15), %rdi
shlq $0x4, %rsi
callq 0x1160
movq 0x8(%rbx), %r15
movq %rax, (%r15)
testq %rax, %rax
je 0xd1ac
movq 0x8(%r15), %rsi
jmp 0xcfa2
movq (%r15), %rax
jmp 0xcfa2
movq (%r15), %rax
jmp 0xd015
movq $0x1, 0x10(%r15)
movl $0x8, %edi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xd1cb
xorl %esi, %esi
movq $0x0, (%rax,%rsi,8)
movq 0x8(%r15), %rsi
incq %rsi
movq %rsi, 0x8(%r15)
cmpq 0x10(%r15), %rsi
jne 0xd078
testq %rsi, %rsi
je 0xd058
leaq (%rsi,%rsi), %rcx
movq %rcx, 0x10(%r15)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x1160
movq 0x8(%rbx), %r15
movq %rax, (%r15)
testq %rax, %rax
je 0xd1b4
movq 0x8(%r15), %rsi
jmp 0xd078
movq $0x1, 0x10(%r15)
movl $0x8, %edi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xd1c1
xorl %esi, %esi
movq $0x1, (%rax,%rsi,8)
movq 0x8(%r15), %rsi
incq %rsi
movq %rsi, 0x8(%r15)
cmpq 0x10(%r15), %rsi
jne 0xd09f
testq %rsi, %rsi
je 0xd081
leaq (%rsi,%rsi), %rcx
movq %rcx, 0x10(%r15)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x1160
movq 0x8(%rbx), %r15
movq %rax, (%r15)
testq %rax, %rax
jne 0xd09f
jmp 0xd1a4
movq $0x1, 0x10(%r15)
movl $0x8, %edi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xd1c6
xorl %esi, %esi
decq %r13
movq %r13, (%rax,%rsi,8)
jmp 0xd0d5
movq $0x1, 0x10(%r15)
movl $0x8, %edi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xd1bc
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r15, %rdi
callq 0xbf36
cltq
movq 0x8(%rbx), %r15
movq (%r15), %rcx
movq 0x8(%r15), %rdx
movq %rax, (%rcx,%rdx,8)
incq 0x8(%r15)
incq %rbp
cmpq 0x10(%r14), %rbp
jb 0xcec3
jmp 0xd186
movq $0x1, 0x10(%r14)
movl $0x8, %edi
callq 0x1130
movq %rax, (%r14)
testq %rax, %rax
je 0xd207
xorl %esi, %esi
cmpl $0x1, %r12d
movl $0x4, %ecx
sbbq $0x0, %rcx
movq %rcx, (%rax,%rsi,8)
movq 0x8(%r14), %rsi
incq %rsi
movq %rsi, 0x8(%r14)
cmpq 0x10(%r14), %rsi
jne 0xd17c
testq %rsi, %rsi
je 0xd15c
leaq (%rsi,%rsi), %rcx
movq %rcx, 0x10(%r14)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x1160
movq 0x8(%rbx), %r14
movq %rax, (%r14)
testq %rax, %rax
je 0xd1fa
movq 0x8(%r14), %rsi
jmp 0xd17c
movq $0x1, 0x10(%r14)
movl $0x8, %edi
callq 0x1130
movq %rax, (%r14)
testq %rax, %rax
je 0xd20c
xorl %esi, %esi
movl %ebp, %ecx
movq %rcx, (%rax,%rsi,8)
incq 0x8(%r14)
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x38fa
movq %r15, %rdi
callq 0x3828
movq %r15, %rdi
callq 0x3860
movq %r15, %rdi
callq 0x3756
movq %r15, %rdi
callq 0x378e
callq 0x3898
callq 0x38c9
callq 0x37c6
callq 0x37f7
movq %r15, %rdi
callq 0x36ae
movq %r15, %rdi
callq 0x36e6
movq %r15, %rdi
callq 0x371e
movq %r14, %rdi
callq 0x39b0
callq 0x397f
callq 0x394e
movq %r14, %rdi
callq 0x39e8
callq 0x391d
callq 0x3a51
callq 0x3a20