// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/arch/arm32/arm_core.c
// Function: subtilis_arm_add_addsub_imm
void subtilis_arm_add_addsub_imm(subtilis_arm_section_t *s,
				 subtilis_arm_instr_type_t itype,
				 subtilis_arm_instr_type_t alt_type,
				 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;
	subtilis_arm_data_instr_t *datai2;
	bool can_encode;
	uint32_t encoded;
	uint32_t encoded2 = 0;

	can_encode = subtilis_arm_encode_imm(op2, &encoded);
	/* TODO why does it matter if the op2 is less than 0? */
	if ((!can_encode) && (op2 < 0)) {
		can_encode = subtilis_arm_encode_imm(-op2, &encoded);
		if (can_encode) {
			op2 = -op2;
			itype = alt_type;
		}
	}

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

		can_encode =
		    subtilis_arm_encode_lvl2_imm(op2, &encoded, &encoded2);

		if ((!can_encode) && (op2 < 0)) {
			can_encode = subtilis_arm_encode_lvl2_imm(
			    -op2, &encoded, &encoded2);
			if (can_encode) {
				op2 = -op2;
				itype = alt_type;
			}
		}
	}

	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 = encoded2 == 0 ? dest : subtilis_arm_acquire_new_reg(s);
	datai->op1 = op1;
	datai->op2.op.integer = encoded;

	if (encoded2 == 0)
		return;

	instr = subtilis_arm_section_dup_instr(s, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	datai2 = &instr->operands.data;
	datai2->op1 = datai->dest;
	datai2->op2.op.integer = encoded2;
	datai2->dest = dest;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r13
movl %r8d, 0x8(%rsp)
movl %ecx, %ebp
movl %edx, %r14d
movl %esi, %ebx
movq %rdi, %r12
movl 0x58(%rsp), %r15d
movl $0x0, 0xc(%rsp)
leaq 0x4(%rsp), %rsi
movl %r15d, %edi
callq 0x4f87d
testl %r15d, %r15d
setns %cl
orb %al, %cl
je 0x4fd8c
testb %al, %al
je 0x4fdd5
movl %ebx, %r14d
jmp 0x4fd9f
movl %r15d, %edi
negl %edi
leaq 0x4(%rsp), %rsi
callq 0x4f87d
testb %al, %al
je 0x4fdd5
movq %r12, %rdi
movq 0x60(%rsp), %r15
movq %r15, %rsi
callq 0x4f560
cmpl $0x0, (%r15)
jne 0x4fdcc
movq %rax, %rbx
movl $0x0, (%rax)
movl %r14d, 0x8(%rax)
cmpl $0x0, (%r15)
je 0x4fe75
addq $0x18, %rsp
jmp 0x4fe6a
cmpl $0xe, %ebp
sete %al
movl 0x8(%rsp), %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0x4fdf4
movq %r12, %rdi
movl %ebx, %esi
movl %ebp, %edx
movl $0x1, %ecx
jmp 0x4fe53
movq %r13, 0x10(%rsp)
testl %r15d, %r15d
setns %r13b
leaq 0x4(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movl %r15d, %edi
callq 0x4f8f4
orb %al, %r13b
je 0x4fe26
testb %al, %al
movq 0x10(%rsp), %r13
jne 0x4fd87
jmp 0x4fe47
movl %r15d, %edi
negl %edi
leaq 0x4(%rsp), %rsi
leaq 0xc(%rsp), %rdx
callq 0x4f8f4
testb %al, %al
movq 0x10(%rsp), %r13
jne 0x4fd9f
movzbl 0x8(%rsp), %ecx
movq %r12, %rdi
movl %ebx, %esi
movl %ebp, %edx
movq %r13, %r8
movq 0x50(%rsp), %r9
pushq 0x60(%rsp)
pushq %r15
callq 0x4fbd3
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x8(%rsp), %eax
movb %al, 0x14(%rbx)
movl $0x1, 0x28(%rbx)
movl %ebp, 0x10(%rbx)
movl 0xc(%rsp), %ebp
testl %ebp, %ebp
je 0x4feb2
movq (%r12), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%r12)
leaq -0x1(%rax), %rcx
cmpq $0x3, %rcx
jae 0x4fecb
leaq 0x25d15(%rip), %rcx     # 0x75bc0
movq -0x8(%rcx,%rax,8), %rax
jmp 0x4fecf
movq %r13, 0x18(%rbx)
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rbx)
movl 0x4(%rsp), %eax
movl %eax, 0x30(%rbx)
jmp 0x4fdcc
addq $0xc, %rax
movq %rax, 0x18(%rbx)
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rbx)
movl 0x4(%rsp), %eax
movl %eax, 0x30(%rbx)
movq %r12, %rdi
movq %r15, %rsi
callq 0x4f74c
cmpl $0x0, (%r15)
jne 0x4fdcc
movq 0x18(%rbx), %rcx
movq %rcx, 0x18(%rax)
movl %ebp, 0x28(%rax)
movq %r13, 0x10(%rax)
jmp 0x4fdcc