// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/arch/arm32/arm_encode.c
// Function: prv_encode_prog
static void prv_encode_prog(subtilis_arm_prog_t *arm_p,
			    subtilis_arm_encode_ud_t *ud, subtilis_error_t *err)
{
	subtilis_arm_section_t *arm_s;
	size_t i;
	size_t size_in_bytes;
	size_t size_in_words;
	size_t *const_locations = NULL;

	for (i = 0; i < arm_p->num_sections; i++) {
		arm_s = arm_p->sections[i];
		subtilis_arm_link_section(ud->link, i, ud->bytes_written);
		prv_reset_encode_ud(ud, arm_s);
		prv_arm_encode(arm_s, ud, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	/* Let's write the constants arrays and strings */

	if (arm_p->constant_pool->size > 0) {
		const_locations = malloc(arm_p->constant_pool->size *
					 sizeof(*const_locations));
		if (!const_locations) {
			subtilis_error_set_oom(err);
			return;
		}
		for (i = 0; i < arm_p->constant_pool->size; i++) {
			size_in_bytes = arm_p->constant_pool->data[i].data_size;
			size_in_words = size_in_bytes >> 2;
			if (size_in_bytes > size_in_words << 2)
				size_in_bytes = (size_in_words + 1) << 2;
			prv_ensure_code_size(ud, size_in_bytes, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;
			const_locations[i] = ud->bytes_written;
			prv_copy_constant_to_buf(
			    arm_p, ud, &arm_p->constant_pool->data[i], err);
			if (err->type != SUBTILIS_ERROR_OK)
				return;
			ud->bytes_written += size_in_bytes;
		}
	}

	subtilis_arm_link_link(ud->link, ud->code, ud->bytes_written,
			       const_locations, arm_p->constant_pool->size,
			       err);

cleanup:

	free(const_locations);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rdx, %rbx
movq %rsi, %r14
cmpq $0x0, 0x8(%rdi)
movq %rdi, (%rsp)
je 0x57352
leaq 0x58(%r14), %rax
movq %rax, 0x18(%rsp)
leaq 0x88(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
movq (%rdi), %rax
movq (%rax,%r15,8), %r13
movq 0x30(%r14), %rdx
movq 0x80(%r14), %rdi
movq %r15, %rsi
callq 0x5a405
movq %r13, (%r14)
movq 0x10(%r13), %rax
movq %rax, 0x20(%r14)
xorl %eax, %eax
movq %rax, 0x70(%r14)
movq %rax, 0x48(%r14)
movq 0x18(%rsp), %rax
pxor %xmm0, %xmm0
movdqu %xmm0, (%rax)
movq 0x10(%rsp), %rax
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, (%rax)
movq %r14, 0x28(%rsp)
leaq 0x6b3(%rip), %rax       # 0x575fa
movq %rax, 0x38(%rsp)
leaq 0x72e(%rip), %rax       # 0x57681
movq %rax, 0x30(%rsp)
leaq 0x911(%rip), %rax       # 0x57870
movq %rax, 0x40(%rsp)
leaq 0xaf6(%rip), %rax       # 0x57a61
movq %rax, 0x48(%rsp)
leaq 0xbf0(%rip), %rax       # 0x57b67
movq %rax, 0x50(%rsp)
leaq 0xc2a(%rip), %rax       # 0x57bad
movq %rax, 0x58(%rsp)
leaq 0xc64(%rip), %rax       # 0x57bf3
movq %rax, 0x60(%rsp)
leaq 0xe4d(%rip), %rax       # 0x57de8
movq %rax, 0x68(%rsp)
leaq 0xf9e(%rip), %rax       # 0x57f45
movq %rax, 0x70(%rsp)
leaq 0x108d(%rip), %rax      # 0x58040
movq %rax, 0x78(%rsp)
leaq 0x111d(%rip), %rax      # 0x580dc
movq %rax, 0x80(%rsp)
leaq 0x11ae(%rip), %rax      # 0x5817c
movq %rax, 0x88(%rsp)
leaq 0x1254(%rip), %rax      # 0x58231
movq %rax, 0x90(%rsp)
leaq 0x12b2(%rip), %rax      # 0x5829e
movq %rax, 0xa0(%rsp)
leaq 0x13a4(%rip), %rax      # 0x5839f
movq %rax, 0x98(%rsp)
leaq 0x146f(%rip), %rax      # 0x58479
movq %rax, 0xa8(%rsp)
leaq 0x14a8(%rip), %rax      # 0x584c1
movq %rax, 0xb0(%rsp)
leaq 0x14e4(%rip), %rax      # 0x5850c
movq %rax, 0xb8(%rsp)
leaq 0x15f3(%rip), %rax      # 0x5862a
movq %rax, 0xc0(%rsp)
leaq 0x1713(%rip), %rax      # 0x58759
movq %rax, 0xc8(%rsp)
leaq 0x17fa(%rip), %rax      # 0x5884f
movq %rax, 0xd0(%rsp)
leaq 0x1880(%rip), %rax      # 0x588e4
movq %rax, 0xd8(%rsp)
leaq 0x1913(%rip), %rax      # 0x58986
movq %rax, 0xe0(%rsp)
leaq 0x1a4b(%rip), %rax      # 0x58acd
movq %rax, 0xe8(%rsp)
leaq 0x1b7b(%rip), %rax      # 0x58c0c
movq %rax, 0xf0(%rsp)
leaq 0x1bf7(%rip), %rax      # 0x58c97
movq %rax, 0xf8(%rsp)
leaq 0x1d6d(%rip), %rax      # 0x58e1c
movq %rax, 0x100(%rsp)
leaq 0x1f1a(%rip), %rax      # 0x58fd8
movq %rax, 0x108(%rsp)
leaq 0x1ff5(%rip), %rax      # 0x590c2
movq %rax, 0x110(%rsp)
leaq 0x21a2(%rip), %rax      # 0x5927e
movq %rax, 0x118(%rsp)
leaq 0x22da(%rip), %rax      # 0x593c5
movq %rax, 0x120(%rsp)
leaq 0x23a4(%rip), %rax      # 0x5949e
movq %rax, 0x128(%rsp)
leaq 0x2459(%rip), %rax      # 0x59562
movq %rax, 0x130(%rsp)
leaq 0x252a(%rip), %rax      # 0x59642
movq %rax, 0x138(%rsp)
leaq 0x269f(%rip), %rax      # 0x597c6
movq %rax, 0x140(%rsp)
leaq 0x2789(%rip), %rax      # 0x598bf
movq %rax, 0x148(%rsp)
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
movq %rbx, %rdx
callq 0x5275c
cmpl $0x0, (%rbx)
jne 0x574d6
movq %r14, %rdi
movq %rbx, %rsi
callq 0x599cc
cmpl $0x0, (%rbx)
jne 0x574d6
movq %r15, 0x20(%rsp)
cmpq $0x0, 0x70(%r14)
je 0x5730a
movl $0x10, %r13d
xorl %r15d, %r15d
movq 0x68(%r14), %r12
movq (%r12,%r13), %rbp
testb $0x3, %bpl
je 0x571af
movq %rbx, %rdi
movl $0x5d, %esi
leaq 0x1ecdf(%rip), %rdx     # 0x75e80
movl $0xee, %ecx
callq 0x145a4
xorl %ebp, %ebp
jmp 0x571b3
addq 0x28(%r14), %rbp
cmpl $0x0, (%rbx)
jne 0x5730a
movl -0x10(%r12,%r13), %eax
cmpl $0x1, %eax
je 0x57227
testl %eax, %eax
jne 0x572de
movq 0x10(%r14), %rcx
movq -0x8(%r12,%r13), %rdx
movq (%r12,%r13), %rax
movq (%rcx,%rdx,8), %rcx
movq %rcx, %rsi
subq %rax, %rsi
negq %rsi
movq %rcx, %rdx
subq %rax, %rdx
cmovbeq %rsi, %rdx
cmpq $0x800000, %rdx         # imm = 0x800000
jbe 0x57279
movq %rbx, %rdi
movl $0xf, %esi
leaq 0x1ec76(%rip), %rdx     # 0x75e80
movl $0x91b, %ecx            # imm = 0x91B
callq 0x145a4
movl $0xfffffe, %eax         # imm = 0xFFFFFE
cmpl $0x0, (%rbx)
je 0x572db
jmp 0x5730a
movq 0x10(%r14), %rax
movq -0x8(%r12,%r13), %rdx
movq (%r12,%r13), %rcx
movq (%rax,%rdx,8), %rdx
movq %rdx, %rax
subq %rcx, %rax
negq %rax
movq %rdx, %rsi
subq %rcx, %rsi
cmovbeq %rax, %rsi
movq %rsi, %rax
shrq $0x20, %rax
je 0x5729a
movq %rbx, %rdi
movl $0xf, %esi
leaq 0x1ec1d(%rip), %rdx     # 0x75e80
movl $0x91b, %ecx            # imm = 0x91B
callq 0x145a4
xorl %eax, %eax
cmpl $0x0, (%rbx)
je 0x572a9
jmp 0x5730a
movl %edx, %esi
negl %esi
cmpq %rax, %rcx
cmovael %edx, %esi
leal 0x3(%rsi), %eax
testl %esi, %esi
cmovnsl %esi, %eax
shrl $0x2, %eax
addl $0xfffffe, %eax         # imm = 0xFFFFFE
andl $0xffffff, %eax         # imm = 0xFFFFFF
jmp 0x572db
movl %esi, %eax
negl %eax
cmpq %rcx, %rdx
cmovael %esi, %eax
cmpl $0x7, %eax
jg 0x572c4
movl $0x8, %edi
subl %eax, %edi
movl (%rbp), %eax
movl $0xff3fffff, %ecx       # imm = 0xFF3FFFFF
andl %ecx, %eax
orl $0x400000, %eax         # imm = 0x400000
movl %eax, (%rbp)
jmp 0x572c9
addl $-0x8, %eax
movl %eax, %edi
leaq 0xc(%rsp), %rsi
callq 0x4f87d
testb %al, %al
je 0x572f1
movl 0xc(%rsp), %eax
orl %eax, (%rbp)
incq %r15
addq $0x18, %r13
cmpq 0x70(%r14), %r15
jb 0x57184
jmp 0x5730a
movq %rbx, %rdi
movl $0x61, %esi
leaq 0x1eb80(%rip), %rdx     # 0x75e80
movl $0x94e, %ecx            # imm = 0x94E
callq 0x145a4
movl $0x9, 0x150(%rsp)
movl $0x4, 0x158(%rsp)
movq %r14, %rdi
leaq 0x150(%rsp), %rsi
movq %rbx, %rdx
callq 0x57681
cmpl $0x0, (%rbx)
jne 0x574d6
movq 0x20(%rsp), %r15
incq %r15
movq (%rsp), %rdi
cmpq 0x8(%rdi), %r15
jb 0x56ef2
movq 0x20(%rdi), %r13
movq (%r13), %rdi
testq %rdi, %rdi
je 0x57493
shlq $0x3, %rdi
callq 0x121d0
testq %rax, %rax
je 0x574bd
movq %rax, %r12
xorl %r15d, %r15d
movq 0x10(%r13), %rax
leaq (%r15,%r15,2), %r13
movq (%rax,%r13,8), %rbp
addq $0x3, %rbp
andq $-0x4, %rbp
movq %r14, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x5758f
cmpl $0x0, (%rbx)
jne 0x574b3
movq 0x30(%r14), %rdi
movq %rdi, (%r12,%r15,8)
movq (%rsp), %rcx
movq 0x20(%rcx), %rax
movq 0x10(%rax), %rax
leaq (%rax,%r13,8), %r13
cmpb $0x1, 0x10(%r13)
jne 0x57404
movq 0x40(%rcx), %rax
testq %rax, %rax
je 0x57404
cmpb $0x1, 0xc(%rax)
jne 0x57404
testb $0x3, %dil
je 0x57463
movq %rbx, %rdi
movl $0x5d, %esi
leaq 0x1ea93(%rip), %rdx     # 0x75e80
movl $0xee, %ecx
callq 0x145a4
cmpl $0x0, (%rbx)
jne 0x574d6
xorl %edi, %edi
jmp 0x57467
addq 0x28(%r14), %rdi
movq (%r13), %rdx
movq 0x8(%r13), %rsi
callq 0x121b0
movq (%r13), %rax
movq %rax, %rcx
andq $0x3, %rcx
je 0x5743c
movl $0x4, %edx
subq %rcx, %rdx
movq 0x28(%r14), %rdi
addq 0x30(%r14), %rdi
addq %rax, %rdi
xorl %esi, %esi
callq 0x12140
cmpl $0x0, (%rbx)
jne 0x574d6
addq %rbp, 0x30(%r14)
incq %r15
movq (%rsp), %rax
movq 0x20(%rax), %r13
movq (%r13), %r8
cmpq %r8, %r15
jb 0x5737b
jmp 0x57499
addq 0x28(%r14), %rdi
movq (%r13), %rax
cmpq $0x8, %rax
jb 0x5743c
shrq $0x3, %rax
movq 0x8(%r13), %rcx
xorl %edx, %edx
movl 0x4(%rcx,%rdx,8), %esi
movl %esi, (%rdi,%rdx,8)
movl (%rcx,%rdx,8), %esi
movl %esi, 0x4(%rdi,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x5747b
jmp 0x5743c
xorl %r8d, %r8d
xorl %r12d, %r12d
movq 0x80(%r14), %rdi
movq 0x28(%r14), %rsi
movq 0x30(%r14), %rdx
movq %r12, %rcx
movq %rbx, %r9
callq 0x5a40e
movq %r12, %rdi
callq 0x122c0
jmp 0x574d6
leaq 0x1e9bc(%rip), %rdx     # 0x75e80
movq %rbx, %rdi
movl $0x1, %esi
movl $0xa1d, %ecx            # imm = 0xA1D
callq 0x145a4
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq