// File: /workspace/github_c_makefile_star2_O0/Mithreindeir[P]ewcc/src/tac.c
// Function: unop_emit
struct ir_operand *unop_emit(struct generator *context, struct unop *u, int result)
{
	struct ir_stmt *stmt = ir_stmt_init();
	enum operator op = u->op;
	stmt->type = map_stmt(op);
	if (op==o_preinc || op == o_predec || op == o_postinc || op == o_postdec ) {
		stmt->type = (op==o_preinc||op==o_postinc) ? stmt_add : stmt_sub;
		stmt->arg1 = 	generate_from_node(u->term, context, VALUE);
		stmt->arg2 = 	from_cnum(1);
		stmt->result = 	from_reg(context->reg_cnt++);
		emit(context, stmt);
		struct ir_operand *lreg = copy(stmt->result), *preg = stmt->arg1;
		stmt = ir_stmt_init();
		stmt->type = stmt_store;
		stmt->arg1 = generate_from_node(u->term, context, ADDRESS);
		stmt->arg2 = lreg;
		emit(context, stmt);
		/*Post inc/dec returns the old value in a register, then increments
		 * contents at the address*/
		if (op==o_postinc || op==o_postdec)
			return result != IGNORE ? copy(preg) : NULL;
		else /*Pre inc/dec increments it first then returns the final register*/
			return result != IGNORE ? copy(lreg) : NULL;
	} else if (stmt->type == stmt_load &&  TYPE(u->term)->type == type_array) {
		/*Arrays are not pointers to pointers to arrays, just pointers to arrays
		 * So remove the first dereference if storing in an array*/
		if (result==ADDRESS) stmt->type = stmt_move;
		stmt->arg1 = generate_from_node(u->term, context, ADDRESS);
	} else if (stmt->type == stmt_load && result == ADDRESS) {
		//Do not dereference, if an address is needed as a result
		free(stmt);
		return generate_from_node(u->term, context, VALUE);
	} else if (stmt->type == stmt_load) {
		/*If there is a deref/ref involved, let the parent decide*/
		stmt->arg1 = generate_from_node(u->term, context, ADDRESS);
	} else if (stmt->type == stmt_addr) {
		stmt->arg1 = generate_from_node(u->term, context, ADDRESS);
	} else {
		/*Most instructions use the value of the operands*/
		stmt->arg1 = generate_from_node(u->term, context, VALUE);
	}
	stmt->result = 	from_reg(context->reg_cnt++);
	emit(context, stmt);
	return result != IGNORE ? copy(stmt->result) : NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
callq 0x70d0
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %edi
callq 0x5810
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x15, -0x2c(%rbp)
je 0x6592
cmpl $0x17, -0x2c(%rbp)
je 0x6592
cmpl $0x14, -0x2c(%rbp)
je 0x6592
cmpl $0x16, -0x2c(%rbp)
jne 0x66e8
movb $0x1, %al
cmpl $0x15, -0x2c(%rbp)
movb %al, -0x41(%rbp)
je 0x65a7
cmpl $0x14, -0x2c(%rbp)
sete %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %dl
movl $0xb, %ecx
movl $0xa, %eax
testb $0x1, %dl
cmovnel %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movl $0x2, %edx
callq 0x5920
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x1, %edi
callq 0x64f0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movl (%rax), %edi
movl %edi, %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
callq 0x6ee0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x6c40
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x6f30
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
callq 0x70d0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl $0x12, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movl $0x1, %edx
callq 0x5920
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x6c40
cmpl $0x14, -0x2c(%rbp)
je 0x6694
cmpl $0x16, -0x2c(%rbp)
jne 0x66be
cmpl $0x3, -0x1c(%rbp)
je 0x66a9
movq -0x40(%rbp), %rdi
callq 0x6f30
movq %rax, -0x50(%rbp)
jmp 0x66b1
xorl %eax, %eax
movq %rax, -0x50(%rbp)
jmp 0x66b1
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6841
cmpl $0x3, -0x1c(%rbp)
je 0x66d3
movq -0x38(%rbp), %rdi
callq 0x6f30
movq %rax, -0x58(%rbp)
jmp 0x66db
xorl %eax, %eax
movq %rax, -0x58(%rbp)
jmp 0x66db
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6841
movq -0x28(%rbp), %rax
cmpl $0x11, (%rax)
jne 0x673a
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
cmpl $0x2, 0x18(%rax)
jne 0x673a
cmpl $0x1, -0x1c(%rbp)
jne 0x6715
movq -0x28(%rbp), %rax
movl $0x6, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movl $0x1, %edx
callq 0x5920
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x67ec
movq -0x28(%rbp), %rax
cmpl $0x11, (%rax)
jne 0x6770
cmpl $0x1, -0x1c(%rbp)
jne 0x6770
movq -0x28(%rbp), %rdi
callq 0x2030
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movl $0x2, %edx
callq 0x5920
movq %rax, -0x8(%rbp)
jmp 0x6841
movq -0x28(%rbp), %rax
cmpl $0x11, (%rax)
jne 0x679b
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movl $0x1, %edx
callq 0x5920
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x67e8
movq -0x28(%rbp), %rax
cmpl $0x13, (%rax)
jne 0x67c6
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movl $0x1, %edx
callq 0x5920
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x67e6
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movl $0x2, %edx
callq 0x5920
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x67e8
jmp 0x67ea
jmp 0x67ec
jmp 0x67ee
movq -0x10(%rbp), %rax
movl (%rax), %edi
movl %edi, %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
callq 0x6ee0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x6c40
cmpl $0x3, -0x1c(%rbp)
je 0x6831
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x6f30
movq %rax, -0x60(%rbp)
jmp 0x6839
xorl %eax, %eax
movq %rax, -0x60(%rbp)
jmp 0x6839
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)