// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
addl $-0x8, %eax
movl %eax, %ecx
movq %rcx, -0x100(%rbp)
subl $0x7, %eax
ja 0x4add
movq -0x100(%rbp), %rax
leaq 0xca30(%rip), %rcx      # 0x114d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x46, -0x14(%rbp)
jmp 0x4add
movl $0x47, -0x14(%rbp)
jmp 0x4add
movl $0x49, -0x14(%rbp)
jmp 0x4add
movl $0x48, -0x14(%rbp)
jmp 0x4add
movl $0x4b, -0x14(%rbp)
jmp 0x4add
movl $0x4a, -0x14(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x4920
movq -0x8(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0x38(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x63c0
movl $0x36, %edi
movl $0x1, %esi
leaq -0x38(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
movb $0x0, %al
callq 0x6460
movq -0x130(%rbp), %rdi
movq %rax, %rsi
callq 0x68f0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x4920
movq -0x8(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movl $0x5, %edx
callq 0x63c0
movl $0x37, %edi
movl $0x1, %esi
leaq -0x58(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
movb $0x0, %al
callq 0x6460
movq -0x128(%rbp), %rdi
movq %rax, %rsi
callq 0x68f0
movq -0x8(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq -0x78(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x63c0
leaq -0x98(%rbp), %rdi
xorl %esi, %esi
movl $0x5, %edx
callq 0x63c0
movl $0x35, %edi
movl $0x2, %esi
leaq -0x78(%rbp), %rcx
leaq -0x98(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rsp)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rsp)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rsp)
movq (%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x28(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x30(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
movb $0x0, %al
callq 0x6460
movq -0x120(%rbp), %rdi
movq %rax, %rsi
callq 0x68f0
movq -0x8(%rbp), %rax
movq %rax, -0x110(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x114(%rbp)
leaq -0xb8(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x63c0
movl -0x114(%rbp), %edi
movl $0x1, %esi
leaq -0xb8(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
movb $0x0, %al
callq 0x6460
movq -0x110(%rbp), %rdi
movq %rax, %rsi
callq 0x68f0
movq -0x8(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0xd8(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x63c0
leaq -0xf8(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x63c0
movl $0x50, %edi
movl $0x2, %esi
leaq -0xd8(%rbp), %rcx
leaq -0xf8(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rsp)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rsp)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rsp)
movq (%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x28(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x30(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
movb $0x0, %al
callq 0x6460
movq -0x108(%rbp), %rdi
movq %rax, %rsi
callq 0x68f0
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopw %cs:(%rax,%rax)