// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x15c14a(%rip), %rsi    # 0x1a3ce4
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x10, %esi
callq 0x15b780
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x47bcf
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x15ccc0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jge 0x47bde
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x168020
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rcx
subq (%rcx), %rax
movq %rax, -0x28(%rbp)
cmpq $0x1, -0x28(%rbp)
jge 0x47c2a
jmp 0x47ce1
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x47f00
cmpl $0x0, %eax
jne 0x47c41
jmp 0x47ce1
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq (%rax), %rdx
movq -0x20(%rbp), %rcx
leaq 0x15c0a1(%rip), %rsi    # 0x1a3cf8
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
leaq 0x15bffb(%rip), %rsi    # 0x1a3c64
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x166c60
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x1685f0
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rdx
movq -0x18(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
callq 0x166070
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rax
movq (%rax), %rsi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
addq 0x18(%rax), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
subq 0x18(%rax), %rdx
movq -0x18(%rbp), %rcx
callq 0x166070
movl $0x1, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x47d03
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x47d01
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x40(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x40(%rax)
jmp 0x47d15
movq -0x8(%rbp), %rdi
leaq 0x15c000(%rip), %rsi    # 0x1a3d0e
movb $0x0, %al
callq 0x15bfb0
movq -0x18(%rbp), %rdi
callq 0x1676a0
cmpq $0x0, -0x30(%rbp)
je 0x47d3f
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)