// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rdi, %rbx
leaq 0x24(%rsp), %rsi
callq 0xe958c
movq %rbx, %rdi
callq 0xfdb0a
movq %rax, %r14
movl $0x1, 0x10(%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0xd, %edx
callq 0xeb7d1
movl %eax, 0x18(%r14)
leaq 0xb80d7(%rip), %rsi     # 0x125d0d
movq %rbx, %rdi
xorl %edx, %edx
callq 0xea727
movl %eax, 0x5c(%r14)
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rsi
addq $-0x3, %rsi
leaq 0xb81a4(%rip), %rdx     # 0x125dfb
movl $0x3, %ecx
callq 0xf025e
testl %eax, %eax
je 0x6dc71
leaq 0xb80ad(%rip), %r15     # 0x125d19
jmp 0x6e1df
leaq 0xb80b0(%rip), %rsi     # 0x125d28
movq %rbx, %rdi
callq 0xeb6d6
cmpl $0x0, 0x5c(%r14)
jne 0x6dc98
leaq 0xb80a6(%rip), %rsi     # 0x125d34
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9ef5
leaq 0xdd537(%rip), %rsi     # 0x14b1d6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movq 0x18(%rdi), %rax
addq $-0x1b, %rax
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
callq 0xef1ed
movq %rax, %r15
movq 0x18(%rbx), %rax
movq 0x18(%rax), %r12
subq %r15, %r12
leaq 0xb80a4(%rip), %rsi     # 0x125d88
sets %bpl
movq %rbx, %rdi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0xe9226
cmpq $0x1b, %r15
setl %al
orb %bpl, %al
leaq 0xb80e5(%rip), %r15     # 0x125dee
jne 0x6e1df
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0xef14d
movzbl %al, %ebp
leaq 0xb807b(%rip), %rsi     # 0x125da2
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe9226
cmpb $0x1e, %bpl
jb 0x6e1df
leaq 0x10(%rsp), %r13
addq $0xd, (%r13)
leaq 0xb806f(%rip), %rdx     # 0x125dbd
leaq 0x38(%rsp), %rsi
movq %r14, %rdi
movl $0x1, %ecx
movq %r13, %r8
callq 0xfdc9b
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef1ed
movq %rax, %r13
leaq 0xb805a(%rip), %rsi     # 0x125dd3
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq %r13, %rax
movq %rbp, (%rsp)
imulq %rbp, %rax
subq %rax, %r12
leaq 0x10(%rsp), %rax
movq %r12, (%rax)
js 0x6e1df
movq %r13, %rcx
testq %r13, %r13
movq (%rsp), %r12
jle 0x6e1ec
xorl %r13d, %r13d
movq %rcx, 0x30(%rsp)
movq 0x10(%rsp), %r15
movq %r15, 0x8(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfda6c
movq %rax, %rbp
movq %rbx, %rdi
leaq 0xd68a9(%rip), %rsi     # 0x144692
movq %r15, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
callq 0xf6870
movq %rax, 0x68(%rbp)
movq 0x18(%rbx), %rdi
movq 0x8(%rsp), %rsi
movl 0x18(%r14), %r9d
movl $0xc, %edx
movq %rax, %rcx
movl $0x1, %r8d
callq 0xf01b0
movq 0x68(%rbp), %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0xcdb95(%rip), %rsi     # 0x13b9d4
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x58(%rbp), %rdi
movq 0x68(%rbp), %rsi
callq 0xf6969
addq $0xd, 0x8(%rsp)
movq %rbp, %rdi
leaq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0xfdb9b
movq 0x50(%rbp), %rsi
addq $0x18, %rsi
movq %r14, %rdi
leaq 0xaa220(%rip), %rdx     # 0x11809e
movl $0x1, %ecx
movq %r15, %r8
callq 0xfdc9b
movq %rbp, %rdi
movq %r15, %rsi
callq 0xfdbe0
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef3a0
movq %rax, 0x40(%rbp)
movq %rbx, %rdi
leaq 0xb7f4f(%rip), %rsi     # 0x125dff
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef14d
movzbl %al, %r15d
movl %r15d, %edx
andl $0xf, %edx
movl %edx, 0x90(%rbp)
movq %rbx, %rdi
leaq 0xb7d9c(%rip), %rsi     # 0x125c7c
xorl %eax, %eax
callq 0xe9226
shrl $0x4, %r15d
movl %r15d, 0x94(%rbp)
movq %rbx, %rdi
leaq 0xd7222(%rip), %rsi     # 0x14511e
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
testb $0x4, 0x94(%rbp)
je 0x6df16
movb $0x1, 0x80(%rbp)
cmpl $0x1e, %r12d
jne 0x6df21
xorl %r12d, %r12d
jmp 0x6df47
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xef14d
movzbl %al, %r12d
movq %rbx, %rdi
leaq 0xb7ed6(%rip), %rsi     # 0x125e13
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9226
cmpb $0x20, (%rsp)
jb 0x6df75
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xef14d
movzbl %al, %r15d
movq %rbx, %rdi
leaq 0xb7eba(%rip), %rsi     # 0x125e23
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
jmp 0x6df78
xorl %r15d, %r15d
movq $0x0, 0x18(%rsp)
cmpb $0x22, (%rsp)
jb 0x6dfad
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xef1ed
movq %rbx, %rdi
leaq 0xb7e91(%rip), %rsi     # 0x125e30
movq %rax, 0x18(%rsp)
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbp, %rdi
callq 0xfde12
testl %eax, %eax
je 0x6e064
cmpl $0x2, %r15d
jb 0x6e00e
movq %rbx, %rdi
callq 0xf6870
movq %rax, 0x70(%rbp)
movq 0x18(%rbx), %rdi
movq 0x30(%rbp), %rsi
addq 0x40(%rbp), %rsi
leaq -0x1(%r15), %rdx
movl 0x18(%r14), %r9d
movq %rax, %rcx
movl $0x1, %r8d
callq 0xf01b0
movq 0x70(%rbp), %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0xd5e45(%rip), %rsi     # 0x143e49
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
cmpl $0x2, %r12d
jb 0x6e070
movq %rbx, %rdi
callq 0xf6870
movq 0x18(%rbx), %rdi
addq 0x40(%rbp), %r15
addq 0x30(%rbp), %r15
decq %r12
movl 0x18(%r14), %r9d
movq %r15, %rsi
movq %rax, %r15
movq %r12, %rdx
movq %rax, %rcx
movl $0x1, %r8d
callq 0xf01b0
movq %r15, %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0xa674d(%rip), %rsi     # 0x1147a5
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
jmp 0x6e073
xorl %r15d, %r15d
movq (%rsp), %r12
jmp 0x6e1a0
xorl %r15d, %r15d
movq (%rsp), %r12
movq 0x58(%rbp), %rdi
callq 0xf6883
movq 0x68(%rbp), %rcx
movq 0x10(%rcx), %rax
testq %rax, %rax
jle 0x6e0a8
movq 0x8(%rcx), %rcx
xorl %edx, %edx
cmpl $0x2f, (%rcx,%rdx,4)
jne 0x6e0a0
movl $0x5f, (%rcx,%rdx,4)
incq %rdx
cmpq %rdx, %rax
jne 0x6e093
movq 0x70(%rbp), %rdi
callq 0xf6bea
testl %eax, %eax
movq %r15, 0x28(%rsp)
je 0x6e0c9
movq 0x58(%rbp), %rdi
movq 0x68(%rbp), %rsi
callq 0xf6969
jmp 0x6e103
orb $0x1, 0x78(%rbp)
movq 0x58(%rbp), %rdi
movq 0x70(%rbp), %rsi
callq 0xf6969
movq 0x58(%rbp), %rdi
movl $0x1, %esi
callq 0xfdb50
movq 0x68(%rbp), %rdi
callq 0xf6bea
movq 0x58(%rbp), %rdi
testl %eax, %eax
je 0x6e0be
movl $0x5f, %esi
callq 0xf69a2
cmpb $0x22, %r12b
jb 0x6e17e
cmpq $0x0, 0x30(%r14)
jne 0x6e121
movq %rbx, %rdi
movl $0x21, %esi
callq 0xeba56
movq %rax, 0x30(%r14)
movq 0x30(%r14), %rdi
callq 0xebdc3
movq 0x30(%r14), %rdi
movq 0x18(%rbx), %rsi
movq 0x30(%rbp), %rcx
movq 0x40(%rbp), %rdx
callq 0xebf09
movq 0x30(%r14), %rdi
callq 0xebe2a
movl %eax, %r15d
movq %rbx, %rdi
leaq 0xb7d00(%rip), %rsi     # 0x125e55
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
cmpl 0x18(%rsp), %r15d
je 0x6e17e
movq %rbx, %rdi
leaq 0xb7d0d(%rip), %rsi     # 0x125e7c
movq 0x18(%rsp), %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0xe9df7
cmpl $0x0, 0x5c(%r14)
je 0x6e19b
leaq 0x34cc(%rip), %rax      # 0x71658
movq %rax, 0xa8(%rbp)
movq %rbp, %rdi
callq 0xfdec1
movq 0x28(%rsp), %r15
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xfdab8
movq %r15, %rdi
callq 0xf6bb0
cmpl $0x0, 0x38(%r14)
movq 0x30(%rsp), %rcx
jne 0x6e1ec
addq %r12, 0x10(%rsp)
incq %r13
cmpq %rcx, %r13
jne 0x6ddc7
jmp 0x6e1ec
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movq %r14, %rsi
callq 0xfdb25
movl 0x24(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq