// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x3, -0x8(%rbp)
jl 0x16d5
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x2a96(%rip), %rsi      # 0x415e
callq 0x10b0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x16ed
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x15d0
movl $0x1, -0x4(%rbp)
jmp 0x1964
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x2a5b(%rip), %rsi      # 0x4163
callq 0x10b0
cmpl $0x0, %eax
jne 0x171e
movl $0x1, -0x2c(%rbp)
jmp 0x180f
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x2a3b(%rip), %rsi      # 0x4168
callq 0x10b0
cmpl $0x0, %eax
jne 0x174a
movl $0x2, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
jmp 0x180d
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x2a17(%rip), %rsi      # 0x4170
callq 0x10b0
cmpl $0x0, %eax
jne 0x1776
movl $0x3, -0x2c(%rbp)
movl $0x2, -0x30(%rbp)
jmp 0x180b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x29f3(%rip), %rsi      # 0x4178
callq 0x10b0
cmpl $0x0, %eax
jne 0x17d1
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1120
movl %eax, -0x30(%rbp)
cmpl $0x4, -0x8(%rbp)
jge 0x17c3
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x15d0
movl $0x1, -0x4(%rbp)
jmp 0x1964
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x1809
movq 0x5820(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x299a(%rip), %rsi      # 0x4184
movb $0x0, %al
callq 0x10c0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x15d0
movl $0x1, -0x4(%rbp)
jmp 0x1964
jmp 0x180b
jmp 0x180d
jmp 0x180f
movq -0x28(%rbp), %rdi
leaq 0x2981(%rip), %rsi      # 0x419b
callq 0x1100
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x1852
movq 0x57c7(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x295f(%rip), %rsi      # 0x419e
movb $0x0, %al
callq 0x10c0
movl $0x2, -0x4(%rbp)
jmp 0x1964
movq -0x18(%rbp), %rdi
callq 0x3660
leaq 0x585a(%rip), %rax      # 0x70bc
cmpl $0x0, (%rax)
jne 0x1883
leaq 0x5852(%rip), %rax      # 0x70c0
cmpl $0x0, (%rax)
jne 0x1883
leaq 0x293c(%rip), %rdi      # 0x41b6
movb $0x0, %al
callq 0x1080
jmp 0x188f
movq -0x18(%rbp), %rdi
callq 0x1b30
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1070
cmpl $0x0, -0x1c(%rbp)
je 0x1938
movl -0x2c(%rbp), %eax
movl %eax, -0x34(%rbp)
subl $0x1, %eax
je 0x1913
jmp 0x18af
movl -0x34(%rbp), %eax
addl $-0x2, %eax
subl $0x2, %eax
ja 0x1915
jmp 0x18bc
movq -0x28(%rbp), %rdi
leaq 0x290d(%rip), %rsi      # 0x41d4
callq 0x1100
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x18fc
movq 0x571a(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x28ec(%rip), %rsi      # 0x41d8
movb $0x0, %al
callq 0x10c0
movl $0x4, -0x4(%rbp)
jmp 0x1964
movq -0x18(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x12b0
movq -0x18(%rbp), %rdi
callq 0x1070
jmp 0x1936
jmp 0x1936
movq 0x56dc(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x28d6(%rip), %rsi      # 0x41fc
movb $0x0, %al
callq 0x10c0
movl $0x5, -0x4(%rbp)
jmp 0x1964
jmp 0x195d
movq 0x56b9(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x28c8(%rip), %rsi      # 0x4215
movb $0x0, %al
callq 0x10c0
movl $0x3, -0x4(%rbp)
jmp 0x1964
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)