// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
callq 0x17c220
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xd, %edx
callq 0x15e4a0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x8(%rbp), %rdi
leaq 0x1135a0(%rip), %rsi    # 0x1b177a
xorl %edx, %edx
callq 0x15cbc0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x5c(%rax)
movq -0x8(%rbp), %rdi
callq 0xa1220
cmpl $0x0, %eax
jne 0x9e20f
movq -0x8(%rbp), %rdi
leaq 0x113583(%rip), %rsi    # 0x1b1786
movb $0x0, %al
callq 0x15bfb0
jmp 0x9e3e6
movq -0x8(%rbp), %rdi
leaq 0x11357b(%rip), %rsi    # 0x1b1795
callq 0x15e380
movq -0x18(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
jne 0x9e23b
movq -0x8(%rbp), %rdi
leaq 0x11356d(%rip), %rsi    # 0x1b17a1
movb $0x0, %al
callq 0x15c0c0
movq -0x8(%rbp), %rdi
leaq 0x138fb3(%rip), %rsi    # 0x1d71f9
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
subq $0x1b, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
subq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq 0x11354a(%rip), %rsi    # 0x1b17f5
movb $0x0, %al
callq 0x15b0d0
cmpq $0x1b, -0x28(%rbp)
jl 0x9e2c0
cmpq $0x0, -0x20(%rbp)
jge 0x9e2cc
movl $0x1, -0x5c(%rbp)
jmp 0x9e3e6
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0x11351a(%rip), %rsi    # 0x1b180f
movb $0x0, %al
callq 0x15b0d0
cmpq $0x1e, -0x38(%rbp)
jge 0x9e30f
movl $0x1, -0x5c(%rbp)
jmp 0x9e3e6
movq -0x40(%rbp), %rax
addq $0xd, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x58(%rbp), %rsi
leaq 0x113500(%rip), %rdx    # 0x1b182a
movl $0x1, %ecx
leaq -0x40(%rbp), %r8
callq 0x17c580
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
leaq 0x1134e2(%rip), %rsi    # 0x1b1840
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
imulq -0x30(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jge 0x9e397
movl $0x1, -0x5c(%rbp)
jmp 0x9e3e6
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x9e3e4
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0xa1270
movq -0x18(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x9e3ca
jmp 0x9e3e6
movq -0x38(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x9e39f
jmp 0x9e3e6
cmpl $0x0, -0x5c(%rbp)
je 0x9e3fe
movq -0x8(%rbp), %rdi
leaq 0x113464(%rip), %rsi    # 0x1b185b
movb $0x0, %al
callq 0x15bfb0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x17c270
movq -0x8(%rbp), %rdi
movl -0x60(%rbp), %esi
callq 0x15b5a0
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)