// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/arch/arm32/arm_mem.c
// Function: subtilis_arm_mem_memseti8
void subtilis_arm_mem_memseti8(subtilis_ir_section_t *s,
			       subtilis_arm_section_t *arm_s,
			       subtilis_error_t *err)
{
	subtilis_arm_br_instr_t *br;
	subtilis_arm_instr_t *instr;
	subtilis_arm_data_instr_t *datai;
	subtilis_arm_stran_instr_t *stran;
	const size_t base_reg = 0;
	const size_t size_reg = 1;
	const size_t val = 2;
	const size_t end_reg = 11;
	size_t tiny_label = arm_s->label_counter++;
	size_t finish_label = arm_s->label_counter++;
	size_t start_tiny_loop = arm_s->label_counter++;

	subtilis_arm_add_cmp_imm(arm_s, SUBTILIS_ARM_INSTR_CMP,
				 SUBTILIS_ARM_CCODE_AL, size_reg, 4, 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 = tiny_label;

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

	datai = &instr->operands.data;
	datai->status = false;
	datai->ccode = SUBTILIS_ARM_CCODE_AL;
	datai->dest = val;
	datai->op1 = val;
	datai->op2.type = SUBTILIS_ARM_OP2_SHIFTED;
	datai->op2.op.shift.shift_reg = false;
	datai->op2.op.shift.reg = val;
	datai->op2.op.shift.type = SUBTILIS_ARM_SHIFT_LSL;
	datai->op2.op.shift.shift.integer = 16;

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

	datai = &instr->operands.data;
	datai->status = false;
	datai->ccode = SUBTILIS_ARM_CCODE_AL;
	datai->dest = val;
	datai->op1 = val;
	datai->op2.type = SUBTILIS_ARM_OP2_SHIFTED;
	datai->op2.op.shift.shift_reg = false;
	datai->op2.op.shift.reg = val;
	datai->op2.op.shift.type = SUBTILIS_ARM_SHIFT_LSL;
	datai->op2.op.shift.shift.integer = 8;

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

	datai = &instr->operands.data;
	datai->status = false;
	datai->ccode = SUBTILIS_ARM_CCODE_AL;
	datai->dest = end_reg;
	datai->op1 = base_reg;
	datai->op2.type = SUBTILIS_ARM_OP2_REG;
	datai->op2.op.reg = size_reg;

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

	datai = &instr->operands.data;
	datai->status = false;
	datai->ccode = SUBTILIS_ARM_CCODE_AL;
	datai->dest = end_reg;
	datai->op1 = end_reg;
	datai->op2.type = SUBTILIS_ARM_OP2_I32;
	datai->op2.op.integer = 3;

	prv_memseti32_core(s, arm_s, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

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

	datai = &instr->operands.data;
	datai->status = false;
	datai->ccode = SUBTILIS_ARM_CCODE_AL;
	datai->dest = size_reg;
	datai->op1 = size_reg;
	datai->op2.type = SUBTILIS_ARM_OP2_I32;
	datai->op2.op.integer = 3;

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

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

	datai = &instr->operands.data;
	datai->status = false;
	datai->ccode = SUBTILIS_ARM_CCODE_AL;
	datai->dest = end_reg;
	datai->op1 = base_reg;
	datai->op2.type = SUBTILIS_ARM_OP2_REG;
	datai->op2.op.reg = size_reg;

	subtilis_arm_section_add_label(arm_s, start_tiny_loop, 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 = finish_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 = 1;
	stran->pre_indexed = false;
	stran->write_back = true;
	stran->subtract = false;
	stran->byte = true;

	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_tiny_loop;

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

	subtilis_arm_add_mov_reg(arm_s, SUBTILIS_ARM_CCODE_AL, false, 15, 14,
				 err);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdx, %r14
movq %rsi, %rbx
movq 0x10(%rsi), %r15
leaq 0x3(%r15), %rax
movq %rax, 0x10(%rsi)
pushq $0xa
popq %rsi
pushq $0xe
popq %rdx
pushq $0x1
popq %r12
pushq $0x4
popq %r8
movq %rbx, %rdi
movq %r12, %rcx
movq %r14, %r9
callq 0x4d87e
cmpl $0x0, (%r14)
jne 0x5b3d1
pushq $0x16
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4c92b
cmpl $0x0, (%r14)
jne 0x5b3d1
movl $0xb, 0x8(%rax)
movb $0x0, 0xc(%rax)
andl $0x0, 0x10(%rax)
movq %r15, 0x18(%rax)
pushq $0xc
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4c92b
cmpl $0x0, (%r14)
jne 0x5b3d1
xorl %ecx, %ecx
movb %cl, 0xc(%rax)
movl $0xe, 0x8(%rax)
pushq $0x2
popq %r13
movq %r13, 0x10(%rax)
movq %r13, 0x18(%rax)
movl $0x2, 0x20(%rax)
movb %cl, 0x40(%rax)
movq %r13, 0x28(%rax)
andl $0x0, 0x30(%rax)
movl $0x10, 0x38(%rax)
pushq $0xc
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4c92b
cmpl $0x0, (%r14)
jne 0x5b3d1
xorl %ecx, %ecx
movb %cl, 0xc(%rax)
movl $0xe, 0x8(%rax)
movq %r13, 0x10(%rax)
movq %r13, 0x18(%rax)
movl $0x2, 0x20(%rax)
movb %cl, 0x40(%rax)
movq %r13, 0x28(%rax)
andl $0x0, 0x30(%rax)
movl $0x8, 0x38(%rax)
pushq $0x4
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4c92b
cmpl $0x0, (%r14)
jne 0x5b3d1
movb $0x0, 0xc(%rax)
movl $0xe, 0x8(%rax)
movq $0xb, 0x10(%rax)
andq $0x0, 0x18(%rax)
andl $0x0, 0x20(%rax)
movq $0x1, 0x28(%rax)
pushq $0xe
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4c92b
cmpl $0x0, (%r14)
jne 0x5b3d1
movb $0x0, 0xc(%rax)
movl $0xe, 0x8(%rax)
pushq $0xb
popq %rcx
movq %rcx, 0x10(%rax)
movq %rcx, 0x18(%rax)
movl $0x1, 0x20(%rax)
movl $0x3, 0x28(%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5ae3c
cmpl $0x0, (%r14)
jne 0x5b3d1
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x4c92b
cmpl $0x0, (%r14)
jne 0x5b3d1
movb $0x0, 0xc(%rax)
movl $0xe, 0x8(%rax)
movq %r12, 0x10(%rax)
movq %r12, 0x18(%rax)
movl $0x1, 0x20(%rax)
movl $0x3, 0x28(%rax)
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4c77f
cmpl $0x0, (%r14)
jne 0x5b3d1
pushq $0x4
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4c92b
cmpl $0x0, (%r14)
jne 0x5b3d1
leaq 0x2(%r15), %r12
movb $0x0, 0xc(%rax)
movl $0xe, 0x8(%rax)
movq $0xb, 0x10(%rax)
andq $0x0, 0x18(%rax)
andl $0x0, 0x20(%rax)
movq $0x1, 0x28(%rax)
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x4c77f
cmpl $0x0, (%r14)
jne 0x5b3d1
pushq $0xa
popq %rsi
pushq $0xe
popq %rdx
pushq $0xb
popq %r8
movq %rbx, %rdi
xorl %ecx, %ecx
movq %r14, %r9
callq 0x4d921
cmpl $0x0, (%r14)
jne 0x5b3d1
pushq $0x16
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4c92b
cmpl $0x0, (%r14)
jne 0x5b3d1
incq %r15
movl $0xa, 0x8(%rax)
movb $0x0, 0xc(%rax)
andl $0x0, 0x10(%rax)
movq %r15, 0x18(%rax)
pushq $0x13
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4c92b
cmpl $0x0, (%r14)
jne 0x5b3d1
movl $0xe, 0x8(%rax)
movq $0x2, 0x10(%rax)
andq $0x0, 0x18(%rax)
pushq $0x1
popq %rcx
movl %ecx, 0x20(%rax)
movl %ecx, 0x28(%rax)
movl $0x1000100, 0x48(%rax)  # imm = 0x1000100
pushq $0x16
popq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4c92b
cmpl $0x0, (%r14)
jne 0x5b3d1
movl $0xe, 0x8(%rax)
movb $0x0, 0xc(%rax)
andl $0x0, 0x10(%rax)
movq %r12, 0x18(%rax)
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4c77f
cmpl $0x0, (%r14)
jne 0x5b3d1
movq %r14, (%rsp)
pushq $0xd
popq %rsi
pushq $0xe
popq %rdx
pushq $0xf
popq %r8
pushq $0xe
popq %r9
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x4d518
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq