// File: /workspace/github_c_makefile_star2_O2/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, %r13d
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rsi
callq 0x9d5d
cmpl $-0x1, %eax
je 0xb1a0
movl %eax, %ebp
movq 0x10(%r14), %rax
testq %rax, %rax
je 0xb1b5
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpq %rax, %r15
jae 0xb158
movq 0x8(%r14), %rcx
movq (%rcx,%r15,8), %rcx
cmpl $0x1, 0x8(%rcx)
jne 0xb153
incq %r12
movq (%rcx), %rsi
movq %rbx, %rdi
callq 0x9da7
movq 0x10(%r14), %rax
incq %r15
jmp 0xb12e
movq 0x8(%rbx), %r15
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
jne 0xb1f9
testq %rsi, %rsi
je 0xb206
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 0xb6fb
movq 0x8(%r15), %rsi
jmp 0xb224
movups 0x18(%r14), %xmm0
movups %xmm0, 0x40(%rbx)
orl $-0x1, 0x58(%rbx)
pushq $-0x1
popq %rax
jmp 0xb5a8
movq 0x8(%rbx), %r14
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
jne 0xb1fe
testq %rsi, %rsi
je 0xb511
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 0xb76a
movq 0x8(%r14), %rsi
jmp 0xb52f
movq (%r15), %rax
jmp 0xb224
movq (%r14), %rax
jmp 0xb52f
movq $0x1, 0x10(%r15)
pushq $0x8
popq %rdi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xb78f
xorl %esi, %esi
cmpl $0x1, %r13d
pushq $0x9
popq %rcx
sbbq $0x0, %rcx
movq %rcx, (%rax,%rsi,8)
movq 0x8(%r15), %rsi
incq %rsi
movq %rsi, 0x8(%r15)
cmpq 0x10(%r15), %rsi
jne 0xb291
testq %rsi, %rsi
je 0xb273
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 0xb720
movq 0x8(%r15), %rsi
jmp 0xb291
movq $0x1, 0x10(%r15)
pushq $0x8
popq %rdi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xb7b5
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 0xb2f6
testq %rsi, %rsi
je 0xb2d8
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 0xb745
movq 0x8(%r15), %rsi
jmp 0xb2f6
movq $0x1, 0x10(%r15)
pushq $0x8
popq %rdi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xb7fd
xorl %esi, %esi
movq 0x10(%r14), %rcx
movq %rcx, (%rax,%rsi,8)
incq 0x8(%r15)
leaq 0x30(%rsp), %rbp
xorl %r13d, %r13d
cmpq %rcx, %r13
jae 0xb5a6
movq 0x8(%r14), %rax
movq (%rax,%r13,8), %rax
movl 0x8(%rax), %edx
cmpl $0x1, %edx
je 0xb376
testl %edx, %edx
jne 0xb5b7
movq (%rax), %rsi
movq %rbp, %rdi
callq 0x85c8
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
jne 0xb3b4
testq %rsi, %rsi
je 0xb427
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 0xb5d4
movq 0x8(%r15), %rsi
jmp 0xb445
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
jne 0xb3af
testq %rsi, %rsi
je 0xb3bc
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 0xb61b
movq 0x8(%r15), %rsi
jmp 0xb3da
movq (%r15), %rax
jmp 0xb3da
movq (%r15), %rax
jmp 0xb445
movq $0x1, 0x10(%r15)
pushq $0x8
popq %rdi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xb6cb
xorl %esi, %esi
andq $0x0, (%rax,%rsi,8)
movq 0x8(%r15), %rsi
incq %rsi
movq %rsi, 0x8(%r15)
cmpq 0x10(%r15), %rsi
jne 0xb4a6
testq %rsi, %rsi
je 0xb488
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 0xb640
movq 0x8(%r15), %rsi
jmp 0xb4a6
movq $0x1, 0x10(%r15)
pushq $0x8
popq %rdi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xb685
xorl %esi, %esi
movq $0x1, (%rax,%rsi,8)
movq 0x8(%r15), %rsi
incq %rsi
movq %rsi, 0x8(%r15)
cmpq 0x10(%r15), %rsi
jne 0xb4cb
testq %rsi, %rsi
je 0xb4af
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 0xb4cb
jmp 0xb5f9
movq $0x1, 0x10(%r15)
pushq $0x8
popq %rdi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xb6a8
xorl %esi, %esi
decq %r12
movq %r12, (%rax,%rsi,8)
jmp 0xb501
movq $0x1, 0x10(%r15)
pushq $0x8
popq %rdi
callq 0x1130
movq %rax, (%r15)
testq %rax, %rax
je 0xb662
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 0x9ec2
cltq
movq 0x8(%rbx), %r15
movq (%r15), %rcx
movq 0x8(%r15), %rdx
movq %rax, (%rcx,%rdx,8)
incq 0x8(%r15)
incq %r13
movq 0x10(%r14), %rcx
jmp 0xb30a
movq $0x1, 0x10(%r14)
pushq $0x8
popq %rdi
callq 0x1130
movq %rax, (%r14)
testq %rax, %rax
je 0xb823
xorl %esi, %esi
cmpl $0x1, %r13d
pushq $0x4
popq %rcx
sbbq $0x0, %rcx
movq %rcx, (%rax,%rsi,8)
movq 0x8(%r14), %rsi
incq %rsi
movq %rsi, 0x8(%r14)
cmpq 0x10(%r14), %rsi
jne 0xb59c
testq %rsi, %rsi
je 0xb57e
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 0xb7db
movq 0x8(%r14), %rsi
jmp 0xb59c
movq $0x1, 0x10(%r14)
pushq $0x8
popq %rdi
callq 0x1130
movq %rax, (%r14)
testq %rax, %rax
je 0xb849
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
movq 0xaa32(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x4231(%rip), %rsi      # 0xf7f9
xorl %eax, %eax
callq 0x1100
jmp 0xb6f3
movq 0xaa15(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq 0x10(%r15), %r8
shlq $0x3, %r8
leaq 0x3304(%rip), %rsi      # 0xe8f1
leaq 0x3d24(%rip), %rdx      # 0xf318
jmp 0xb6a1
movq 0xa9f0(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq 0x10(%r15), %r8
shlq $0x3, %r8
leaq 0x32df(%rip), %rsi      # 0xe8f1
leaq 0x3cff(%rip), %rdx      # 0xf318
jmp 0xb67e
movq 0xa9ce(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq 0x10(%r15), %r8
shlq $0x3, %r8
leaq 0x32bd(%rip), %rsi      # 0xe8f1
leaq 0x3cdd(%rip), %rdx      # 0xf318
jmp 0xb6e7
movq 0xa9a9(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq 0x10(%r15), %r8
shlq $0x3, %r8
leaq 0x3298(%rip), %rsi      # 0xe8f1
leaq 0x3cb8(%rip), %rdx      # 0xf318
jmp 0xb6c4
movq 0xa987(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x2f4b(%rip), %rsi      # 0xe5be
leaq 0x3c9e(%rip), %rdx      # 0xf318
pushq $0x8
popq %r8
movl $0xe4, %ecx
jmp 0xb6ec
movq 0xa964(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x2f28(%rip), %rsi      # 0xe5be
leaq 0x3c7b(%rip), %rdx      # 0xf318
pushq $0x8
popq %r8
movl $0xe3, %ecx
jmp 0xb6ec
movq 0xa941(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x2f05(%rip), %rsi      # 0xe5be
leaq 0x3c58(%rip), %rdx      # 0xf318
pushq $0x8
popq %r8
movl $0xe8, %ecx
jmp 0xb6ec
movq 0xa91e(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x2ee2(%rip), %rsi      # 0xe5be
leaq 0x3c35(%rip), %rdx      # 0xf318
pushq $0x8
popq %r8
movl $0xe6, %ecx
xorl %eax, %eax
callq 0x1100
pushq $0x1
popq %rdi
callq 0x1180
movq 0xa8ee(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq 0x10(%r15), %r8
shlq $0x3, %r8
leaq 0x31dd(%rip), %rsi      # 0xe8f1
leaq 0x3bfd(%rip), %rdx      # 0xf318
jmp 0xb7ab
movq 0xa8c9(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq 0x10(%r15), %r8
shlq $0x3, %r8
leaq 0x31b8(%rip), %rsi      # 0xe8f1
leaq 0x3bd8(%rip), %rdx      # 0xf318
jmp 0xb7d1
movq 0xa8a4(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq 0x10(%r15), %r8
shlq $0x3, %r8
leaq 0x3193(%rip), %rsi      # 0xe8f1
leaq 0x3bb3(%rip), %rdx      # 0xf318
jmp 0xb819
movq 0xa87f(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq 0x10(%r14), %r8
shlq $0x3, %r8
leaq 0x316e(%rip), %rsi      # 0xe8f1
leaq 0x3b8e(%rip), %rdx      # 0xf318
jmp 0xb83f
movq 0xa85a(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x2e1e(%rip), %rsi      # 0xe5be
leaq 0x3b71(%rip), %rdx      # 0xf318
pushq $0x8
popq %r8
movl $0xdc, %ecx
jmp 0xb6ec
movq 0xa834(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x2df8(%rip), %rsi      # 0xe5be
leaq 0x3b4b(%rip), %rdx      # 0xf318
pushq $0x8
popq %r8
movl $0xdd, %ecx
jmp 0xb6ec
movq 0xa80e(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq 0x10(%r14), %r8
shlq $0x3, %r8
leaq 0x30fd(%rip), %rsi      # 0xe8f1
leaq 0x3b1d(%rip), %rdx      # 0xf318
jmp 0xb865
movq 0xa7ec(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x2db0(%rip), %rsi      # 0xe5be
leaq 0x3b03(%rip), %rdx      # 0xf318
pushq $0x8
popq %r8
movl $0xde, %ecx
jmp 0xb6ec
movq 0xa7c6(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x2d8a(%rip), %rsi      # 0xe5be
leaq 0x3add(%rip), %rdx      # 0xf318
pushq $0x8
popq %r8
movl $0xce, %ecx
jmp 0xb6ec
movq 0xa7a0(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x2d64(%rip), %rsi      # 0xe5be
leaq 0x3ab7(%rip), %rdx      # 0xf318
pushq $0x8
popq %r8
movl $0xcf, %ecx
jmp 0xb6ec