// File: /workspace/github_c_makefile_star2_O2/Yamsman[P]scc/src/gen.c
// Function: gen_expr_cmp
void gen_expr_cmp(asm_f *f, ast_n *n) {
	int set_i = -1;
	switch (n->dat.expr.kind) {
		case EXPR_EQ:  set_i = INST_SETE;	break;
		case EXPR_NEQ: set_i = INST_SETNE;	break;
		case EXPR_GTH: set_i = INST_SETG;	break;
		case EXPR_LTH: set_i = INST_SETL;	break;
		case EXPR_GEQ: set_i = INST_SETGE;	break;
		case EXPR_LEQ: set_i = INST_SETLE;	break;
	}
	
	//Generate LHS into RAX and push the result
	gen_expr(f, n->dat.expr.left);
	asmf_add_inst(f, mk_inst(INST_PUSH, 1, mk_oprd(OPRD_REG, RAX)));

	//Generate RHS into RAX, pop LHS into register for comparison
	gen_expr(f, n->dat.expr.right);
	asmf_add_inst(f, mk_inst(INST_POP, 1, mk_oprd(OPRD_REG, RCX)));

	//Compare the two results and set EAX based on comparison type
	asmf_add_inst(f, mk_inst(INST_CMP, 2,
		mk_oprd(OPRD_REG, RAX),
		mk_oprd(OPRD_REG, RCX)
	));
	asmf_add_inst(f, mk_inst(set_i, 1, mk_oprd(OPRD_REG, AL)));
	asmf_add_inst(f, mk_inst(INST_MOVZX, 2,
		mk_oprd(OPRD_REG, RAX),
		mk_oprd(OPRD_REG, AL)	
	));

	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rsi, %r15
movq %rdi, %rbx
movl 0x8(%rsi), %eax
addl $-0x8, %eax
cmpl $0x7, %eax
ja 0x41c0
movl %eax, %eax
leaq 0x84c5(%rip), %rcx      # 0xc680
movl (%rcx,%rax,4), %ebp
jmp 0x41c3
pushq $-0x1
popq %rbp
movq 0x20(%r15), %rsi
movq %rbx, %rdi
callq 0x40b5
leaq 0x108(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x50d0
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
pushq $0x36
popq %rdi
pushq $0x1
popq %r14
movl %r14d, %esi
xorl %eax, %eax
callq 0x50ff
movq %rbx, %rdi
movq %rax, %rsi
callq 0x53ce
movq 0x28(%r15), %rsi
movq %rbx, %rdi
callq 0x40b5
leaq 0xe8(%rsp), %r12
pushq $0x5
popq %r15
movq %r12, %rdi
xorl %esi, %esi
movl %r15d, %edx
callq 0x50d0
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
pushq $0x37
popq %rdi
movl %r14d, %esi
xorl %eax, %eax
callq 0x50ff
movq %rbx, %rdi
movq %rax, %rsi
callq 0x53ce
leaq 0xc8(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x50d0
leaq 0xa8(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
movl %r15d, %edx
callq 0x50d0
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups %xmm1, 0x30(%rsp)
movups %xmm0, 0x20(%rsp)
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
pushq $0x35
popq %rdi
pushq $0x2
popq %r15
movl %r15d, %esi
xorl %eax, %eax
callq 0x50ff
movq %rbx, %rdi
movq %rax, %rsi
callq 0x53ce
leaq 0x88(%rsp), %r13
pushq $0x4
popq %r12
movq %r13, %rdi
xorl %esi, %esi
movl %r12d, %edx
callq 0x50d0
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl %ebp, %edi
movl %r14d, %esi
xorl %eax, %eax
callq 0x50ff
movq %rbx, %rdi
movq %rax, %rsi
callq 0x53ce
leaq 0x68(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x50d0
leaq 0x48(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
movl %r12d, %edx
callq 0x50d0
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups %xmm1, 0x30(%rsp)
movups %xmm0, 0x20(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
pushq $0x50
popq %rdi
movl %r15d, %esi
xorl %eax, %eax
callq 0x50ff
movq %rbx, %rdi
movq %rax, %rsi
callq 0x53ce
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq