// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/backends/riscos_common/riscos_arm.c
// Function: subtilis_riscos_generate
subtilis_arm_prog_t *
subtilis_riscos_generate(
	subtilis_arm_op_pool_t *op_pool, subtilis_ir_prog_t *p,
	const subtilis_ir_rule_raw_t *rules_raw,
	size_t rule_count, size_t globals,
	const subtilis_arm_fp_if_t *fp_if,
	int32_t start_address, subtilis_error_t *err)
/* clang-format on */
{
	subtilis_ir_rule_t *parsed;
	subtilis_arm_prog_t *arm_p = NULL;
	subtilis_arm_section_t *arm_s;
	subtilis_ir_section_t *s;
	size_t i;

	parsed = malloc(sizeof(*parsed) * rule_count);
	if (!parsed) {
		subtilis_error_set_oom(err);
		return NULL;
	}

	subtilis_ir_parse_rules(rules_raw, parsed, rule_count, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	arm_p = subtilis_arm_prog_new(p->num_sections + 2, op_pool,
				      p->string_pool, p->constant_pool,
				      p->settings, fp_if, start_address, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	s = p->sections[0];
	arm_s = subtilis_arm_prog_section_new(arm_p, s->type, s->reg_counter,
					      s->freg_counter, s->label_counter,
					      s->locals, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;
	prv_add_preamble(arm_s, globals, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;
	prv_add_section(s, arm_s, parsed, rule_count, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	for (i = 1; i < p->num_sections; i++) {
		s = p->sections[i];
		if (s->section_type == SUBTILIS_IR_SECTION_ASM) {
			arm_s = (subtilis_arm_section_t *)s->asm_code;

			/*
			 * Ownership of inline assembly transfers to the ARM
			 * section.
			 */

			s->asm_code = NULL;
			subtilis_arm_prog_append_section(arm_p, arm_s, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;
			continue;
		}
		arm_s = subtilis_arm_prog_section_new(
		    arm_p, s->type, s->reg_counter, s->freg_counter,
		    s->label_counter, s->locals, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		if (s->section_type == SUBTILIS_IR_SECTION_BACKEND_BUILTIN)
			prv_add_builtin(s, arm_s, err);
		else
			prv_add_section(s, arm_s, parsed, rule_count, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	}

	free(parsed);
	parsed = NULL;

	//		printf("\n\n");
	//		subtilis_arm_prog_dump(arm_p);

	return arm_p;

cleanup:

	printf("\n\n");
	if (arm_p)
		subtilis_arm_prog_dump(arm_p);

	subtilis_arm_prog_delete(arm_p);
	free(parsed);

	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
imulq $0x150, -0x28(%rbp), %rdi # imm = 0x150
callq 0x121b0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0xa389e
movq 0x18(%rbp), %rdi
movl $0x1, %esi
leaq 0xcdfd(%rip), %rdx      # 0xb0684
movl $0x224, %ecx            # imm = 0x224
callq 0x158e0
movq $0x0, -0x8(%rbp)
jmp 0xa3b1a
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq 0x18(%rbp), %rcx
callq 0x3a080
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa38c1
jmp 0xa3ae2
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x2, %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %r8
movq -0x38(%rbp), %r9
movl 0x10(%rbp), %r10d
movq 0x18(%rbp), %rax
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x70430
movq %rax, -0x48(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa3915
jmp 0xa3ae2
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x58(%rbp), %rax
movq 0x28(%rax), %r8
movq -0x58(%rbp), %rax
movq 0x10(%rax), %r9
movq 0x18(%rbp), %rax
movq %rax, (%rsp)
callq 0x70600
movq %rax, -0x50(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa396e
jmp 0xa3ae2
movq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq 0x18(%rbp), %rdx
callq 0xa3b30
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa398d
jmp 0xa3ae2
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq 0x18(%rbp), %r8
callq 0xa3f50
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa39b4
jmp 0xa3ae2
movq $0x1, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0xa3ac7
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x2, (%rax)
jne 0xa3a2c
movq -0x58(%rbp), %rax
movq 0xd0(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
movq $0x0, 0xd0(%rax)
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq 0x18(%rbp), %rdx
callq 0x70700
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa3a27
jmp 0xa3ae2
jmp 0xa3ab6
movq -0x48(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x58(%rbp), %rax
movq 0x28(%rax), %r8
movq -0x58(%rbp), %rax
movq 0x10(%rax), %r9
movq 0x18(%rbp), %rax
movq %rax, (%rsp)
callq 0x70600
movq %rax, -0x50(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa3a74
jmp 0xa3ae2
movq -0x58(%rbp), %rax
cmpl $0x1, (%rax)
jne 0xa3a90
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq 0x18(%rbp), %rdx
callq 0xa4140
jmp 0xa3aa9
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq 0x18(%rbp), %r8
callq 0xa3f50
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0xa3ab4
jmp 0xa3ae2
jmp 0xa3ab6
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0xa39bc
movq -0x40(%rbp), %rdi
callq 0x12290
movq $0x0, -0x40(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xa3b1a
leaq 0x7389(%rip), %rdi      # 0xaae72
movb $0x0, %al
callq 0x120f0
cmpq $0x0, -0x48(%rbp)
je 0xa3b00
movq -0x48(%rbp), %rdi
callq 0x86790
movq -0x48(%rbp), %rdi
callq 0x70570
movq -0x40(%rbp), %rdi
callq 0x12290
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)