// File: /workspace/github_c_makefile_star2_O1/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 0x7a79
cmpl $0x4, %eax
je 0x3e25
movups 0x5a1a(%rip), %xmm0     # 0x9820
leaq 0x96d3(%rip), %rax      # 0xd4e0
movaps %xmm0, 0x10(%rax)
movups 0x59f8(%rip), %xmm0     # 0x9810
movaps %xmm0, (%rax)
movl $0x1, %edi
callq 0x5ae0
incq (%r15)
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
movq %r14, %r8
callq 0x3d08
movq (%r15), %rax
cmpb $0x5d, (%rax)
je 0x3e73
movups 0x59df(%rip), %xmm0     # 0x9830
leaq 0x9688(%rip), %rax      # 0xd4e0
movaps %xmm0, (%rax)
movabsq $0x275d2720676e69, %rcx # imm = 0x275D2720676E69
movq %rcx, 0xd(%rax)
movl $0x1, %edi
callq 0x5ae0
incq (%r15)
leaq 0x9303(%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 0x33e8
movl (%r15), %eax
cmpl $0x1, %eax
je 0x3f00
testl %eax, %eax
jne 0x420a
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1984
cmpl $0x1, %eax
je 0x3f94
cmpl $0x4, %eax
jne 0x3f51
movl 0x84(%rsp), %ecx
leaq 0x5956(%rip), %rsi      # 0x9845
movq %r14, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x1710
jmp 0x3f94
movq 0x80(%rsp), %rdi
movl 0x88(%rsp), %esi
callq 0x15ba
leaq 0x59ac(%rip), %rsi      # 0x98c7
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1984
cmpl $0x1, %eax
je 0x40fa
cmpl $0x4, %eax
jne 0x40c5
leaq 0x598c(%rip), %rsi      # 0x98d8
jmp 0x40f0
leaq 0x5900(%rip), %rsi      # 0x9858
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
movl 0x84(%rsp), %edx
leaq 0x58f2(%rip), %rsi      # 0x9864
movq %r14, %rdi
xorl %eax, %eax
callq 0x1710
movl 0x84(%rsp), %edx
leaq 0x58ea(%rip), %rsi      # 0x9874
movq %r14, %rdi
xorl %eax, %eax
callq 0x1710
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x402a
testl %eax, %eax
jne 0x420a
movl 0x4(%rbx), %ecx
movl 0x84(%rsp), %r8d
leaq 0x58c6(%rip), %rsi      # 0x987f
movq %r14, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x1710
testb %bpl, %bpl
je 0x420a
leaq 0x40(%rsp), %rdi
callq 0x7a61
cmpl $0x7, %eax
je 0x420a
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1984
cmpl $0x1, %eax
je 0x41c3
cmpl $0x4, %eax
je 0x4155
movups 0x589d(%rip), %xmm0     # 0x98a3
leaq 0x94d3(%rip), %rax      # 0xd4e0
movups %xmm0, 0xe(%rax)
movups 0x587d(%rip), %xmm0     # 0x9895
movaps %xmm0, (%rax)
movl $0x1, %edi
callq 0x5ae0
jmp 0x420a
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x15ba
leaq 0x562a(%rip), %rsi      # 0x9666
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
movl 0x84(%rsp), %edx
leaq 0x585d(%rip), %rsi      # 0x98b3
movq %r14, %rdi
xorl %eax, %eax
callq 0x1710
testb %bpl, %bpl
je 0x41ec
leaq 0x40(%rsp), %rdi
callq 0x7a61
cmpl $0x7, %eax
je 0x41ec
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1984
cmpl $0x1, %eax
je 0x41ba
cmpl $0x4, %eax
je 0x41db
movups 0x5802(%rip), %xmm0     # 0x98a3
leaq 0x9438(%rip), %rax      # 0xd4e0
movups %xmm0, 0xe(%rax)
movups 0x57e2(%rip), %xmm0     # 0x9895
movaps %xmm0, (%rax)
movl $0x1, %edi
callq 0x5ae0
jmp 0x41ec
leaq 0x578c(%rip), %rsi      # 0x9858
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
leaq 0x580a(%rip), %rsi      # 0x98e9
movq %r14, %rdi
xorl %eax, %eax
callq 0x1710
leaq 0x5808(%rip), %rsi      # 0x98f8
movq %r14, %rdi
xorl %eax, %eax
callq 0x1710
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x4161
testl %eax, %eax
jne 0x420a
movl 0x4(%rbx), %ecx
leaq 0x57ef(%rip), %rsi      # 0x9902
movq %r14, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x1710
testb %bpl, %bpl
je 0x420a
leaq 0x40(%rsp), %rdi
callq 0x7a61
cmpl $0x7, %eax
je 0x420a
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1984
cmpl $0x1, %eax
je 0x41c3
cmpl $0x4, %eax
jne 0x420a
movl 0x4(%rbx), %ecx
leaq 0x55fc(%rip), %rsi      # 0x975b
jmp 0x41cd
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x15ba
leaq 0x54f3(%rip), %rsi      # 0x9666
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
leaq 0x5791(%rip), %rsi      # 0x9917
movq %r14, %rdi
xorl %eax, %eax
callq 0x1710
testb %bpl, %bpl
je 0x41ec
leaq 0x40(%rsp), %rdi
callq 0x7a61
cmpl $0x7, %eax
je 0x41ec
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1984
cmpl $0x4, %eax
je 0x41db
cmpl $0x1, %eax
jne 0x41ec
leaq 0x55ac(%rip), %rsi      # 0x976d
jmp 0x41e2
movl 0x4(%rbx), %ecx
leaq 0x557c(%rip), %rsi      # 0x9749
movq %r14, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x1710
jmp 0x420a
leaq 0x55ac(%rip), %rsi      # 0x978e
movq %r14, %rdi
xorl %eax, %eax
callq 0x1710
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x15ba
leaq 0x53d7(%rip), %rsi      # 0x95d5
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1710
movq 0x80(%rsp), %rdi
movl 0x88(%rsp), %esi
callq 0x156a
testb %bpl, %bpl
je 0x4254
leaq 0x10(%rbx), %r14
movq %r14, %rdi
callq 0x7a79
movq %r14, %rdi
callq 0x7a61
cmpl $0x7, %eax
jne 0x4254
movq %r14, %rdi
callq 0x7a79
decl 0x48(%rbx)
movq %r14, %rdi
movl $0x4, %esi
callq 0x7568
testb %bpl, %bpl
sete 0x50(%rbx)
addq $0xd8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq