// File: /workspace/github_c_makefile_star2_O3/been-jamming[P]MinimalCC/expression.c
// Function: compile_list_index
void compile_list_index(char **c, value *address, unsigned char dereference, FILE *output_file){
	value index;
	type address_type;

	address_type = address->data_type;
	if(pop_type(&address_type) != type_pointer){
		snprintf(error_message, sizeof(error_message), "Cannot address non-pointer type");
		do_error(1);
	}
	++*c;
	compile_expression(&index, c, 1, 0, output_file);
	if(**c != ']'){
		snprintf(error_message, sizeof(error_message), "Expected closing ']'");
		do_error(1);
	}
	++*c;
	cast(&index, INT_TYPE, 1, output_file);
	if(index.data.type == data_register){
		if(type_size(&address_type, 0) == 4){
			fileprint(output_file, "sll $s%d, $s%d, 2\n", index.data.reg, index.data.reg);
		} else if(type_size(&address_type, 0) != 1){
			fileprint(output_file, "li $t0, %d\n", (int) type_size(&address_type, 0));
			fileprint(output_file, "mult $s%d, $t0\n", index.data.reg);
			fileprint(output_file, "mflo $s%d\n", index.data.reg);
		}
		if(address->data.type == data_register){
			fileprint(output_file, "add $s%d, $s%d, $s%d\n", address->data.reg, address->data.reg, index.data.reg);
			if(dereference && peek_type(&address_type) != type_list){
				if(type_size(&address_type, 0) == 4){
					fileprint(output_file, "lw $s%d, 0($s%d)\n", address->data.reg, address->data.reg);
				} else if(type_size(&address_type, 0) == 1){
					fileprint(output_file, "lb $s%d, 0($s%d)\n", address->data.reg, address->data.reg);
				} else {
					snprintf(error_message, sizeof(error_message), "[INTERNAL] Unusable type size");
					do_error(1);
				}
			}
		} else if(address->data.type == data_stack){
			fileprint(output_file, "lw $t0, %d($sp)\n", get_stack_pos(address->data));
			fileprint(output_file, "add $t0, $t0, $s%d\n", index.data.reg);
			if(dereference && peek_type(&address_type) != type_list){
				if(type_size(&address_type, 0) == 4){
					fileprint(output_file, "lw $t0, 0($t0)\n");
				} else if(type_size(&address_type, 0) == 1){
					fileprint(output_file, "lb $t0, 0($t0)\n");
				} else {
					snprintf(error_message, sizeof(error_message), "[INTERNAL] Unusable type size");
					do_error(1);
				}
			}
			fileprint(output_file, "sw $t0, %d($sp)\n", get_stack_pos(address->data));
		}
	} else if(index.data.type == data_stack){
		fileprint(output_file, "lw $t1, %d($sp)\n", get_stack_pos(index.data));
		if(type_size(&address_type, 0) == 4){
			fileprint(output_file, "sll $t1, $t1, 2\n");
		} else if(type_size(&address_type, 0) != 1){
			fileprint(output_file, "li $t0, %d\n", (int) type_size(&address_type, 0));
			fileprint(output_file, "mult $t1, $t0\n");
			fileprint(output_file, "mflo $t1\n");
		}
		if(address->data.type == data_register){
			fileprint(output_file, "add $s%d, $s%d, $t1\n", address->data.reg, address->data.reg);
			if(dereference && peek_type(&address_type) != type_list){
				if(type_size(&address_type, 0) == 4){
					fileprint(output_file, "lw $s%d, 0($s%d)\n", address->data.reg, address->data.reg);
				} else if(type_size(&address_type, 0) == 1){
					fileprint(output_file, "lb $s%d, 0($s%d)\n", address->data.reg, address->data.reg);
				}
			}
		} else if(address->data.type == data_stack){
			fileprint(output_file, "lw $t0, %d($sp)\n", get_stack_pos(address->data));
			fileprint(output_file, "add $t0, $t0, $t1\n");
			if(dereference && peek_type(&address_type) != type_list){
				if(type_size(&address_type, 0) == 4){
					fileprint(output_file, "lw $t0, 0($t0)\n");
				} else if(type_size(&address_type, 0) == 1){
					fileprint(output_file, "lb $t0, 0($t0)\n");
				}
			}
			fileprint(output_file, "sw $t0, %d($sp)\n", get_stack_pos(address->data));
		}
	}
	deallocate(index.data);
	if(dereference){
		pop_type(&(address->data_type));
		if(peek_type(&(address->data_type)) == type_list){
			pop_type(&(address->data_type));
			address->data_type.current_index--;
			add_type_entry(&(address->data_type), type_pointer);
		}
	}
	address->is_reference = !dereference;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xd8, %rsp
movq %rcx, %r14
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r15
movups 0x10(%rsi), %xmm0
movups 0x20(%rsi), %xmm1
movups 0x30(%rsi), %xmm2
movups 0x40(%rsi), %xmm3
leaq 0x40(%rsp), %rdi
movaps %xmm3, 0x30(%rdi)
movaps %xmm2, 0x20(%rdi)
movaps %xmm1, 0x10(%rdi)
movaps %xmm0, (%rdi)
callq 0x7ab4
cmpl $0x4, %eax
je 0x3e3f
movups 0x5a00(%rip), %xmm0     # 0x9820
leaq 0x96b9(%rip), %rax      # 0xd4e0
movaps %xmm0, 0x10(%rax)
movups 0x59de(%rip), %xmm0     # 0x9810
movaps %xmm0, (%rax)
movl $0x1, %edi
callq 0x5b10
incq (%r15)
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
movq %r14, %r8
callq 0x3d22
movq (%r15), %rax
cmpb $0x5d, (%rax)
je 0x3e90
movups 0x59c5(%rip), %xmm0     # 0x9830
leaq 0x966e(%rip), %rax      # 0xd4e0
movaps %xmm0, (%rax)
movabsq $0x275d2720676e69, %rcx # imm = 0x275D2720676E69
movq %rcx, 0xd(%rax)
movl $0x1, %edi
callq 0x5b10
movq (%r15), %rax
incq %rax
movq %rax, (%r15)
leaq 0x92e3(%rip), %rax      # 0xd180
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups 0x30(%rax), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x80(%rsp), %r15
movq %r15, %rdi
movl $0x1, %esi
movq %r14, %rdx
callq 0x340d
movl (%r15), %eax
cmpl $0x1, %eax
je 0x3f20
testl %eax, %eax
jne 0x422a
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1990
cmpl $0x1, %eax
je 0x3fb4
cmpl $0x4, %eax
jne 0x3f71
movl 0x84(%rsp), %ecx
leaq 0x5936(%rip), %rsi      # 0x9845
movq %r14, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x171c
jmp 0x3fb4
movq 0x80(%rsp), %rdi
movl 0x88(%rsp), %esi
callq 0x15ba
leaq 0x598c(%rip), %rsi      # 0x98c7
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x171c
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1990
cmpl $0x1, %eax
je 0x411a
cmpl $0x4, %eax
jne 0x40e5
leaq 0x596c(%rip), %rsi      # 0x98d8
jmp 0x4110
leaq 0x58e0(%rip), %rsi      # 0x9858
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x171c
movl 0x84(%rsp), %edx
leaq 0x58d2(%rip), %rsi      # 0x9864
movq %r14, %rdi
xorl %eax, %eax
callq 0x171c
movl 0x84(%rsp), %edx
leaq 0x58ca(%rip), %rsi      # 0x9874
movq %r14, %rdi
xorl %eax, %eax
callq 0x171c
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x404a
testl %eax, %eax
jne 0x422a
movl 0x4(%rbx), %ecx
movl 0x84(%rsp), %r8d
leaq 0x58a6(%rip), %rsi      # 0x987f
movq %r14, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x171c
testb %bpl, %bpl
je 0x422a
leaq 0x40(%rsp), %rdi
callq 0x7a9c
cmpl $0x7, %eax
je 0x422a
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1990
cmpl $0x1, %eax
je 0x41e3
cmpl $0x4, %eax
je 0x4175
movups 0x587d(%rip), %xmm0     # 0x98a3
leaq 0x94b3(%rip), %rax      # 0xd4e0
movups %xmm0, 0xe(%rax)
movups 0x585d(%rip), %xmm0     # 0x9895
movaps %xmm0, (%rax)
movl $0x1, %edi
callq 0x5b10
jmp 0x422a
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x15ba
leaq 0x560a(%rip), %rsi      # 0x9666
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x171c
movl 0x84(%rsp), %edx
leaq 0x583d(%rip), %rsi      # 0x98b3
movq %r14, %rdi
xorl %eax, %eax
callq 0x171c
testb %bpl, %bpl
je 0x420c
leaq 0x40(%rsp), %rdi
callq 0x7a9c
cmpl $0x7, %eax
je 0x420c
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1990
cmpl $0x1, %eax
je 0x41da
cmpl $0x4, %eax
je 0x41fb
movups 0x57e2(%rip), %xmm0     # 0x98a3
leaq 0x9418(%rip), %rax      # 0xd4e0
movups %xmm0, 0xe(%rax)
movups 0x57c2(%rip), %xmm0     # 0x9895
movaps %xmm0, (%rax)
movl $0x1, %edi
callq 0x5b10
jmp 0x420c
leaq 0x576c(%rip), %rsi      # 0x9858
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x171c
leaq 0x57ea(%rip), %rsi      # 0x98e9
movq %r14, %rdi
xorl %eax, %eax
callq 0x171c
leaq 0x57e8(%rip), %rsi      # 0x98f8
movq %r14, %rdi
xorl %eax, %eax
callq 0x171c
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x4181
testl %eax, %eax
jne 0x422a
movl 0x4(%rbx), %ecx
leaq 0x57cf(%rip), %rsi      # 0x9902
movq %r14, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x171c
testb %bpl, %bpl
je 0x422a
leaq 0x40(%rsp), %rdi
callq 0x7a9c
cmpl $0x7, %eax
je 0x422a
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1990
cmpl $0x1, %eax
je 0x41e3
cmpl $0x4, %eax
jne 0x422a
movl 0x4(%rbx), %ecx
leaq 0x55dc(%rip), %rsi      # 0x975b
jmp 0x41ed
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x15ba
leaq 0x54d3(%rip), %rsi      # 0x9666
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x171c
leaq 0x5771(%rip), %rsi      # 0x9917
movq %r14, %rdi
xorl %eax, %eax
callq 0x171c
testb %bpl, %bpl
je 0x420c
leaq 0x40(%rsp), %rdi
callq 0x7a9c
cmpl $0x7, %eax
je 0x420c
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1990
cmpl $0x4, %eax
je 0x41fb
cmpl $0x1, %eax
jne 0x420c
leaq 0x558c(%rip), %rsi      # 0x976d
jmp 0x4202
movl 0x4(%rbx), %ecx
leaq 0x555c(%rip), %rsi      # 0x9749
movq %r14, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x171c
jmp 0x422a
leaq 0x558c(%rip), %rsi      # 0x978e
movq %r14, %rdi
xorl %eax, %eax
callq 0x171c
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x15ba
leaq 0x53b7(%rip), %rsi      # 0x95d5
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x171c
movq 0x80(%rsp), %rdi
movl 0x88(%rsp), %esi
callq 0x156a
testb %bpl, %bpl
je 0x4274
leaq 0x10(%rbx), %r14
movq %r14, %rdi
callq 0x7ab4
movq %r14, %rdi
callq 0x7a9c
cmpl $0x7, %eax
jne 0x4274
movq %r14, %rdi
callq 0x7ab4
decl 0x48(%rbx)
movq %r14, %rdi
movl $0x4, %esi
callq 0x75ac
testb %bpl, %bpl
sete 0x50(%rbx)
addq $0xd8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq