// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/arch/arm32/arm_core.c
// Function: subtilis_arm_add_rsub_imm
void subtilis_arm_add_rsub_imm(subtilis_arm_section_t *s,
			       subtilis_arm_ccode_type_t ccode, bool status,
			       subtilis_arm_reg_t dest, subtilis_arm_reg_t op1,
			       int32_t op2, subtilis_error_t *err)
{
	subtilis_arm_instr_t *instr;
	subtilis_arm_data_instr_t *datai;
	bool can_encode;
	uint32_t encoded;
	subtilis_arm_reg_t neg_dest;
	subtilis_arm_instr_type_t itype = SUBTILIS_ARM_INSTR_RSB;

	can_encode = subtilis_arm_encode_imm(op2, &encoded);
	if ((!can_encode) && (op2 < 0) &&
	    !(status && (ccode != SUBTILIS_ARM_CCODE_AL))) {
		can_encode = subtilis_arm_encode_imm(-op2, &encoded);
		if (can_encode) {
			neg_dest = subtilis_arm_acquire_new_reg(s);
			subtilis_arm_add_rsub_imm(s, ccode, false, neg_dest,
						  op1, 0, err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
			op1 = neg_dest;
			op2 = -op2;
			itype = SUBTILIS_ARM_INSTR_SUB;
		}
	}

	if (!can_encode) {
		(void)subtilis_add_data_imm_ldr_datai(s, itype, ccode, status,
						      dest, op1, op2, err);
		return;
	}

	instr = subtilis_arm_section_add_instr(s, itype, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	datai = &instr->operands.data;
	datai->status = status;
	datai->op2.type = SUBTILIS_ARM_OP2_I32;
	datai->ccode = ccode;
	datai->dest = dest;
	datai->op1 = op1;
	datai->op2.op.integer = encoded;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r9d, %r13d
movq %r8, %r14
movq %rcx, 0x10(%rsp)
movl %edx, %ebp
movl %esi, %ebx
movq %rdi, %r12
leaq 0xc(%rsp), %rsi
movl %r9d, %edi
callq 0x4f8d1
movl %eax, %r15d
testl %r13d, %r13d
setns %al
movl %ebx, 0x4(%rsp)
cmpl $0xe, %ebx
setne %cl
movl %ebp, 0x8(%rsp)
andb %bpl, %cl
orb %r15b, %al
orb %cl, %al
movl $0x3, %ebp
jne 0x50082
movl %r13d, %ebx
negl %ebx
leaq 0xc(%rsp), %rsi
movl %ebx, %edi
callq 0x4f8d1
movl %eax, %r15d
testb %al, %al
je 0x50082
movq (%r12), %r13
leaq 0x1(%r13), %rax
movq %rax, (%r12)
leaq -0x1(%r13), %rax
cmpq $0x3, %rax
jae 0x5010c
leaq 0x25b08(%rip), %rax     # 0x75b80
movq -0x8(%rax,%r13,8), %r13
jmp 0x50110
movl %r13d, %ebx
movq %r14, %r13
movq 0x50(%rsp), %r14
testb %r15b, %r15b
je 0x500a7
movq %r12, %rdi
movq %r14, %rsi
callq 0x4f5b7
cmpl $0x0, (%r14)
je 0x500cb
xorl %ecx, %ecx
jmp 0x500db
movzbl 0x8(%rsp), %ecx
movq %r12, %rdi
movl %ebp, %esi
movl 0x4(%rsp), %edx
movq 0x10(%rsp), %r8
movq %r13, %r9
pushq %r14
pushq %rbx
callq 0x4fc61
addq $0x28, %rsp
jmp 0x50140
movl $0x0, (%rax)
movq %rax, %rcx
addq $0x8, %rcx
movl %ebp, 0x8(%rax)
cmpl $0x0, (%r14)
jne 0x5013c
movl 0x8(%rsp), %eax
movb %al, 0xc(%rcx)
movl $0x1, 0x20(%rcx)
movl 0x4(%rsp), %eax
movl %eax, 0x8(%rcx)
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rcx)
movq %r13, 0x18(%rcx)
movl 0xc(%rsp), %eax
movl %eax, 0x28(%rcx)
jmp 0x5013c
addq $0xc, %r13
subq $0x8, %rsp
movq %r12, %rdi
movl 0xc(%rsp), %esi
xorl %edx, %edx
movq %r13, %rcx
movq %r14, %r8
xorl %r9d, %r9d
movq 0x58(%rsp), %r14
pushq %r14
callq 0x4ffec
addq $0x10, %rsp
cmpl $0x0, (%r14)
je 0x5014b
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x2, %ebp
jmp 0x5008d