// File: /workspace/github_c_makefile_star2_O2/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 0x761b
cmpl $0x4, %eax
je 0x3b44
movups 0x4cd9(%rip), %xmm0     # 0x8800
leaq 0x89b2(%rip), %rax      # 0xc4e0
movaps %xmm0, 0x10(%rax)
movups 0x4cb7(%rip), %xmm0     # 0x87f0
movaps %xmm0, (%rax)
pushq $0x1
popq %rdi
callq 0x56c5
incq (%r15)
leaq 0x80(%rsp), %rdi
pushq $0x1
popq %rdx
movq %r15, %rsi
xorl %ecx, %ecx
movq %r14, %r8
callq 0x3a29
movq (%r15), %rax
cmpb $0x5d, (%rax)
je 0x3b91
movups 0x4ca2(%rip), %xmm0     # 0x8810
leaq 0x896b(%rip), %rax      # 0xc4e0
movaps %xmm0, (%rax)
movabsq $0x275d2720676e69, %rcx # imm = 0x275D2720676E69
movq %rcx, 0xd(%rax)
pushq $0x1
popq %rdi
callq 0x56c5
movq (%r15), %rax
incq %rax
movq %rax, (%r15)
leaq 0x85e2(%rip), %rax      # 0xc180
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
pushq $0x1
popq %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0x312b
movl (%r15), %eax
cmpl $0x1, %eax
je 0x3c1f
testl %eax, %eax
jne 0x3f25
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1756
cmpl $0x1, %eax
je 0x3cb3
cmpl $0x4, %eax
jne 0x3c70
movl 0x84(%rsp), %ecx
leaq 0x4c17(%rip), %rsi      # 0x8825
movq %r14, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x14e8
jmp 0x3cb3
movq 0x80(%rsp), %rdi
movl 0x88(%rsp), %esi
callq 0x1393
leaq 0x4c6d(%rip), %rsi      # 0x88a7
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x14e8
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1756
cmpl $0x1, %eax
je 0x3e15
cmpl $0x4, %eax
jne 0x3de0
leaq 0x4c4d(%rip), %rsi      # 0x88b8
jmp 0x3e0b
leaq 0x4bc1(%rip), %rsi      # 0x8838
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x14e8
movl 0x84(%rsp), %edx
leaq 0x4bb3(%rip), %rsi      # 0x8844
movq %r14, %rdi
xorl %eax, %eax
callq 0x14e8
movl 0x84(%rsp), %edx
leaq 0x4bab(%rip), %rsi      # 0x8854
movq %r14, %rdi
xorl %eax, %eax
callq 0x14e8
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x3d47
testl %eax, %eax
jne 0x3f25
movl 0x4(%rbx), %ecx
movl 0x84(%rsp), %r8d
leaq 0x4b87(%rip), %rsi      # 0x885f
movq %r14, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x14e8
testb %bpl, %bpl
je 0x3f25
leaq 0x40(%rsp), %rdi
callq 0x7603
cmpl $0x7, %eax
je 0x3f25
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1756
cmpl $0x1, %eax
je 0x3ede
cmpl $0x4, %eax
je 0x3e70
movups 0x4b5e(%rip), %xmm0     # 0x8883
leaq 0x87b4(%rip), %rax      # 0xc4e0
movups %xmm0, 0xe(%rax)
movups 0x4b3e(%rip), %xmm0     # 0x8875
movaps %xmm0, (%rax)
pushq $0x1
popq %rdi
callq 0x56c5
jmp 0x3f25
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x1393
leaq 0x48ed(%rip), %rsi      # 0x8646
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x14e8
movl 0x84(%rsp), %edx
leaq 0x4b20(%rip), %rsi      # 0x8893
movq %r14, %rdi
xorl %eax, %eax
callq 0x14e8
testb %bpl, %bpl
je 0x3f07
leaq 0x40(%rsp), %rdi
callq 0x7603
cmpl $0x7, %eax
je 0x3f07
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1756
cmpl $0x1, %eax
je 0x3ed5
cmpl $0x4, %eax
je 0x3ef6
movups 0x4ac5(%rip), %xmm0     # 0x8883
leaq 0x871b(%rip), %rax      # 0xc4e0
movups %xmm0, 0xe(%rax)
movups 0x4aa5(%rip), %xmm0     # 0x8875
movaps %xmm0, (%rax)
pushq $0x1
popq %rdi
callq 0x56c5
jmp 0x3f07
leaq 0x4a51(%rip), %rsi      # 0x8838
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x14e8
leaq 0x4acf(%rip), %rsi      # 0x88c9
movq %r14, %rdi
xorl %eax, %eax
callq 0x14e8
leaq 0x4acd(%rip), %rsi      # 0x88d8
movq %r14, %rdi
xorl %eax, %eax
callq 0x14e8
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x3e7c
testl %eax, %eax
jne 0x3f25
movl 0x4(%rbx), %ecx
leaq 0x4ab4(%rip), %rsi      # 0x88e2
movq %r14, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x14e8
testb %bpl, %bpl
je 0x3f25
leaq 0x40(%rsp), %rdi
callq 0x7603
cmpl $0x7, %eax
je 0x3f25
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1756
cmpl $0x1, %eax
je 0x3ede
cmpl $0x4, %eax
jne 0x3f25
movl 0x4(%rbx), %ecx
leaq 0x48c1(%rip), %rsi      # 0x873b
jmp 0x3ee8
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x1393
leaq 0x47b8(%rip), %rsi      # 0x8646
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x14e8
leaq 0x4a56(%rip), %rsi      # 0x88f7
movq %r14, %rdi
xorl %eax, %eax
callq 0x14e8
testb %bpl, %bpl
je 0x3f07
leaq 0x40(%rsp), %rdi
callq 0x7603
cmpl $0x7, %eax
je 0x3f07
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x1756
cmpl $0x4, %eax
je 0x3ef6
cmpl $0x1, %eax
jne 0x3f07
leaq 0x4871(%rip), %rsi      # 0x874d
jmp 0x3efd
movl 0x4(%rbx), %ecx
leaq 0x4841(%rip), %rsi      # 0x8729
movq %r14, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x14e8
jmp 0x3f25
leaq 0x4871(%rip), %rsi      # 0x876e
movq %r14, %rdi
xorl %eax, %eax
callq 0x14e8
movq (%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x1393
leaq 0x469c(%rip), %rsi      # 0x85b5
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x14e8
movq 0x80(%rsp), %rdi
movl 0x88(%rsp), %esi
callq 0x1343
testb %bpl, %bpl
je 0x3f6d
leaq 0x10(%rbx), %r14
movq %r14, %rdi
callq 0x761b
movq %r14, %rdi
callq 0x7603
cmpl $0x7, %eax
jne 0x3f6d
movq %r14, %rdi
callq 0x761b
decl 0x48(%rbx)
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x7204
testb %bpl, %bpl
sete 0x50(%rbx)
addq $0xd8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq