// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/fmtutil-advfile.c
// Function: de_advfile_run
void de_advfile_run(struct de_advfile *advf)
{
	deark *c = advf->c;
	u8 has_mac_rfork;
	u8 extract_as_macfile;
	u8 has_mac_metadata;
	u8 try_to_keep_mac_metadata;
	int fmt;

	if(!c->macformat_known) {
		const char *mfmt;

		c->macformat_known = 1;
		c->macformat = DE_MACFORMAT_APPLEDOUBLE;

		// [I know there is a module named "macrsrc", so this could lead to confusion,
		// but I can't think of a better name.]
		mfmt = de_get_ext_option(c, "macrsrc");
		if(mfmt) {
			if(!de_strcmp(mfmt, "raw")) {
				c->macformat = DE_MACFORMAT_RAW; // Raw resource file
			}
			else if(!de_strcmp(mfmt, "as")) {
				c->macformat = DE_MACFORMAT_APPLESINGLE;
			}
			else if(!de_strcmp(mfmt, "ad")) {
				c->macformat = DE_MACFORMAT_APPLEDOUBLE;
			}
			else if(!de_strcmp(mfmt, "mbin")) {
				c->macformat = DE_MACFORMAT_MACBINARY;
			}
		}

		c->macmetaflag = (u8)de_get_ext_option_bool(c, "macmeta", 0);
	}

	// There's also finderflags, but I don't think it matters.
	has_mac_metadata = (advf->has_creatorcode || advf->has_typecode);

	has_mac_rfork = (advf->rsrcfork.fork_exists && advf->rsrcfork.fork_len>0);

	try_to_keep_mac_metadata = has_mac_rfork || (c->macmetaflag && has_mac_metadata);
	extract_as_macfile = has_mac_rfork || try_to_keep_mac_metadata;

	fmt = c->macformat; // Default to the default Mac format.

	// It's hard to decide what conversions to allow, and to account for all
	// combinations of options.
	// For now, we do allow some silly things, like MacBinary->MacBinary.
	// But we want to be careful when AppleDouble is the source format, since
	// (1) it doesn't contain the data fork (maybe it shouldn't even use
	// advfile), and (2) it's special because it's our standard format for
	// extracting resource forks.
	if(advf->originally_appledouble &&
		(fmt==DE_MACFORMAT_APPLEDOUBLE || fmt==DE_MACFORMAT_APPLESINGLE))
	{
		fmt = DE_MACFORMAT_RAW;
	}

	if(extract_as_macfile && fmt==DE_MACFORMAT_APPLESINGLE) {
		de_advfile_run_applesd(c, advf, 0);
	}
	else if(extract_as_macfile && fmt==DE_MACFORMAT_APPLEDOUBLE) {
		int extract_dfork = 0;
		int extract_rfork = 0;

		if(advf->mainfork.fork_exists && advf->mainfork.fork_len>0) {
			extract_dfork = 1;
		}
		if(advf->rsrcfork.fork_exists && advf->rsrcfork.fork_len>0) {
			extract_rfork = 1;
		}
		else if(try_to_keep_mac_metadata) {
			extract_rfork = 1;
		}
		if(!extract_dfork && !extract_rfork) {
			extract_dfork = 1;
		}

		if(extract_dfork) {
			de_advfile_run_rawfiles(c, advf, 1); // For the data/main fork
		}
		if(extract_rfork) {
			de_advfile_run_applesd(c, advf, 1); // For the rsrc fork
		}
	}
	else if(extract_as_macfile && fmt==DE_MACFORMAT_MACBINARY) {
		de_advfile_run_macbinary(c, advf);
	}
	else {
		de_advfile_run_rawfiles(c, advf, 0);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0xd1(%rax)
jne 0x17ad29
movq -0x10(%rbp), %rax
movb $0x1, 0xd1(%rax)
movq -0x10(%rbp), %rax
movb $0x2, 0xd2(%rax)
movq -0x10(%rbp), %rdi
leaq 0x27d7f(%rip), %rsi     # 0x1a29e8
callq 0x15cb30
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x17ad0b
movq -0x20(%rbp), %rdi
leaq 0x49250(%rip), %rsi     # 0x1c3ed8
callq 0x191a0
cmpl $0x0, %eax
jne 0x17ac9f
movq -0x10(%rbp), %rax
movb $0x0, 0xd2(%rax)
jmp 0x17ad09
movq -0x20(%rbp), %rdi
leaq 0x5bc29(%rip), %rsi     # 0x1d68d3
callq 0x191a0
cmpl $0x0, %eax
jne 0x17acc1
movq -0x10(%rbp), %rax
movb $0x1, 0xd2(%rax)
jmp 0x17ad07
movq -0x20(%rbp), %rdi
leaq 0x41518(%rip), %rsi     # 0x1bc1e4
callq 0x191a0
cmpl $0x0, %eax
jne 0x17ace3
movq -0x10(%rbp), %rax
movb $0x2, 0xd2(%rax)
jmp 0x17ad05
movq -0x20(%rbp), %rdi
leaq 0x5bbd2(%rip), %rsi     # 0x1d68c0
callq 0x191a0
cmpl $0x0, %eax
jne 0x17ad03
movq -0x10(%rbp), %rax
movb $0x3, 0xd2(%rax)
jmp 0x17ad05
jmp 0x17ad07
jmp 0x17ad09
jmp 0x17ad0b
movq -0x10(%rbp), %rdi
leaq 0x5bbaf(%rip), %rsi     # 0x1d68c5
xorl %edx, %edx
callq 0x15cbc0
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0xd3(%rax)
movq -0x8(%rbp), %rax
movzbl 0x7c(%rax), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x29(%rbp)
jne 0x17ad4c
movq -0x8(%rbp), %rax
movzbl 0x7b(%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x29(%rbp)
movb -0x29(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movb %al, -0x13(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x38(%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x2a(%rbp)
je 0x17ad78
movq -0x8(%rbp), %rax
cmpq $0x0, 0x40(%rax)
setg %al
movb %al, -0x2a(%rbp)
movb -0x2a(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movb %al, -0x11(%rbp)
movzbl -0x11(%rbp), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x2b(%rbp)
jne 0x17adb9
movq -0x10(%rbp), %rax
movzbl 0xd3(%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x2c(%rbp)
je 0x17adb3
movzbl -0x13(%rbp), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x2c(%rbp)
movb -0x2c(%rbp), %al
movb %al, -0x2b(%rbp)
movb -0x2b(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movb %al, -0x14(%rbp)
movzbl -0x11(%rbp), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x2d(%rbp)
jne 0x17addf
movzbl -0x14(%rbp), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x2d(%rbp)
movb -0x2d(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movb %al, -0x12(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xd2(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x7a(%rax), %eax
cmpl $0x0, %eax
je 0x17ae18
cmpl $0x2, -0x18(%rbp)
je 0x17ae11
cmpl $0x1, -0x18(%rbp)
jne 0x17ae18
movl $0x0, -0x18(%rbp)
movzbl -0x12(%rbp), %eax
cmpl $0x0, %eax
je 0x17ae3b
cmpl $0x1, -0x18(%rbp)
jne 0x17ae3b
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
xorl %edx, %edx
callq 0x17af30
jmp 0x17af25
movzbl -0x12(%rbp), %eax
cmpl $0x0, %eax
je 0x17aef4
cmpl $0x2, -0x18(%rbp)
jne 0x17aef4
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x0, %eax
je 0x17ae7f
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jle 0x17ae7f
movl $0x1, -0x24(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x0, %eax
je 0x17aea0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jle 0x17aea0
movl $0x1, -0x28(%rbp)
jmp 0x17aeaf
cmpb $0x0, -0x14(%rbp)
je 0x17aead
movl $0x1, -0x28(%rbp)
jmp 0x17aeaf
cmpl $0x0, -0x24(%rbp)
jne 0x17aec2
cmpl $0x0, -0x28(%rbp)
jne 0x17aec2
movl $0x1, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x17aeda
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl $0x1, %edx
callq 0x17b790
cmpl $0x0, -0x28(%rbp)
je 0x17aef2
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl $0x1, %edx
callq 0x17af30
jmp 0x17af23
movzbl -0x12(%rbp), %eax
cmpl $0x0, %eax
je 0x17af12
cmpl $0x3, -0x18(%rbp)
jne 0x17af12
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x17b9e0
jmp 0x17af21
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
xorl %edx, %edx
callq 0x17b790
jmp 0x17af23
jmp 0x17af25
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)