// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/arch/arm32/arm_mem.c
// Function: prv_memseti32_core
static void prv_memseti32_core(subtilis_ir_section_t *s,
			       subtilis_arm_section_t *arm_s,
			       subtilis_error_t *err)
{
	const size_t base_reg = 0;
	const size_t val = 2;
	const size_t stm_end_reg = 10;
	const size_t end_reg = 11;
	subtilis_arm_instr_t *instr;
	subtilis_arm_stran_instr_t *stran;
	subtilis_arm_br_instr_t *br;
	size_t i;
	size_t end_label = arm_s->label_counter++;
	size_t start_label = arm_s->label_counter++;
	size_t start_small_label = arm_s->label_counter++;

	subtilis_arm_add_sub_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false,
				 stm_end_reg, end_reg, 32, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_cmp(arm_s, SUBTILIS_ARM_INSTR_CMP,
			     SUBTILIS_ARM_CCODE_AL, base_reg, stm_end_reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	instr =
	    subtilis_arm_section_add_instr(arm_s, SUBTILIS_ARM_INSTR_B, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	br = &instr->operands.br;
	br->ccode = SUBTILIS_ARM_CCODE_GT;
	br->link = false;
	br->link_type = SUBTILIS_ARM_BR_LINK_VOID;
	br->target.label = start_small_label;

	for (i = 3; i <= 9; i++) {
		subtilis_arm_add_mov_reg(arm_s, SUBTILIS_ARM_CCODE_AL, false, i,
					 2, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	subtilis_arm_section_add_label(arm_s, start_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_mtran(arm_s, SUBTILIS_ARM_INSTR_STM,
			       SUBTILIS_ARM_CCODE_AL, 0, 255 << 2,
			       SUBTILIS_ARM_MTRAN_IA, true, false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_cmp(arm_s, SUBTILIS_ARM_INSTR_CMP,
			     SUBTILIS_ARM_CCODE_AL, base_reg, stm_end_reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	instr =
	    subtilis_arm_section_add_instr(arm_s, SUBTILIS_ARM_INSTR_B, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	br = &instr->operands.br;
	br->ccode = SUBTILIS_ARM_CCODE_LT;
	br->link = false;
	br->link_type = SUBTILIS_ARM_BR_LINK_VOID;
	br->target.label = start_label;

	subtilis_arm_section_add_label(arm_s, start_small_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_cmp(arm_s, SUBTILIS_ARM_INSTR_CMP,
			     SUBTILIS_ARM_CCODE_AL, base_reg, end_reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	instr =
	    subtilis_arm_section_add_instr(arm_s, SUBTILIS_ARM_INSTR_B, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	br = &instr->operands.br;
	br->ccode = SUBTILIS_ARM_CCODE_GE;
	br->link = false;
	br->link_type = SUBTILIS_ARM_BR_LINK_VOID;
	br->target.label = end_label;

	instr =
	    subtilis_arm_section_add_instr(arm_s, SUBTILIS_ARM_INSTR_STR, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	stran = &instr->operands.stran;
	stran->ccode = SUBTILIS_ARM_CCODE_AL;
	stran->dest = val;
	stran->base = base_reg;
	stran->offset.type = SUBTILIS_ARM_OP2_I32;
	stran->offset.op.integer = 4;
	stran->pre_indexed = false;
	stran->write_back = true;
	stran->subtract = false;
	stran->byte = false;

	instr =
	    subtilis_arm_section_add_instr(arm_s, SUBTILIS_ARM_INSTR_B, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	br = &instr->operands.br;
	br->ccode = SUBTILIS_ARM_CCODE_AL;
	br->link = false;
	br->link_type = SUBTILIS_ARM_BR_LINK_VOID;
	br->target.label = start_small_label;

	subtilis_arm_section_add_label(arm_s, end_label, err);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r15
movq 0x10(%rdi), %rax
movq %rax, 0x20(%rsp)
leaq 0x3(%rax), %rax
movq %rax, 0x10(%rdi)
movq %rsi, 0x10(%rsp)
movl $0x20, 0x8(%rsp)
movq $0xb, (%rsp)
pushq $0x2
popq %rsi
pushq $0x4
popq %rdx
pushq $0xe
popq %rcx
pushq $0xa
popq %r9
xorl %r8d, %r8d
callq 0x4ced7
cmpl $0x0, (%rbx)
jne 0x5b07b
pushq $0xa
popq %rsi
pushq $0xe
popq %rdx
pushq $0xa
popq %r8
movq %r15, %rdi
xorl %ecx, %ecx
movq %rbx, %r9
callq 0x4d921
cmpl $0x0, (%rbx)
jne 0x5b07b
pushq $0x16
popq %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x4c92b
cmpl $0x0, (%rbx)
jne 0x5b07b
movq 0x20(%rsp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x30(%rsp)
addq $0x2, %rcx
movl $0xc, 0x8(%rax)
movb $0x0, 0xc(%rax)
andl $0x0, 0x10(%rax)
movq %rcx, 0x28(%rsp)
movq %rcx, 0x18(%rax)
pushq $0x3
popq %rbp
pushq $0xd
popq %r12
pushq $0xe
popq %r13
pushq $0x2
popq %r14
cmpq $0xa, %rbp
je 0x5af31
movq %rbx, (%rsp)
movq %r15, %rdi
movl %r12d, %esi
movl %r13d, %edx
xorl %ecx, %ecx
movq %rbp, %r8
movq %r14, %r9
callq 0x4d518
incq %rbp
cmpl $0x0, (%rbx)
je 0x5af04
jmp 0x5b07b
movq %r15, %rdi
movq 0x30(%rsp), %rsi
movq %rbx, %rdx
callq 0x4c77f
cmpl $0x0, (%rbx)
jne 0x5b07b
movq %rbx, 0x10(%rsp)
andl $0x0, 0x8(%rsp)
movl $0x1, (%rsp)
pushq $0x15
popq %rsi
pushq $0xe
popq %rdx
movl $0x3fc, %r8d            # imm = 0x3FC
movq %r15, %rdi
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x4d95f
cmpl $0x0, (%rbx)
jne 0x5b07b
pushq $0xa
popq %rsi
pushq $0xe
popq %rdx
pushq $0xa
popq %r8
movq %r15, %rdi
xorl %ecx, %ecx
movq %rbx, %r9
callq 0x4d921
cmpl $0x0, (%rbx)
jne 0x5b07b
pushq $0x16
popq %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x4c92b
cmpl $0x0, (%rbx)
jne 0x5b07b
movl $0xb, 0x8(%rax)
movb $0x0, 0xc(%rax)
andl $0x0, 0x10(%rax)
movq 0x30(%rsp), %rcx
movq %rcx, 0x18(%rax)
movq %r15, %rdi
movq 0x28(%rsp), %rsi
movq %rbx, %rdx
callq 0x4c77f
cmpl $0x0, (%rbx)
jne 0x5b07b
pushq $0xa
popq %rsi
pushq $0xe
popq %rdx
pushq $0xb
popq %r8
movq %r15, %rdi
xorl %ecx, %ecx
movq %rbx, %r9
callq 0x4d921
cmpl $0x0, (%rbx)
jne 0x5b07b
pushq $0x16
popq %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x4c92b
cmpl $0x0, (%rbx)
jne 0x5b07b
movl $0xa, 0x8(%rax)
movb $0x0, 0xc(%rax)
andl $0x0, 0x10(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x18(%rax)
pushq $0x13
popq %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x4c92b
cmpl $0x0, (%rbx)
jne 0x5b07b
movl $0xe, 0x8(%rax)
movq $0x2, 0x10(%rax)
andq $0x0, 0x18(%rax)
movl $0x1, 0x20(%rax)
movl $0x4, 0x28(%rax)
movl $0x100, 0x48(%rax)      # imm = 0x100
pushq $0x16
popq %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x4c92b
cmpl $0x0, (%rbx)
je 0x5b08a
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xe, 0x8(%rax)
movb $0x0, 0xc(%rax)
andl $0x0, 0x10(%rax)
movq 0x28(%rsp), %rcx
movq %rcx, 0x18(%rax)
movq %r15, %rdi
movq 0x20(%rsp), %rsi
movq %rbx, %rdx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4c77f