// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, %rdx
movq %rdi, %rbx
testl %ecx, %ecx
je 0x932de
leaq 0xc0(%r14), %rax
leaq 0x8f121(%rip), %rdi     # 0x1223fa
xorl %r13d, %r13d
jmp 0x932f3
leaq 0xb0(%r14), %rax
movq 0xb8(%r14), %r13
leaq 0x837ec(%rip), %rdi     # 0x116adf
movq (%rax), %r15
movq %r15, %rax
orq %r13, %rax
je 0x9331e
testq %r15, %r15
je 0x93326
cmpq $0x0, 0x20(%r15)
jle 0x93326
movl 0x8(%r15), %ecx
movb $0x1, %al
cmpl $0x3, %ecx
ja 0x93328
andb $0xf, %cl
movb $0x2, %al
shrb %cl, %al
jmp 0x93328
xorl %r12d, %r12d
jmp 0x934e5
xorl %eax, %eax
testq %r13, %r13
je 0x9334c
cmpq $0x0, 0x20(%r13)
jle 0x9334c
movl 0x8(%r13), %ecx
leaq 0x9c580(%rip), %rsi     # 0x12f8bf
xorl %r12d, %r12d
cmpl $0x3, %ecx
ja 0x9335a
cmpl $0x1, %ecx
je 0x9335a
testb $0x1, %al
je 0x9336d
leaq 0x9c568(%rip), %rsi     # 0x12f8bf
xorl %r12d, %r12d
movl 0x8(%r14), %edx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x934e5
movq %rdi, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq %rbx, %rdi
callq 0xfc498
movq %rax, %r12
testb %bpl, %bpl
leaq 0x297(%rip), %rax       # 0x93623
leaq 0x266(%rip), %rcx       # 0x935f9
cmoveq %rax, %rcx
movq %r14, 0x8(%r12)
movq %rcx, 0x60(%r12)
movb $0x1, %bpl
movb %bpl, 0x78(%r12)
movq 0x20(%r12), %rax
movups 0x70(%r14), %xmm0
movups %xmm0, 0x18(%rax)
movq 0x20(%r12), %rax
movups 0x60(%r14), %xmm0
movups %xmm0, 0x28(%rax)
movq 0x68(%r12), %rdi
movq 0x98(%r14), %rsi
callq 0xf6509
orb %bpl, 0x70(%r12)
movb %bpl, 0x79(%r12)
testq %r15, %r15
je 0x93413
movb $0x1, 0x10(%r12)
movq 0x20(%r15), %rax
movq %rax, 0x18(%r12)
leaq 0x5e056(%rip), %rax     # 0xf1451
movq %rax, 0x30(%r12)
movq 0x8(%rsp), %rax
movq 0x68(%rax), %rdi
movq %rdi, 0x28(%r12)
callq 0xeb7fe
testq %r13, %r13
je 0x93446
movb $0x1, 0x38(%r12)
movq 0x20(%r13), %rax
movq %rax, 0x40(%r12)
leaq 0x5e023(%rip), %rax     # 0xf1451
movq %rax, 0x58(%r12)
movq 0x8(%rsp), %rax
movq 0x60(%rax), %rdi
movq %rdi, 0x50(%r12)
callq 0xeb7fe
movq %r12, %rdi
callq 0xfc5b7
testq %r15, %r15
je 0x934a9
cmpb $0x0, 0x48(%r15)
je 0x934a9
cmpb $0x0, 0x49(%r15)
je 0x934a9
movq 0x8(%rsp), %rax
movq 0x68(%rax), %rdi
callq 0xeb865
movl %eax, %ebp
leaq 0x9c474(%rip), %rsi     # 0x12f8ec
movq %rbx, %rdi
movq 0x10(%rsp), %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0xe8617
cmpl 0x10(%r15), %ebp
je 0x934a9
movl 0x8(%r14), %edx
leaq 0x9c46e(%rip), %rsi     # 0x12f908
movq %rbx, %rdi
movq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0xe9295
testq %r13, %r13
je 0x934e5
cmpb $0x0, 0x48(%r13)
je 0x934e5
cmpb $0x0, 0x49(%r13)
je 0x934e5
movq 0x8(%rsp), %rax
movq 0x60(%rax), %rdi
callq 0xeb865
movl %eax, %ebp
leaq 0x9c458(%rip), %rsi     # 0x12f92b
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
cmpl 0x10(%r13), %ebp
jne 0x934fb
movq %r12, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xfc4de
leaq 0x9c44c(%rip), %rsi     # 0x12f94e
jmp 0x9335a