// File: /workspace/github_c_makefile_star2_O1/miniupnp[P]hfsplustools/src/hfspatchnoautofolder.c
// Function: main
int main(int argc, char * * argv)
{
	FILE * f;
	int ok = 0;
	const char * filename = NULL;
	enum command cmd = INVALID;
	uint32_t folderid = 0;

	if(argc < 3 || 0 == strcmp(argv[1], "help")) {
		usage(argv[0]);
		return 1;
	}
	filename = argv[2];
	if(strcmp(argv[1], "show") == 0) {
		cmd = SHOW;
	} else if(strcmp(argv[1], "disable") == 0) {
		cmd = DISABLE;
		folderid = 0;
	} else if(strcmp(argv[1], "setroot") == 0) {
		cmd = SETROOT;
		folderid = 2; /* ROOT folder */
	} else if(strcmp(argv[1], "setfolderid") == 0) {
		folderid = strtoul(argv[2], NULL, 0);
		if(argc < 4) {
			usage(argv[0]);
			return 1;
		}
		filename = argv[3];
	} else {
		fprintf(stderr, "unknown command '%s'\n\n", argv[1]);
		usage(argv[0]);
		return 1;
	}
	f = fopen(filename, "rb");
	if(!f) {
		fprintf(stderr, "Failed to open file %s\n", filename);
		return 2;
	}
	read_partition_map(f);
	if(hfs_part_sector == 0 && hfs_part_sector_count == 0) {
		printf("HFS/HFS+ partition not found\n");
	} else {
		ok = read_hfs_volume_header(f);
	}
	fclose(f);

	if(ok) {
		switch(cmd) {
		case DISABLE:
		case SETROOT:
		case SETID:
			f = fopen(filename, "r+b");
			if(!f) {
				fprintf(stderr, "Failed to open file %s for Writing\n", filename);
				return 4;
			}
			set_auto_folder(f, folderid);
			fclose(f);
			break;
		case SHOW:
			(void)0;
			break;
		default:
			fprintf(stderr, "*** INVALID COMMAND ***\n");
			return 5;
		}
	} else {
		fprintf(stderr, "Errors reading HFS+ volume from %s\n", filename);
		return 3;
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r15
cmpl $0x3, %edi
jl 0x1946
movl %edi, %ebp
movq 0x8(%r15), %r12
leaq 0x1935(%rip), %rsi      # 0x312a
movq %r12, %rdi
callq 0x10b0
testl %eax, %eax
je 0x1946
movq 0x10(%r15), %rbx
leaq 0x191f(%rip), %rsi      # 0x312f
movq %r12, %rdi
callq 0x10b0
xorl %r14d, %r14d
testl %eax, %eax
je 0x187d
leaq 0x190e(%rip), %rsi      # 0x3134
movq %r12, %rdi
callq 0x10b0
testl %eax, %eax
je 0x1885
leaq 0x1903(%rip), %rsi      # 0x313c
movq %r12, %rdi
callq 0x10b0
testl %eax, %eax
je 0x188d
leaq 0x18f8(%rip), %rsi      # 0x3144
movq %r12, %rdi
callq 0x10b0
testl %eax, %eax
jne 0x19d8
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1130
cmpl $0x3, %ebp
je 0x1946
movq %rax, %r14
movq 0x18(%r15), %rbx
jmp 0x1899
movl $0x1, %r12d
jmp 0x1899
movl $0x2, %r12d
jmp 0x1899
movl $0x2, %r14d
movl $0x3, %r12d
leaq 0x18c7(%rip), %rsi      # 0x3167
movq %rbx, %rdi
callq 0x1110
testq %rax, %rax
je 0x1955
movq %rax, %r15
movq %rax, %rdi
callq 0x2c47
leaq 0x4801(%rip), %rax      # 0x60c4
leaq 0x47fe(%rip), %rcx      # 0x60c8
movl (%rcx), %ecx
orl (%rax), %ecx
je 0x1977
movq %r15, %rdi
callq 0x1b18
movl %eax, %ebp
movq %r15, %rdi
callq 0x1080
testl %ebp, %ebp
je 0x198b
xorl %ebp, %ebp
leal -0x2(%r12), %eax
cmpl $0x2, %eax
jae 0x192d
leaq 0x1881(%rip), %rsi      # 0x3182
movq %rbx, %rdi
callq 0x1110
testq %rax, %rax
je 0x19ad
movq %rax, %r15
movq %rax, %rdi
movl %r14d, %esi
callq 0x1591
movq %r15, %rdi
callq 0x1080
jmp 0x19cd
cmpl $0x1, %r12d
je 0x19cd
callq 0x12a9
movl $0x5, %ebp
jmp 0x19cd
movq (%r15), %rdi
callq 0x1170
movl $0x1, %ebp
jmp 0x19cd
movq 0x469c(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x1804(%rip), %rsi      # 0x316a
movq %rbx, %rdx
xorl %eax, %eax
callq 0x10c0
movl $0x2, %ebp
jmp 0x19cd
leaq 0x189a(%rip), %rdi      # 0x3218
callq 0x1060
movq %r15, %rdi
callq 0x1080
movq 0x4666(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x1827(%rip), %rsi      # 0x31c3
movq %rbx, %rdx
xorl %eax, %eax
callq 0x10c0
movl $0x3, %ebp
jmp 0x19cd
movq 0x4644(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x17c8(%rip), %rsi      # 0x3186
movq %rbx, %rdx
xorl %eax, %eax
callq 0x10c0
movl $0x4, %ebp
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
movq %r15, %rsi
callq 0x1281
jmp 0x194e