// File: /workspace/github_c_makefile_star2_O2/Encryptr[P]O-plus-plus/opp/compiler/compile_expr.c
// Function: opp_compile_logic_assign
static Opp_Obj opp_compile_logic_assign(struct Opp_Context* opp, struct Opp_Node* logic)
{
	Opp_Obj type_info = {0};
	struct Opp_Cond save = opp->cond_state;

	switch (logic->logic_expr.tok) 
	{
		case TEQEQ: case TNOTEQ: case TLT:
		case TGT: case TLE: case TGE: {
			Opp_Obj lhs = opp_compile_expr(opp, logic->logic_expr.left);
			Opp_Obj rhs = opp_compile_expr(opp, logic->logic_expr.right);

			// temp
			type_info = lhs;
			assert(lhs.unsign == 0 && rhs.unsign == 0);
			assert(lhs.decl->t_type != TYPE_FLOAT && lhs.decl->t_type != TYPE_DOUBLE);
			// check sign vs unsign
			// cast types 

			OPCODE_START();
				OPCODE_TYPE(OPCODE_CMP);
				opp->ir.opcodes[opp->ir.instr_idx].cmp.imm = 0; // add imm
			OPCODE_END();

			OPCODE_START();
				OPCODE_TYPE(OPCODE_JMP);
				if (opp->cond_state.use_op)
					opp->ir.opcodes[opp->ir.instr_idx].jmp.type = 
						jmp_opposites[logic->logic_expr.tok];
				else
					opp->ir.opcodes[opp->ir.instr_idx].jmp.type = 
						logic->logic_expr.tok;

				opp->ir.opcodes[opp->ir.instr_idx].jmp.loc = opp->cond_state.jloc;
			OPCODE_END();
			break;
		}

		case TOR: {
			opp->cond_state.curr_logic = TOR;

			if (logic->logic_expr.left->logic_expr.tok == TAND) {
				opp->cond_state.locs[1] = opp->info.label_loc++;
			}

			opp->cond_state.use_op = 0;
			opp->cond_state.jloc = opp->cond_state.locs[0];
			opp->cond_state.hs = 0;
			type_info = opp_compile_logic_assign(opp, logic->logic_expr.left);

			if (logic->logic_expr.left->logic_expr.tok == TAND) {
				OPCODE_START();
					OPCODE_TYPE(OPCODE_LABEL);
					opp->ir.opcodes[opp->ir.instr_idx].constant.val.imm_i32
						= opp->cond_state.locs[1];
				OPCODE_END();

				opp->cond_state.locs[1] = save.locs[1];
			}

			if (save.curr_logic == TOR && save.hs == 0) {
				opp->cond_state.use_op = 0;
				opp->cond_state.jloc = opp->cond_state.locs[0];
			}
			else if (save.hs == 1 && save.curr_logic == TOR) {
				opp->cond_state.use_op = 0;
				opp->cond_state.jloc = opp->cond_state.locs[0];
			}
			else {
				opp->cond_state.use_op = 1;
				opp->cond_state.jloc = opp->cond_state.locs[1];
			}
			opp->cond_state.hs = 1;
			opp->cond_state.curr_logic = save.curr_logic;
			opp_compile_logic_assign(opp, logic->logic_expr.right);
			break;
		}

		case TAND: {
			opp->cond_state.curr_logic = TAND;

			if (logic->logic_expr.left->logic_expr.tok == TOR) {
				opp->cond_state.locs[0] = opp->info.label_loc++;
			}

			opp->cond_state.use_op = 1;
			opp->cond_state.jloc = opp->cond_state.locs[1];
			opp->cond_state.hs = 0;
			type_info = opp_compile_logic_assign(opp, logic->logic_expr.left);

			if (logic->logic_expr.left->logic_expr.tok == TOR) {
				OPCODE_START();
					OPCODE_TYPE(OPCODE_LABEL);
					opp->ir.opcodes[opp->ir.instr_idx].constant.val.imm_i32 = opp->cond_state.locs[0];
				OPCODE_END();

				opp->cond_state.locs[0] = save.locs[0];
			}

			if (save.curr_logic == TOR && save.hs == 0) {
				opp->cond_state.use_op = 0;
				opp->cond_state.jloc = opp->cond_state.locs[0];
			}
			else if (save.hs == 1 && save.curr_logic == TOR) {
				opp->cond_state.use_op = 0;
				opp->cond_state.jloc = opp->cond_state.locs[0];
			}
			else {
				opp->cond_state.use_op = 1;
				opp->cond_state.jloc = opp->cond_state.locs[1];
			}
			opp->cond_state.hs = 1;
			opp->cond_state.curr_logic = save.curr_logic;
			opp_compile_logic_assign(opp, logic->logic_expr.right);
			break;
		}

		default: break;
	}

	opp->cond_state = save;
	return type_info;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x68(%rdi), %r13
movl 0x70(%rdi), %edx
movl 0x74(%rdi), %esi
movl 0x78(%rdi), %r15d
movl 0x7c(%rdi), %eax
movl %eax, 0xc(%rsp)
movq 0x80(%rdi), %r12
movl 0x88(%rdi), %eax
movl %eax, 0x8(%rsp)
movl 0x10(%r14), %eax
leal -0x9(%rax), %ecx
cmpl $0x6, %ecx
jae 0x4775
movq %r12, 0x10(%rsp)
movl %r15d, (%rsp)
movl %esi, %r15d
movl %edx, 0x4(%rsp)
movq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0x3abc
movq %rax, %r12
movq %rdx, %rbp
movq 0x18(%r14), %rsi
movq %rbx, %rdi
callq 0x3abc
movq %rbp, 0x20(%rsp)
orq %rbp, %rdx
btq $0x20, %rdx
jb 0x4978
movq %r12, 0x18(%rsp)
movl 0x8(%r12), %eax
addl $-0x5, %eax
cmpl $0x1, %eax
jbe 0x4997
addq $0x10, %r14
movq %rbx, %rdi
callq 0x3725
movq 0x58(%rbx), %rax
imulq $0x28, 0x48(%rbx), %rcx
movl $0x7, (%rax,%rcx)
movb $0x0, 0x8(%rax,%rcx)
incq 0x48(%rbx)
movq %rbx, %rdi
callq 0x3725
imulq $0x28, 0x48(%rbx), %rax
movq 0x58(%rbx), %rcx
movl $0x8, (%rcx,%rax)
cmpb $0x1, 0x80(%rbx)
jne 0x473d
movl (%r14), %edx
leaq 0x6967(%rip), %rsi      # 0xb0a0
leaq (%rsi,%rdx,4), %r14
movl %r15d, %esi
movl (%rsp), %r15d
movq 0x10(%rsp), %r12
movl (%r14), %edx
movl %edx, 0x8(%rcx,%rax)
movl 0x84(%rbx), %eax
movq 0x58(%rbx), %rcx
imulq $0x28, 0x48(%rbx), %rdx
movl %eax, 0xc(%rcx,%rdx)
incq 0x48(%rbx)
movl 0x4(%rsp), %edx
movq 0x20(%rsp), %rbp
jmp 0x4938
cmpl $0x7, %eax
je 0x4861
xorl %ebp, %ebp
movl $0x0, %ecx
cmpl $0x8, %eax
jne 0x493d
movq %r12, 0x10(%rsp)
movl %r15d, (%rsp)
movl %edx, %r15d
movl $0x8, 0x7c(%rbx)
movq 0x20(%r14), %rax
cmpl $0x7, 0x10(%rax)
jne 0x47b7
movl 0x24(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x24(%rbx)
movl %eax, 0x70(%rbx)
movb $0x1, 0x80(%rbx)
movl %esi, 0x4(%rsp)
movl %esi, 0x84(%rbx)
andl $0x0, 0x88(%rbx)
movq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0x4648
movq %rax, 0x18(%rsp)
movq %rdx, %rbp
movq 0x20(%r14), %rax
cmpl $0x7, 0x10(%rax)
jne 0x4814
movq %rbx, %rdi
callq 0x3725
imulq $0x28, 0x48(%rbx), %rax
movq 0x58(%rbx), %rcx
movl $0xa, (%rcx,%rax)
movl 0x70(%rbx), %edx
movl %edx, 0x10(%rcx,%rax)
incq 0x48(%rbx)
movl %r15d, 0x70(%rbx)
movl 0xc(%rsp), %esi
movl %esi, %eax
xorl $0x7, %eax
movl 0x8(%rsp), %ecx
andl $-0x2, %ecx
xorl %edx, %edx
orl %eax, %ecx
setne %dl
setne 0x80(%rbx)
movl 0x70(%rbx,%rdx,4), %eax
movl %eax, 0x84(%rbx)
movl $0x1, 0x88(%rbx)
movl %esi, 0x7c(%rbx)
movq 0x18(%r14), %rsi
movq %rbx, %rdi
callq 0x4648
movl %r15d, %edx
movl 0x4(%rsp), %esi
jmp 0x492f
movq %r12, 0x10(%rsp)
movl %r15d, (%rsp)
movl %esi, %r15d
movl $0x7, 0x7c(%rbx)
movq 0x20(%r14), %rax
cmpl $0x8, 0x10(%rax)
jne 0x488a
movl 0x24(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x24(%rbx)
movl %eax, 0x74(%rbx)
movb $0x0, 0x80(%rbx)
movl %edx, 0x4(%rsp)
movl %edx, 0x84(%rbx)
andl $0x0, 0x88(%rbx)
movq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0x4648
movq %rax, 0x18(%rsp)
movq %rdx, %rbp
movq 0x20(%r14), %rax
cmpl $0x8, 0x10(%rax)
jne 0x48e7
movq %rbx, %rdi
callq 0x3725
imulq $0x28, 0x48(%rbx), %rax
movq 0x58(%rbx), %rcx
movl $0xa, (%rcx,%rax)
movl 0x74(%rbx), %edx
movl %edx, 0x10(%rcx,%rax)
incq 0x48(%rbx)
movl %r15d, 0x74(%rbx)
movl 0xc(%rsp), %esi
movl %esi, %eax
xorl $0x7, %eax
movl 0x8(%rsp), %ecx
andl $-0x2, %ecx
xorl %edx, %edx
orl %eax, %ecx
setne %dl
setne 0x80(%rbx)
movl 0x70(%rbx,%rdx,4), %eax
movl %eax, 0x84(%rbx)
movl $0x1, 0x88(%rbx)
movl %esi, 0x7c(%rbx)
movq 0x18(%r14), %rsi
movq %rbx, %rdi
callq 0x4648
movl 0x4(%rsp), %edx
movl %r15d, %esi
movl (%rsp), %r15d
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %rcx
movq %r13, 0x68(%rbx)
movl %edx, 0x70(%rbx)
movl %esi, 0x74(%rbx)
movl %r15d, 0x78(%rbx)
movl 0xc(%rsp), %eax
movl %eax, 0x7c(%rbx)
movq %r12, 0x80(%rbx)
movl 0x8(%rsp), %eax
movl %eax, 0x88(%rbx)
movq %rcx, %rax
movq %rbp, %rdx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x675d(%rip), %rdi      # 0xb0dc
leaq 0x6779(%rip), %rsi      # 0xb0ff
leaq 0x678e(%rip), %rcx      # 0xb11b
movl $0x15b, %edx            # imm = 0x15B
callq 0x1100
leaq 0x67c7(%rip), %rdi      # 0xb165
leaq 0x675a(%rip), %rsi      # 0xb0ff
leaq 0x676f(%rip), %rcx      # 0xb11b
movl $0x15c, %edx            # imm = 0x15C
callq 0x1100
nop