// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/arch/arm32/arm_peephole.c
// Function: subtilis_arm_peephole
void subtilis_arm_peephole(subtilis_arm_section_t *arm_s, subtilis_error_t *err)
{
	subtilis_arm_op_t *op = NULL;
	size_t ptr;
	subtilis_arm_instr_t *instr;
	subtilis_arm_data_instr_t *data;
	subtilis_fpa_data_instr_t *fpa_data;
	subtilis_vfp_copy_instr_t *vfp_copy;
	subtilis_fpa_stran_instr_t *fpa_stran;
	subtilis_vfp_stran_instr_t *vfp_stran;

	ptr = arm_s->first_op;
	while (ptr != SIZE_MAX) {
		op = &arm_s->op_pool->ops[ptr];

		if (op->type != SUBTILIS_ARM_OP_INSTR) {
			ptr = op->next;
			continue;
		}

		instr = &op->op.instr;
		switch (instr->type) {
		case SUBTILIS_ARM_INSTR_MOV:
			data = &instr->operands.data;
			if ((data->op2.type == SUBTILIS_ARM_OP2_REG) &&
			    (data->op2.op.reg == data->dest) &&
			    (data->dest != 15)) {
				ptr = prv_remove_op(arm_s, ptr, op);
				continue;
			}
			break;
		case SUBTILIS_FPA_INSTR_MVF:
			fpa_data = &instr->operands.fpa_data;
			if (!fpa_data->immediate &&
			    fpa_data->op2.reg == fpa_data->dest) {
				ptr = prv_remove_op(arm_s, ptr, op);
				continue;
			}
			break;
		case SUBTILIS_VFP_INSTR_FCPYD:
			vfp_copy = &instr->operands.vfp_copy;
			if (vfp_copy->src == vfp_copy->dest) {
				ptr = prv_remove_op(arm_s, ptr, op);
				continue;
			}
			break;
		case SUBTILIS_FPA_INSTR_LDF:
		case SUBTILIS_FPA_INSTR_STF:
			fpa_stran = &instr->operands.fpa_stran;
			if (fpa_stran->ccode == SUBTILIS_ARM_CCODE_NV) {
				ptr = prv_remove_op(arm_s, ptr, op);
				continue;
			}
			break;
		case SUBTILIS_VFP_INSTR_FSTD:
		case SUBTILIS_VFP_INSTR_FLDD:
			vfp_stran = &instr->operands.vfp_stran;
			if (vfp_stran->ccode == SUBTILIS_ARM_CCODE_NV) {
				ptr = prv_remove_op(arm_s, ptr, op);
				continue;
			}
			break;
		default:
			break;
		}

		ptr = op->next;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $-0x1, -0x20(%rbp)
je 0x8a7ed
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq (%rax), %rax
imulq $0x68, -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x8a66d
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x8a634
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
addl $-0xd, %eax
movl %eax, %ecx
movq %rcx, -0x58(%rbp)
subl $0x3e, %eax
ja 0x8a7da
movq -0x58(%rbp), %rax
leaq 0x23330(%rip), %rcx     # 0xad9cc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x8a6f2
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x8a6f2
movq -0x30(%rbp), %rax
cmpq $0xf, 0x8(%rax)
je 0x8a6f2
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x8a800
movq %rax, -0x20(%rbp)
jmp 0x8a634
jmp 0x8a7dc
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
testb $0x1, 0x20(%rax)
jne 0x8a739
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x38(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x8a739
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x8a800
movq %rax, -0x20(%rbp)
jmp 0x8a634
jmp 0x8a7dc
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x8a776
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x8a800
movq %rax, -0x20(%rbp)
jmp 0x8a634
jmp 0x8a7dc
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpl $0xf, (%rax)
jne 0x8a7a7
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x8a800
movq %rax, -0x20(%rbp)
jmp 0x8a634
jmp 0x8a7dc
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpl $0xf, (%rax)
jne 0x8a7d8
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x8a800
movq %rax, -0x20(%rbp)
jmp 0x8a634
jmp 0x8a7dc
jmp 0x8a7dc
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x8a634
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)