// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/macpaint.c
// Function: do_macbinary
static void do_macbinary(deark *c, lctx *d)
{
	u8 b0, b1;
	de_module_params *mparams = NULL;

	b0 = de_getbyte(0);
	b1 = de_getbyte(1);

	// Instead of a real MacBinary header, a few macpaint files just have
	// 128 NUL bytes, or something like that. So we'll skip MacBinary parsing
	// in some cases.
	if(b0!=0) goto done;
	if(b1<1 || b1>63) goto done;

	de_dbg(c, "MacBinary header");
	de_dbg_indent(c, 1);
	mparams = de_malloc(c, sizeof(de_module_params));
	mparams->in_params.codes = "D"; // = decode only, don't extract
	mparams->out_params.fi = de_finfo_create(c); // A temporary finfo object
	mparams->out_params.fi->name_other = ucstring_create(c);
	de_run_module_by_id_on_slice(c, "macbinary", mparams, c->infile, 0, c->infile->len);
	de_dbg_indent(c, -1);

	if(mparams->out_params.uint1>0) {
		d->df_known = 1;
		d->expected_dfpos = (i64)mparams->out_params.uint1;
		d->expected_dflen = (i64)mparams->out_params.uint2;
	}
	if(mparams->out_params.uint3>0) {
		d->rf_known = 1;
		d->expected_rfpos = (i64)mparams->out_params.uint3;
		d->expected_rflen = (i64)mparams->out_params.uint4;
	}

	if(mparams->out_params.fi->timestamp[DE_TIMESTAMPIDX_MODIFY].is_valid) {
		d->mod_time_from_macbinary = mparams->out_params.fi->timestamp[DE_TIMESTAMPIDX_MODIFY];
	}

	if(d->df_known) {
		if(d->expected_dfpos+d->expected_dflen>c->infile->len) {
			de_warn(c, "MacBinary data fork (ends at %"I64_FMT") "
				"goes past end of file (%"I64_FMT")",
			d->expected_dfpos+d->expected_dflen, c->infile->len);
			d->df_known = 0;
		}
	}

	if(ucstring_isnonempty(mparams->out_params.fi->name_other) && !d->filename) {
		d->filename = ucstring_clone(mparams->out_params.fi->name_other);
	}

	if(d->rf_known) {
		do_decode_rsrc(c, d);
	}

done:
	if(mparams) {
		de_finfo_destroy(c, mparams->out_params.fi);
		de_free(c, mparams);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x165060
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x1, %esi
callq 0x165060
movb %al, -0x12(%rbp)
movzbl -0x11(%rbp), %eax
cmpl $0x0, %eax
je 0xd937f
jmp 0xd958e
movzbl -0x12(%rbp), %eax
cmpl $0x1, %eax
jl 0xd9391
movzbl -0x12(%rbp), %eax
cmpl $0x3f, %eax
jle 0xd9396
jmp 0xd958e
movq -0x8(%rbp), %rdi
leaq 0xe251c(%rip), %rsi     # 0x1bb8bd
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movl $0x70, %esi
callq 0x15b780
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
leaq 0xfe65a(%rip), %rcx     # 0x1d7a2d
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rax
movq %rcx, 0x90(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %r9
leaq 0xe2078(%rip), %rsi     # 0x1bb4a0
xorl %eax, %eax
movl %eax, %r8d
callq 0x15c9f0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x20(%rbp), %rax
cmpl $0x0, 0x44(%rax)
jbe 0xd9474
movq -0x10(%rbp), %rax
movb $0x1, 0x5(%rax)
movq -0x20(%rbp), %rax
movl 0x44(%rax), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movl 0x48(%rax), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x4c(%rax)
jbe 0xd94a8
movq -0x10(%rbp), %rax
movb $0x1, 0x6(%rax)
movq -0x20(%rbp), %rax
movl 0x4c(%rax), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rax
cmpb $0x0, 0x18(%rax)
je 0xd94d2
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x60(%rcx), %rcx
movq 0x18(%rcx), %rdx
movq %rdx, 0x30(%rax)
movq 0x20(%rcx), %rcx
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x5(%rax)
je 0xd9532
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
addq 0x18(%rcx), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xd9530
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x10(%rbp), %rax
addq 0x18(%rax), %rdx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rcx
leaq 0xe218b(%rip), %rsi     # 0x1bb6ac
movb $0x0, %al
callq 0x15bc10
movq -0x10(%rbp), %rax
movb $0x0, 0x5(%rax)
jmp 0xd9532
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rax
movq 0x90(%rax), %rdi
callq 0x1717f0
cmpl $0x0, %eax
je 0xd9575
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0xd9575
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rax
movq 0x90(%rax), %rdi
callq 0x171700
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x6(%rax)
je 0xd958c
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xd9d10
jmp 0xd958e
cmpq $0x0, -0x20(%rbp)
je 0xd95b3
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rsi
callq 0x15d260
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15b820
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)