// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/arj.c
// Function: do_run_arj_relocator
static void do_run_arj_relocator(deark *c, struct options_struct *arj_opts)
{
	dbuf *outf = NULL;
	i64 dst_startpos = 0;
	i64 archive_size;
	struct arjreloc_ctx *d = NULL;
	int ok = 0;

	de_dbg(c, "ARJ relocation mode");
	d = de_malloc(c, sizeof(struct arjreloc_ctx));

	if(arj_opts->reloc_opt) {
		dst_startpos = de_atoi64(arj_opts->reloc_opt);
	}
	if(dst_startpos<0) dst_startpos = 0;

	d->ahdr = dbuf_create_membuf(c, 0, 0);

	d->src_startpos = arj_opts->archive_start;
	archive_size = c->infile->len - d->src_startpos;
	if(archive_size<1) goto done;

	if(!reloc_process_archive_hdr(c, d)) goto done;

	de_dbg(c, "reloc from %"I64_FMT" to %"I64_FMT, d->src_startpos, dst_startpos);
	outf = dbuf_create_output_file(c, "arj", NULL, 0);
	dbuf_write_zeroes(outf, dst_startpos);

	// Copy the potentially-changed part of the file
	dbuf_copy(d->ahdr, 0, d->ahdr->len, outf);
	// Copy the definitely-unchanged part of the file
	dbuf_copy(c->infile, d->src_startpos+d->ahdr->len, archive_size-d->ahdr->len, outf);
	ok = 1;

done:
	if(ok) {
		if(arj_opts->mparams) {
			// Inform the caller of success
			arj_opts->mparams->out_params.flags |= 0x1;
		}
	}
	else {
		de_err(c, "Cannot relocate/extract this ARJ file");
	}
	dbuf_close(outf);
	if(d) {
		dbuf_close(d->ahdr);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r15
movq %rdi, %rbx
leaq 0xe1b7b(%rip), %rsi     # 0x117e8f
xorl %r12d, %r12d
xorl %eax, %eax
callq 0xe9226
movl $0x10, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r14
movq 0x8(%r15), %rdi
testq %rdi, %rdi
je 0x3633f
callq 0xea786
movq %rax, %r12
xorl %ebp, %ebp
testq %r12, %r12
cmovleq %rbp, %r12
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf0faf
movq %rax, 0x8(%r14)
movq %r15, 0x10(%rsp)
movq 0x10(%r15), %rsi
movq %rsi, (%r14)
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %r13
movb $0x1, %r15b
subq %rsi, %r13
jle 0x363e5
callq 0xef1ca
cmpl $0xea60, %eax           # imm = 0xEA60
jne 0x363dc
movq 0x18(%rbx), %rdi
movq (%r14), %rsi
addq $0x2, %rsi
callq 0xef1ca
movq %rax, 0x8(%rsp)
addq $-0xa29, %rax           # imm = 0xF5D7
cmpq $-0xa0b, %rax           # imm = 0xF5F5
jb 0x363dc
movq 0x18(%rbx), %rdi
movq (%r14), %rsi
addq $0x8, %rsi
callq 0xef0d5
movl %eax, %ebp
movq 0x18(%rbx), %rdi
movq (%r14), %rsi
addq $0xa, %rsi
callq 0xef0d5
cmpb $0x2, %al
jne 0x363dc
testb $0x40, %bpl
jne 0x36438
testb $0x8, %bpl
jne 0x36444
xorl %ebp, %ebp
jmp 0x36533
xorl %ebp, %ebp
xorl %edi, %edi
callq 0xebe1d
testb %r15b, %r15b
je 0x363fd
leaq 0xe1ac8(%rip), %rsi     # 0x117eb9
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x3640e
movq 0x10(%rsp), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x3640e
orb $0x1, 0x40(%rax)
movq %rbp, %rdi
callq 0xf0b13
movq 0x8(%r14), %rdi
callq 0xf0b13
movq %rbx, %rdi
movq %r14, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe9752
movb $-0x40, %r15b
leaq 0xe1a9d(%rip), %rsi     # 0x117edf
jmp 0x3644e
movb $-0x8, %r15b
leaq 0xe1ab7(%rip), %rsi     # 0x117f05
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9ef5
addb %r15b, %bpl
movq 0x18(%rbx), %rdi
movq (%r14), %rsi
movq 0x8(%r14), %rcx
movl $0x8, %edx
callq 0xefabc
movq 0x8(%r14), %rdi
movzbl %bpl, %esi
callq 0xf11be
movq 0x8(%r14), %rdi
xorl %esi, %esi
callq 0xf11be
movq 0x18(%rbx), %rdi
movq (%r14), %rsi
movq 0x8(%r14), %rcx
addq $0xa, %rsi
movl $0xa, %edx
callq 0xefabc
movq 0x8(%r14), %rdi
xorl %esi, %esi
callq 0xf1645
movq 0x8(%r14), %rdi
xorl %esi, %esi
callq 0xf1645
movq 0x18(%rbx), %rdi
movq (%r14), %rsi
movq 0x8(%r14), %rcx
addq $0x1c, %rsi
movl $0x2, %edx
callq 0xefabc
movq 0x8(%r14), %rdi
xorl %esi, %esi
callq 0xf1598
movq 0x18(%rbx), %rdi
movq (%r14), %rsi
movq 0x8(%r14), %rcx
addq $0x20, %rsi
movq 0x8(%rsp), %r15
movq %r15, %rdx
addq $-0x1c, %rdx
callq 0xefabc
movq %rbx, %rdi
movl $0x10, %esi
callq 0xeba56
movq %rax, %rbp
movq 0x8(%r14), %rsi
movl $0x4, %edx
movq %rax, %rdi
movq %r15, %rcx
callq 0xebf09
movq %rbp, %rdi
callq 0xebe2a
movq 0x8(%r14), %rdi
movslq %eax, %rsi
callq 0xf1645
movq %rbp, %rdi
callq 0xebe1d
movq (%r14), %rdx
leaq 0xe195e(%rip), %rsi     # 0x117ea3
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0xe9226
leaq 0xe18b3(%rip), %rsi     # 0x117e0f
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xf037a
movq %rax, %rbp
movq %rax, %rdi
movq %r12, %rsi
callq 0xf1346
movq 0x8(%r14), %rdi
movq 0x18(%rdi), %rdx
xorl %esi, %esi
movq %rbp, %rcx
callq 0xefabc
movq 0x18(%rbx), %rdi
movq 0x8(%r14), %rax
movq 0x18(%rax), %rax
movq (%r14), %rsi
addq %rax, %rsi
subq %rax, %r13
movq %r13, %rdx
movq %rbp, %rcx
callq 0xefabc
jmp 0x363e5