// File: /workspace/github_c_makefile_star2_O1/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 %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rsi, %r14
movq %rdi, %rbx
movl 0x8(%rsi), %eax
addl $-0x8, %eax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x7, %eax
ja 0x427a
movl %eax, %eax
leaq 0x9409(%rip), %rcx      # 0xd680
movl (%rcx,%rax,4), %ebp
movq 0x20(%r14), %rsi
movq %rbx, %rdi
callq 0x4173
leaq 0x108(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5220
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl $0x36, %edi
movl $0x1, %esi
xorl %eax, %eax
callq 0x5255
movq %rbx, %rdi
movq %rax, %rsi
callq 0x5543
movq 0x28(%r14), %rsi
movq %rbx, %rdi
callq 0x4173
leaq 0xe8(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
movl $0x5, %edx
callq 0x5220
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl $0x37, %edi
movl $0x1, %esi
xorl %eax, %eax
callq 0x5255
movq %rbx, %rdi
movq %rax, %rsi
callq 0x5543
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5220
leaq 0xa8(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
movl $0x5, %edx
callq 0x5220
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x30(%rsp)
movups %xmm0, 0x20(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl $0x35, %edi
movl $0x2, %esi
xorl %eax, %eax
callq 0x5255
movq %rbx, %rdi
movq %rax, %rsi
callq 0x5543
leaq 0x88(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x5220
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl %ebp, %edi
movl $0x1, %esi
xorl %eax, %eax
callq 0x5255
movq %rbx, %rdi
movq %rax, %rsi
callq 0x5543
leaq 0x68(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5220
leaq 0x48(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x5220
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x30(%rsp)
movups %xmm0, 0x20(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl $0x50, %edi
movl $0x2, %esi
xorl %eax, %eax
callq 0x5255
movq %rbx, %rdi
movq %rax, %rsi
callq 0x5543
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r14
popq %r15
popq %rbp
retq