// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/arj.c
// Function: decompress_method_4
static void decompress_method_4(deark *c, lctx *d, struct member_data *md,
	struct de_dfilter_in_params *dcmpri, struct de_dfilter_out_params *dcmpro,
	struct de_dfilter_results *dres)
{
	struct method4_ctx *cctx = NULL;
	struct de_lz77buffer *ringbuf = NULL;

	cctx = de_malloc(c, sizeof(struct method4_ctx));
	cctx->dcmpro = dcmpro;
	cctx->bitrd.f = dcmpri->f;
	cctx->bitrd.curpos = dcmpri->pos;
	cctx->bitrd.endpos = dcmpri->pos + dcmpri->len;

	if(md->archiver_ver_num==1) {
		cctx->old_format = 1;
	}

	// The maximum offset that can be encoded is 15871, so a 16K history is enough.
	ringbuf = de_lz77buffer_create(c, 16384);
	ringbuf->writebyte_cb = method4_lz77buf_writebytecb;
	ringbuf->userdata = (void*)cctx;

	while(1) {
		UI len_code;

		if(cctx->bitrd.eof_flag) goto done;
		if(cctx->stop_flag) goto done;
		if(cctx->dcmpro->len_known && (cctx->nbytes_written >= cctx->dcmpro->expected_len)) {
			goto done;
		}

		len_code = method4_read_a_length_code(cctx);
		if(len_code==0) {
			u8 b;

			b = (u8)de_bitreader_getbits(&cctx->bitrd, 8);
			if(c->debug_level>=4) {
				de_dbg(c, "lit %u", (UI)b);
			}
			de_lz77buffer_add_literal_byte(ringbuf, b);
		}
		else {
			UI offs;

			offs = method4_read_an_offset(cctx);
			if(c->debug_level>=4) {
				de_dbg(c, "match d=%u l=%u", (UI)(offs+1), (UI)(len_code+2));
			}
			de_lz77buffer_copy_from_hist(ringbuf, ringbuf->curpos-1-offs, len_code+2);
		}
	}

done:
	dres->bytes_consumed_valid = 1;
	dres->bytes_consumed = cctx->bitrd.curpos - dcmpri->pos;
	de_lz77buffer_destroy(c, ringbuf);
	de_free(c, cctx);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movl $0x48, %esi
callq 0x15b780
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x20(%rbp), %rax
addq 0x10(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
movzbl 0xd(%rax), %eax
cmpl $0x1, %eax
jne 0x4a6ea
movq -0x38(%rbp), %rax
movb $0x1, 0xc(%rax)
movq -0x8(%rbp), %rdi
movl $0x4000, %esi           # imm = 0x4000
callq 0x1785d0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
leaq 0x1a9(%rip), %rcx       # 0x4a8b0
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
cmpb $0x0, 0x30(%rax)
je 0x4a725
jmp 0x4a808
movq -0x38(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x4a734
jmp 0x4a808
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movzbl 0x8(%rax), %eax
cmpl $0x0, %eax
je 0x4a75f
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x10(%rcx), %rcx
cmpq 0x10(%rcx), %rax
jl 0x4a75f
jmp 0x4a808
movq -0x38(%rbp), %rdi
callq 0x4a940
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x4a7b4
movq -0x38(%rbp), %rdi
addq $0x18, %rdi
movl $0x8, %esi
callq 0x16a390
movb %al, -0x45(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x4, (%rax)
jl 0x4a7a5
movq -0x8(%rbp), %rdi
movzbl -0x45(%rbp), %edx
leaq 0x18bdda(%rip), %rsi    # 0x1d6578
movb $0x0, %al
callq 0x15b0d0
movq -0x40(%rbp), %rdi
movzbl -0x45(%rbp), %esi
callq 0x178880
jmp 0x4a803
movq -0x38(%rbp), %rdi
callq 0x4a9e0
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x4, (%rax)
jl 0x4a7e7
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %edx
addl $0x1, %edx
movl -0x44(%rbp), %ecx
addl $0x2, %ecx
leaq 0x18cbf0(%rip), %rsi    # 0x1d73d0
movb $0x0, %al
callq 0x15b0d0
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rax
movl 0x10(%rax), %esi
subl $0x1, %esi
subl -0x4c(%rbp), %esi
movl -0x44(%rbp), %edx
addl $0x2, %edx
callq 0x1788e0
jmp 0x4a716
movq -0x30(%rbp), %rax
movb $0x1, 0x4(%rax)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x20(%rbp), %rax
subq 0x8(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x178950
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x15b820
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)