// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/misc3.c
// Function: de_run_dwc
static void de_run_dwc(deark *c, de_module_params *mparams)
{
	de_arch_lctx *d = NULL;
	i64 trailer_pos;
	i64 trailer_len;
	i64 nmembers;
	i64 fhsize; // size of each file header
	i64 pos;
	i64 i;
	struct de_timestamp tmpts;
	int need_errmsg = 0;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);

	d = de_arch_create_lctx(c);
	d->is_le = 1;
	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_CP437);
	d->private1 = de_get_ext_option_bool(c, "dwc:extract", 0);

	if(!has_dwc_sig(c)) {
		de_err(c, "Not a DWC file");
		goto done;
	}
	de_declare_fmt(c, "DWC archive");

	if(!d->private1) {
		de_info(c, "Note: Use \"-opt dwc:extract\" to attempt decompression "
			"(works for most small files).");
	}

	de_dbg(c, "trailer");
	de_dbg_indent(c, 1);

	pos = c->infile->len - 27; // Position of the "trailer size" field
	trailer_len = de_getu16le_p(&pos); // Usually 27
	trailer_pos = c->infile->len - trailer_len;
	de_dbg(c, "size: %"I64_FMT" (starts at %"I64_FMT")", trailer_len, trailer_pos);
	if(trailer_len<27 || trailer_pos<0) {
		need_errmsg = 1;
		goto done;
	}

	fhsize = (i64)de_getbyte_p(&pos);
	de_dbg(c, "file header entry size: %d", (int)fhsize);
	if(fhsize<30) {
		need_errmsg = 1;
		goto done;
	}

	pos += 13; // TODO?: name of header file ("h" command)
	de_arch_read_field_dttm_p(d, &tmpts, "archive last-modified", DE_ARCH_TSTYPE_UNIX, &pos);

	nmembers = de_getu16le_p(&pos);
	de_dbg(c, "number of member files: %d", (int)nmembers);
	de_dbg_indent(c, -1);

	pos = trailer_pos - fhsize*nmembers;
	if(pos<0) {
		need_errmsg = 1;
		goto done;
	}
	for(i=0; i<nmembers; i++) {
		do_dwc_member(c, d, pos, fhsize);
		if(d->fatalerrflag) goto done;
		pos += fhsize;
	}

done:
	if(need_errmsg) {
		de_err(c, "Bad DWC file");
	}
	de_arch_destroy_lctx(c, d);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq 0x34(%rsp), %rsi
callq 0xdebae
movq %rbx, %rdi
callq 0xf16ce
movq %rax, %r14
movl $0x1, 0x10(%rax)
pushq $0xd
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, 0x18(%r14)
leaq 0xaeffa(%rip), %rsi     # 0x118d3d
movq %rbx, %rdi
xorl %edx, %edx
callq 0xdfae5
movl %eax, 0x5c(%r14)
movq %rbx, %rdi
callq 0x6d4a8
testl %eax, %eax
je 0x6a308
leaq 0xaeff0(%rip), %rsi     # 0x118d58
movq %rbx, %rdi
callq 0xe07f7
cmpl $0x0, 0x5c(%r14)
jne 0x69d88
leaq 0xaefe6(%rip), %rsi     # 0x118d64
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf37f
leaq 0xd456e(%rip), %rsi     # 0x13e2fd
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rax
addq $-0x1b, %rax
leaq 0x18(%rsp), %rsi
movq %rax, (%rsi)
callq 0xe3fc4
movq %rax, %r15
movq 0x18(%rbx), %rax
movq 0x18(%rax), %r13
subq %r15, %r13
leaq 0xaefe6(%rip), %rsi     # 0x118db8
sets %bpl
movq %rbx, %rdi
movq %r15, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xde896
cmpq $0x1b, %r15
setl %al
orb %bpl, %al
jne 0x6a2ff
movq 0x18(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0xe3f2a
movzbl %al, %ebp
leaq 0xaefc4(%rip), %rsi     # 0x118dd2
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
cmpb $0x1e, %bpl
jb 0x6a2ff
leaq 0x18(%rsp), %r15
addq $0xd, (%r15)
leaq 0xaefb9(%rip), %rdx     # 0x118ded
leaq 0x48(%rsp), %rsi
pushq $0x1
popq %rcx
movq %r14, %rdi
movq %r15, %r8
callq 0xf1866
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fc4
movq %rax, %r12
leaq 0xaefa6(%rip), %rsi     # 0x118e03
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq %r12, %rax
imulq %rbp, %rax
subq %rax, %r13
movq %r13, (%r15)
js 0x6a2ff
xorl %eax, %eax
testq %r12, %r12
cmovleq %rax, %r12
xorl %eax, %eax
movq %rbp, 0x20(%rsp)
movq %r12, 0x38(%rsp)
cmpq %r12, %rax
je 0x6a319
movq %rax, 0x40(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf1630
movq %rax, %r12
movq %rbx, %rdi
leaq 0xcd85f(%rip), %rsi     # 0x137722
movq %r13, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rbp
movl %ebp, %esi
callq 0xdeba7
movq %rbx, %rdi
callq 0xeac74
movq %rax, 0x68(%r12)
movq 0x18(%rbx), %rdi
movl 0x18(%r14), %r9d
movq %r13, %rsi
pushq $0xc
popq %rdx
movq %rax, %rcx
movl %ebp, %r8d
callq 0xe4c9a
movq 0x68(%r12), %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0xc4b4a(%rip), %rsi     # 0x12ea5e
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x58(%r12), %rdi
movq 0x68(%r12), %rsi
callq 0xead71
addq $0xd, %r13
movq %r13, 0x28(%rsp)
movq %r12, %rdi
leaq 0x28(%rsp), %r13
movq %r13, %rsi
callq 0xf1766
movq 0x50(%r12), %rsi
addq $0x18, %rsi
movq %r14, %rdi
leaq 0xa118d(%rip), %rdx     # 0x10b0e6
movl %ebp, %ecx
movq %r13, %r8
callq 0xf1866
movq %r12, %rdi
movq %r13, %rsi
callq 0xf17ab
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe40bf
movq %rax, 0x40(%r12)
movq %rbx, %rdi
leaq 0xaeea6(%rip), %rsi     # 0x118e2f
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3f2a
movzbl %al, %ebp
movl %ebp, %edx
andl $0xf, %edx
movl %edx, 0x90(%r12)
movq %rbx, %rdi
leaq 0xaecf3(%rip), %rsi     # 0x118cac
xorl %eax, %eax
callq 0xde896
shrl $0x4, %ebp
movl %ebp, 0x94(%r12)
movq %rbx, %rdi
leaq 0xce1d9(%rip), %rsi     # 0x1381ae
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
testb $0x4, 0x94(%r12)
je 0x69ff2
movb $0x1, 0x80(%r12)
xorl %r15d, %r15d
movb $0x1, %al
movl %eax, 0x14(%rsp)
movq 0x20(%rsp), %rbp
cmpl $0x1e, %ebp
jne 0x6a00a
xorl %r13d, %r13d
jmp 0x6a03a
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3f2a
movzbl %al, %r13d
xorl %r15d, %r15d
movq %rbx, %rdi
leaq 0xaee1c(%rip), %rsi     # 0x118e43
movl %r13d, %edx
xorl %eax, %eax
callq 0xde896
cmpl $0x1f, %ebp
jne 0x6a171
movq $0x0, 0x8(%rsp)
movq %r12, %rdi
callq 0xf19d5
testl %eax, %eax
je 0x6a104
movzbl %r15b, %r15d
cmpb $0x2, %r15b
jb 0x6a0aa
movq %rbx, %rdi
callq 0xeac74
movq %rax, 0x70(%r12)
movq 0x18(%rbx), %rdi
movq 0x30(%r12), %rsi
addq 0x40(%r12), %rsi
leaq -0x1(%r15), %rdx
movl 0x18(%r14), %r9d
movq %rax, %rcx
pushq $0x1
popq %r8
callq 0xe4c9a
movq 0x70(%r12), %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0xcce39(%rip), %rsi     # 0x136ed9
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movzbl %r13b, %ebp
cmpb $0x2, %bpl
jb 0x6a10c
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r13
movq 0x18(%rbx), %rdi
addq 0x40(%r12), %r15
addq 0x30(%r12), %r15
decq %rbp
movl 0x18(%r14), %r9d
movq %r15, %rsi
movq %rbp, %rdx
movq %rax, %rcx
pushq $0x1
popq %r8
callq 0xe4c9a
movq %r13, %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0x9d6fd(%rip), %rsi     # 0x1077f5
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
jmp 0x6a10f
xorl %r13d, %r13d
jmp 0x6a2bb
xorl %r13d, %r13d
movq 0x58(%r12), %rdi
callq 0xeac85
movq 0x68(%r12), %rax
movq 0x10(%rax), %rcx
testq %rcx, %rcx
movl $0x0, %edx
cmovleq %rdx, %rcx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x6a14b
movq 0x8(%rax), %rsi
cmpl $0x2f, (%rsi,%rdx,4)
jne 0x6a146
movl $0x5f, (%rsi,%rdx,4)
incq %rdx
jmp 0x6a130
movq 0x70(%r12), %rdi
callq 0xeaf76
testl %eax, %eax
je 0x6a1dd
movq 0x58(%r12), %rdi
movq 0x68(%r12), %rsi
callq 0xead71
jmp 0x6a21e
movq 0x18(%rbx), %rdi
leaq 0x28(%rsp), %rsi
callq 0xe3f2a
movzbl %al, %r15d
movq $0x0, 0x8(%rsp)
movq %rbx, %rdi
leaq 0xaecbd(%rip), %rsi     # 0x118e53
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
cmpb $0x22, %bpl
jb 0x6a043
movq 0x18(%rbx), %rdi
leaq 0x28(%rsp), %rsi
callq 0xe3fc4
movl $0x0, 0x14(%rsp)
movq %rbx, %rdi
leaq 0xaec96(%rip), %rsi     # 0x118e60
movq %rax, 0x8(%rsp)
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
jmp 0x6a043
orb $0x1, 0x78(%r12)
movq 0x58(%r12), %rdi
movq 0x70(%r12), %rsi
callq 0xead71
movq 0x58(%r12), %rdi
pushq $0x1
popq %rsi
callq 0xf1712
movq 0x68(%r12), %rdi
callq 0xeaf76
movq 0x58(%r12), %rdi
testl %eax, %eax
je 0x6a162
pushq $0x5f
popq %rsi
callq 0xeada5
cmpb $0x0, 0x14(%rsp)
jne 0x6a298
movq 0x30(%r14), %rdi
testq %rdi, %rdi
jne 0x6a240
movq %rbx, %rdi
pushq $0x21
popq %rsi
callq 0xe0ae9
movq %rax, %rdi
movq %rax, 0x30(%r14)
callq 0xe0e44
movq 0x30(%r14), %rdi
movq 0x18(%rbx), %rsi
movq 0x30(%r12), %rcx
movq 0x40(%r12), %rdx
callq 0xe0f33
movq 0x30(%r14), %rdi
callq 0xe0e95
movl %eax, %ebp
movq %rbx, %rdi
leaq 0xaec14(%rip), %rsi     # 0x118e85
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
cmpl 0x8(%rsp), %ebp
je 0x6a298
movq %rbx, %rdi
leaq 0xaec22(%rip), %rsi     # 0x118eac
movq 0x8(%rsp), %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0xdf2a5
cmpl $0x0, 0x5c(%r14)
je 0x6a2b6
leaq 0x3229(%rip), %rax      # 0x6d4cf
movq %rax, 0xa8(%r12)
movq %r12, %rdi
callq 0xf1a85
movq 0x20(%rsp), %rbp
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf167c
movq %r13, %rdi
callq 0xeaf3c
cmpl $0x0, 0x38(%r14)
movq 0x38(%rsp), %r12
movq 0x40(%rsp), %rax
jne 0x6a319
movq 0x18(%rsp), %r13
addq %rbp, %r13
movq %r13, 0x18(%rsp)
incq %rax
jmp 0x69e9d
leaq 0xaeb18(%rip), %rsi     # 0x118e1e
jmp 0x6a30f
leaq 0xaea3a(%rip), %rsi     # 0x118d49
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf16e7
movl 0x34(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq