// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/nufx.c
// Function: extract_main_threads
static void extract_main_threads(deark *c, struct nufx_ctx *d,
	struct nufx_record *rec, u8 disk_image_flag)
{
	struct de_advfile *advf = NULL;
	struct nufx_thread *t_d;
	struct nufx_thread *t_r;
	const char *dname;
	u32 d_crc_calc, r_crc_calc;
	u8 ok_cmpr;

	if(disk_image_flag) {
		dname = "disk image";
		t_d = rec->disk_image_thread_ptr;
		t_r = NULL;
	}
	else {
		dname = "data fork";
		t_d = rec->data_thread_ptr;
		t_r = rec->resource_thread_ptr;
	}

	if(!t_d && !t_r) {
		goto done;
	}

	ok_cmpr = 1;
	if(t_d) {
		if(t_d->orig_len>0 && !cmpr_meth_is_supported(t_d->cmpr_meth)) {
			ok_cmpr = 0;
		}
	}
	if(t_r) {
		if(t_r->orig_len>0 && !cmpr_meth_is_supported(t_r->cmpr_meth)) {
			ok_cmpr = 0;
		}
	}
	// Continue only if we're pretty sure we can decompress both forks.
	if(!ok_cmpr) {
		de_err(c, "record #%u: Compression method not supported", rec->idx);
		goto done;
	}

	advf = de_advfile_create(c);
	advf->userdata = (void*)rec;
	advf->writefork_cbfn = disk_image_flag ? my_advfile_cbfn_diskimage : my_advfile_cbfn;
	advf->enable_wbuffer = 1;

	advf->mainfork.fi->timestamp[DE_TIMESTAMPIDX_MODIFY] = rec->mod_time;
	advf->mainfork.fi->timestamp[DE_TIMESTAMPIDX_CREATE] = rec->create_time;

	ucstring_append_ucstring(advf->filename, rec->filename);
	advf->original_filename_flag = 1;
	advf->snflags |= DE_SNFLAG_FULLPATH;
	//de_advfile_set_orig_filename(rec->advf, ...); // TODO?

	if(t_d) {
		advf->mainfork.fork_exists = 1;
		advf->mainfork.fork_len = t_d->orig_len;
		advf->mainfork.writelistener_cb = de_writelistener_for_crc;
		advf->mainfork.userdata_for_writelistener = (void*)d->crco_dfork;
		de_crcobj_reset(d->crco_dfork);
	}
	if(t_r) {
		advf->rsrcfork.fork_exists = 1;
		advf->rsrcfork.fork_len = t_r->orig_len;
		advf->rsrcfork.writelistener_cb = de_writelistener_for_crc;
		advf->rsrcfork.userdata_for_writelistener = (void*)d->crco_rfork;
		de_crcobj_reset(d->crco_rfork);
	}

	de_advfile_run(advf);

	if(t_d && t_d->dcmpr_ok_flag && t_d->respect_crc_field) {
		d_crc_calc = de_crcobj_getval(d->crco_dfork);
		de_dbg(c, "%s crc (calculated): 0x%04x", dname, (UI)d_crc_calc);
		if(d_crc_calc!=t_d->crc_reported) {
			de_err(c, "CRC check failed for record #%u %s", rec->idx, dname);
		}
	}
	if(t_r && t_r->dcmpr_ok_flag && t_r->respect_crc_field) {
		r_crc_calc = de_crcobj_getval(d->crco_rfork);
		de_dbg(c, "rsrc fork crc (calculated): 0x%04x", (UI)r_crc_calc);
		if(r_crc_calc!=t_r->crc_reported) {
			de_err(c, "CRC check failed for record #%u resource fork", rec->idx);
		}
	}

done:
	de_advfile_destroy(advf);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb %al, -0x19(%rbp)
movq $0x0, -0x28(%rbp)
cmpb $0x0, -0x19(%rbp)
je 0xd78ab
leaq 0xd65c1(%rip), %rax     # 0x1ade4f
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0xc0(%rax), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
jmp 0xd78d4
leaq 0xcb049(%rip), %rax     # 0x1a28fb
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0xb0(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0xb8(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xd78e7
cmpq $0x0, -0x38(%rbp)
jne 0xd78e7
jmp 0xd7b8b
movb $0x1, -0x49(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xd7914
movq -0x30(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jle 0xd7912
movq -0x30(%rbp), %rax
movl 0x8(%rax), %edi
callq 0xd8a20
cmpl $0x0, %eax
jne 0xd7912
movb $0x0, -0x49(%rbp)
jmp 0xd7914
cmpq $0x0, -0x38(%rbp)
je 0xd793d
movq -0x38(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jle 0xd793b
movq -0x38(%rbp), %rax
movl 0x8(%rax), %edi
callq 0xd8a20
cmpl $0x0, %eax
jne 0xd793b
movb $0x0, -0x49(%rbp)
jmp 0xd793d
cmpb $0x0, -0x49(%rbp)
jne 0xd7961
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0xe3a66(%rip), %rsi     # 0x1bb3bb
movb $0x0, %al
callq 0x15bfb0
jmp 0xd7b8b
movq -0x8(%rbp), %rdi
callq 0x17aa20
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movzbl -0x19(%rbp), %edx
leaq 0x113b(%rip), %rcx      # 0xd8ac0
leaq 0x10c4(%rip), %rax      # 0xd8a50
cmpl $0x0, %edx
cmovneq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x28(%rbp), %rax
movb $0x1, 0x78(%rax)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x70(%rcx), %rdx
movq %rdx, 0x18(%rax)
movq 0x78(%rcx), %rcx
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x60(%rcx), %rdx
movq %rdx, 0x28(%rax)
movq 0x68(%rcx), %rcx
movq %rcx, 0x30(%rax)
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rsi
callq 0x171460
movq -0x28(%rbp), %rax
movb $0x1, 0x79(%rax)
movq -0x28(%rbp), %rax
movl 0x70(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x70(%rax)
cmpq $0x0, -0x30(%rbp)
je 0xd7a53
movq -0x28(%rbp), %rax
movb $0x1, 0x10(%rax)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rax
leaq 0x9189e(%rip), %rcx     # 0x1692d0
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x15f250
cmpq $0x0, -0x38(%rbp)
je 0xd7a9e
movq -0x28(%rbp), %rax
movb $0x1, 0x38(%rax)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x28(%rbp), %rax
leaq 0x91853(%rip), %rcx     # 0x1692d0
movq %rcx, 0x58(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x15f250
movq -0x28(%rbp), %rdi
callq 0x17ac20
cmpq $0x0, -0x30(%rbp)
je 0xd7b1c
movq -0x30(%rbp), %rax
movzbl 0x48(%rax), %eax
cmpl $0x0, %eax
je 0xd7b1c
movq -0x30(%rbp), %rax
movzbl 0x49(%rax), %eax
cmpl $0x0, %eax
je 0xd7b1c
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x15f340
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
movl -0x44(%rbp), %ecx
leaq 0xe38fe(%rip), %rsi     # 0x1bb3e8
movb $0x0, %al
callq 0x15b0d0
movl -0x44(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x10(%rcx), %eax
je 0xd7b1a
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x40(%rbp), %rcx
leaq 0xe38f1(%rip), %rsi     # 0x1bb404
movb $0x0, %al
callq 0x15bfb0
jmp 0xd7b1c
cmpq $0x0, -0x38(%rbp)
je 0xd7b89
movq -0x38(%rbp), %rax
movzbl 0x48(%rax), %eax
cmpl $0x0, %eax
je 0xd7b89
movq -0x38(%rbp), %rax
movzbl 0x49(%rax), %eax
cmpl $0x0, %eax
je 0xd7b89
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x15f340
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movl -0x48(%rbp), %edx
leaq 0xe38cc(%rip), %rsi     # 0x1bb427
movb $0x0, %al
callq 0x15b0d0
movl -0x48(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x10(%rcx), %eax
je 0xd7b87
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0xe38ca(%rip), %rsi     # 0x1bb44a
movb $0x0, %al
callq 0x15bfb0
jmp 0xd7b89
jmp 0xd7b8b
movq -0x28(%rbp), %rdi
callq 0x17aaa0
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)