// File: /workspace/github_c_makefile_star2_O2/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 0x1607
movl %edi, %ebp
movq 0x8(%r15), %r12
leaq 0x1ba2(%rip), %rsi      # 0x312a
movq %r12, %rdi
callq 0x10b0
testl %eax, %eax
je 0x1607
movq 0x10(%r15), %rbx
leaq 0x1b90(%rip), %rsi      # 0x312f
movq %r12, %rdi
callq 0x10b0
xorl %r14d, %r14d
testl %eax, %eax
je 0x161d
leaq 0x1b7f(%rip), %rsi      # 0x3134
movq %r12, %rdi
callq 0x10b0
testl %eax, %eax
je 0x1621
leaq 0x1b74(%rip), %rsi      # 0x313c
movq %r12, %rdi
callq 0x10b0
testl %eax, %eax
je 0x16e6
leaq 0x1b65(%rip), %rsi      # 0x3144
movq %r12, %rdi
callq 0x10b0
testl %eax, %eax
jne 0x1779
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1130
cmpl $0x3, %ebp
jne 0x16f3
movq (%r15), %rdi
callq 0x14d2
pushq $0x1
popq %rbp
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
jmp 0x1623
pushq $0x2
popq %r12
leaq 0x1b3b(%rip), %rsi      # 0x3167
movq %rbx, %rdi
callq 0x1110
testq %rax, %rax
je 0x16ff
movq %rax, %r15
movq %rax, %rdi
callq 0x2b0b
leaq 0x4a75(%rip), %rax      # 0x60c4
leaq 0x4a72(%rip), %rcx      # 0x60c8
movl (%rcx), %ecx
orl (%rax), %ecx
je 0x1721
movq %r15, %rdi
callq 0x1894
movl %eax, %ebp
movq %r15, %rdi
callq 0x1080
testl %ebp, %ebp
je 0x1735
xorl %ebp, %ebp
leal -0x2(%r12), %eax
cmpl $0x2, %eax
jae 0x16b9
leaq 0x1af5(%rip), %rsi      # 0x3182
movq %rbx, %rdi
callq 0x1110
testq %rax, %rax
je 0x1757
movq %rax, %r15
movq %rax, %rdi
movl %r14d, %esi
callq 0x1261
movq %r15, %rdi
callq 0x1080
jmp 0x1612
cmpl $0x1, %r12d
je 0x1612
movq 0x492e(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1ad6(%rip), %rdi      # 0x31aa
pushq $0x18
popq %rsi
pushq $0x1
popq %rdx
callq 0x1140
pushq $0x5
jmp 0x1611
pushq $0x3
popq %r12
pushq $0x2
popq %r14
jmp 0x1625
movq %rax, %r14
movq 0x18(%r15), %rbx
jmp 0x1625
movq 0x48f2(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x1a5a(%rip), %rsi      # 0x316a
movq %rbx, %rdx
xorl %eax, %eax
callq 0x10c0
pushq $0x2
jmp 0x1611
leaq 0x1af0(%rip), %rdi      # 0x3218
callq 0x1060
movq %r15, %rdi
callq 0x1080
movq 0x48bc(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x1a7d(%rip), %rsi      # 0x31c3
movq %rbx, %rdx
xorl %eax, %eax
callq 0x10c0
pushq $0x3
jmp 0x1611
movq 0x489a(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x1a1e(%rip), %rsi      # 0x3186
movq %rbx, %rdx
xorl %eax, %eax
callq 0x10c0
pushq $0x4
jmp 0x1611
movq 0x4878(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x19c6(%rip), %rsi      # 0x3150
movq %r12, %rdx
xorl %eax, %eax
callq 0x10c0
jmp 0x1607
nopl (%rax)