// File: /workspace/github_c_makefile_star2_O0/Encryptr[P]O-plus-plus/opp/ir/ir.c
// Function: oppir_write_reg
static void oppir_write_reg(struct OppIr* ir, enum Regs reg_type, struct OppIr_Const* imm)
{
	bool small = imm->val.imm_i32 > -128;

	if (small)
		imm->val.type = IMM_I8;
	else
		imm->val.type = IMM_I32;

	oppir_check_realloc(ir, 8);
	switch (imm->loc_type)
	{
		case IMM_F32:
		case IMM_F64:
			if (imm->loc_type == IMM_F32)
				IR_EMIT(0xf3);
			else
				IR_EMIT(0xf2);
			IR_EMIT(0x0f);
			IR_EMIT(0x10);
			reg_type -= 3;
			break;

		case IMM_U8:
		case IMM_U16:
		case IMM_I8:
		case IMM_I16:
		case IMM_I32:
			IR_EMIT(0x48);
			if (imm->loc_type != IMM_I32)
				IR_EMIT(0x0f);
			else
				IR_EMIT(0x63);

			switch (imm->loc_type) {
					break;
				case IMM_I8: 
					IR_EMIT(0xbe); 
					break;
				case IMM_U8:
					IR_EMIT(0xb7);
					break;
				case IMM_I16:
					IR_EMIT(0xbf);
					break;
				case IMM_U16:
					IR_EMIT(0xb7);
					break;
			}
			break;

		case IMM_U64:
		case IMM_I64:
			IR_EMIT(0x48);
			IR_EMIT(0x8b);
			break;

		case IMM_U32:
			IR_EMIT(0x8b);
			break;

		default: break;
	}
	if (small) 
		IR_EMIT(0x45 + (reg_type*8));
	else 
		IR_EMIT(0x85 + (reg_type*8));
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movl %esi, 0x2c(%rsp)
movq %rdx, 0x20(%rsp)
movq 0x20(%rsp), %rax
cmpl $-0x80, 0x8(%rax)
setg %al
andb $0x1, %al
movb %al, 0x1f(%rsp)
testb $0x1, 0x1f(%rsp)
je 0xbc88
movq 0x20(%rsp), %rax
movl $0x4, (%rax)
jmp 0xbc93
movq 0x20(%rsp), %rax
movl $0x8, (%rax)
movq 0x30(%rsp), %rdi
movl $0x8, %esi
callq 0x9750
movq 0x20(%rsp), %rax
movl 0x10(%rax), %eax
addl $-0x3, %eax
movl %eax, %ecx
movq %rcx, 0x10(%rsp)
subl $0x9, %eax
ja 0xbef8
movq 0x10(%rsp), %rax
leaq 0x86b7(%rip), %rcx      # 0x14380
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x20(%rsp), %rax
cmpl $0xb, 0x10(%rax)
jne 0xbcff
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
movb $-0xd, (%rax,%rcx)
jmp 0xbd1f
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
movb $-0xe, (%rax,%rcx)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
movb $0xf, (%rax,%rcx)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
movb $0x10, (%rax,%rcx)
movl 0x2c(%rsp), %eax
subl $0x3, %eax
movl %eax, 0x2c(%rsp)
jmp 0xbefa
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
movb $0x48, (%rax,%rcx)
movq 0x20(%rsp), %rax
cmpl $0x8, 0x10(%rax)
je 0xbdbc
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
movb $0xf, (%rax,%rcx)
jmp 0xbddc
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
movb $0x63, (%rax,%rcx)
movq 0x20(%rsp), %rax
movl 0x10(%rax), %eax
addl $-0x3, %eax
movl %eax, %ecx
movq %rcx, 0x8(%rsp)
subl $0x3, %eax
ja 0xbe92
movq 0x8(%rsp), %rax
leaq 0x85a5(%rip), %rcx      # 0x143a8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
movb $-0x42, (%rax,%rcx)
jmp 0xbe92
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
movb $-0x49, (%rax,%rcx)
jmp 0xbe92
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
movb $-0x41, (%rax,%rcx)
jmp 0xbe92
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
movb $-0x49, (%rax,%rcx)
jmp 0xbefa
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
movb $0x48, (%rax,%rcx)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
movb $-0x75, (%rax,%rcx)
jmp 0xbefa
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
movb $-0x75, (%rax,%rcx)
jmp 0xbefa
jmp 0xbefa
testb $0x1, 0x1f(%rsp)
je 0xbf2e
movl 0x2c(%rsp), %eax
shll $0x3, %eax
addl $0x45, %eax
movb %al, %dl
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rsi
movq 0x8(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x8(%rsi)
movb %dl, (%rax,%rcx)
jmp 0xbf5b
movl 0x2c(%rsp), %eax
shll $0x3, %eax
addl $0x85, %eax
movb %al, %dl
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rsi
movq 0x8(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x8(%rsi)
movb %dl, (%rax,%rcx)
addq $0x38, %rsp
retq