// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x68(%rdi), %r13
movl 0x70(%rdi), %edx
movl 0x74(%rdi), %ebp
movl 0x78(%rdi), %r8d
movl 0x7c(%rdi), %r9d
movq 0x80(%rdi), %r15
movl 0x88(%rdi), %esi
movl 0x10(%r14), %edi
leal -0x9(%rdi), %ecx
cmpl $0x6, %ecx
jae 0x4a04
movl %esi, 0xc(%rsp)
movl %r9d, 0x28(%rsp)
movl %r8d, 0x14(%rsp)
movl %ebp, 0x20(%rsp)
movl %edx, 0x10(%rsp)
movq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0x3c28
movq %rax, %rbp
movq %rdx, %r12
movq 0x18(%r14), %rsi
movq %rbx, %rdi
callq 0x3c28
movq %r12, 0x30(%rsp)
orq %r12, %rdx
btq $0x20, %rdx
jb 0x4c25
movl 0x8(%rbp), %eax
addl $-0x5, %eax
cmpl $0x1, %eax
jbe 0x4c44
movq %rbp, %r12
movq %rbx, %rdi
callq 0x385b
movq 0x48(%rbx), %rax
movq 0x58(%rbx), %rcx
leaq (%rax,%rax,4), %rax
movl $0x7, (%rcx,%rax,8)
movb $0x0, 0x8(%rcx,%rax,8)
incq 0x48(%rbx)
movq %rbx, %rdi
callq 0x385b
movq 0x48(%rbx), %rcx
movq 0x58(%rbx), %rax
leaq (%rcx,%rcx,4), %rcx
movl $0x8, (%rax,%rcx,8)
movl 0x10(%r14), %edx
cmpb $0x1, 0x80(%rbx)
jne 0x49c8
leaq 0x76db(%rip), %rsi      # 0xc0a0
movl (%rsi,%rdx,4), %edx
movl 0xc(%rsp), %esi
movl %edx, 0x8(%rax,%rcx,8)
movl 0x84(%rbx), %eax
movq 0x48(%rbx), %rcx
movq 0x58(%rbx), %rdx
leaq (%rcx,%rcx,4), %rcx
movl %eax, 0xc(%rdx,%rcx,8)
incq 0x48(%rbx)
movl 0x10(%rsp), %edx
movl 0x20(%rsp), %ebp
movl 0x14(%rsp), %r8d
movl 0x28(%rsp), %r9d
movq %r12, %rax
jmp 0x4bf2
leaq 0x70(%rbx), %rcx
leaq 0x74(%rbx), %r10
cmpl $0x7, %edi
je 0x4ad8
movq $0x0, 0x30(%rsp)
movl $0x0, %eax
cmpl $0x8, %edi
jne 0x4bf2
movq %r10, 0x38(%rsp)
movq %rcx, 0x18(%rsp)
movl %r9d, %r12d
movl %r8d, 0x14(%rsp)
movl %esi, 0xc(%rsp)
movq %r15, 0x20(%rsp)
movl %edx, 0x10(%rsp)
movq %r13, 0x28(%rsp)
movl $0x8, 0x7c(%rbx)
movq 0x20(%r14), %rax
cmpl $0x7, 0x10(%rax)
jne 0x4a6d
movl 0x24(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x24(%rbx)
movl %eax, 0x70(%rbx)
movb $0x1, 0x80(%rbx)
movl %ebp, 0x84(%rbx)
movl $0x0, 0x88(%rbx)
movq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0x48d6
movq %rax, 0x40(%rsp)
movq %rdx, %r15
movq 0x20(%r14), %rax
cmpl $0x7, 0x10(%rax)
jne 0x4b77
movq %rbx, %rdi
callq 0x385b
movq 0x48(%rbx), %rax
movq 0x58(%rbx), %rcx
leaq (%rax,%rax,4), %rax
movl $0xa, (%rcx,%rax,8)
movl 0x70(%rbx), %edx
movl %edx, 0x10(%rcx,%rax,8)
incq 0x48(%rbx)
movl 0x10(%rsp), %eax
movl %eax, 0x70(%rbx)
jmp 0x4b77
movq %r10, 0x38(%rsp)
movq %rcx, 0x18(%rsp)
movl %r9d, %r12d
movl %r8d, 0x14(%rsp)
movl %esi, 0xc(%rsp)
movq %r15, 0x20(%rsp)
movq %r13, 0x28(%rsp)
movl $0x7, 0x7c(%rbx)
movq 0x20(%r14), %rax
cmpl $0x8, 0x10(%rax)
jne 0x4b15
movl 0x24(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x24(%rbx)
movl %eax, 0x74(%rbx)
movb $0x0, 0x80(%rbx)
movl %edx, 0x10(%rsp)
movl %edx, 0x84(%rbx)
movl $0x0, 0x88(%rbx)
movq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0x48d6
movq %rax, 0x40(%rsp)
movq %rdx, %r15
movq 0x20(%r14), %rax
cmpl $0x8, 0x10(%rax)
jne 0x4b77
movq %rbx, %rdi
callq 0x385b
movq 0x48(%rbx), %rax
movq 0x58(%rbx), %rcx
leaq (%rax,%rax,4), %rax
movl $0xa, (%rcx,%rax,8)
movl 0x74(%rbx), %edx
movl %edx, 0x10(%rcx,%rax,8)
incq 0x48(%rbx)
movl %ebp, 0x74(%rbx)
movl %r12d, %esi
movl %r12d, %eax
xorl $0x7, %eax
movl %eax, %ecx
movl 0xc(%rsp), %edx
orl %edx, %ecx
movq %r15, 0x30(%rsp)
je 0x4b98
movl %edx, %ecx
xorl $0x1, %ecx
orl %ecx, %eax
jne 0x4ba6
movb $0x0, 0x80(%rbx)
movq 0x18(%rsp), %rax
jmp 0x4bb2
movb $0x1, 0x80(%rbx)
movq 0x38(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x84(%rbx)
movl $0x1, 0x88(%rbx)
movl %esi, 0x7c(%rbx)
movq 0x18(%r14), %rsi
movq %rbx, %rdi
callq 0x48d6
movl %r12d, %r9d
movq 0x28(%rsp), %r13
movl 0x10(%rsp), %edx
movq 0x20(%rsp), %r15
movl 0xc(%rsp), %esi
movq 0x40(%rsp), %rax
movl 0x14(%rsp), %r8d
movq %r13, 0x68(%rbx)
movl %edx, 0x70(%rbx)
movl %ebp, 0x74(%rbx)
movl %r8d, 0x78(%rbx)
movl %r9d, 0x7c(%rbx)
movq %r15, 0x80(%rbx)
movl %esi, 0x88(%rbx)
movq 0x30(%rsp), %rdx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x74b0(%rip), %rdi      # 0xc0dc
leaq 0x74cc(%rip), %rsi      # 0xc0ff
leaq 0x74e1(%rip), %rcx      # 0xc11b
movl $0x15b, %edx            # imm = 0x15B
callq 0x1100
leaq 0x751a(%rip), %rdi      # 0xc165
leaq 0x74ad(%rip), %rsi      # 0xc0ff
leaq 0x74c2(%rip), %rcx      # 0xc11b
movl $0x15c, %edx            # imm = 0x15C
callq 0x1100
nop