// File: /workspace/github_c_makefile_star2_O0/miniupnp[P]hfsplustools/src/hfscommon.c
// Function: read_partition_map
void read_partition_map(FILE * f)
{
	unsigned char buffer[SECTOR_SIZE];
	unsigned int i = 0;
	unsigned int count = 0;
	uint16_t block_size = 0;
	uint32_t number_of_blocks = 0;

#if 0
	fseek(f, PARTITION_MAP_OFFSET, SEEK_SET);
#else
	/* read the Driver Descriptor */
	fseek(f, 0, SEEK_SET);
	fread(buffer, 1, sizeof(buffer), f);
	hexdump(buffer, 32, 0);
	if(readu16(buffer) != 0x4552) {	// signature
		printf("bad signature for Driver Descriptor block\n");
	} else {
		unsigned int i, desc_count;
		printf("=== Driver Descriptor Block ===\n");
		block_size = readu16(buffer + 2);
		number_of_blocks = readu32(buffer + 4);
		printf("%lu blocks of %hu bytes. %lu bytes total.\n",
		       (unsigned long)number_of_blocks, block_size, (unsigned long)number_of_blocks * block_size);
		printf("Type %04hx Identifier %04hx Data %08x\n",
		       readu16(buffer+8), readu16(buffer+10), readu32(buffer+12));
		desc_count = readu16(buffer+16);
		printf("%u descriptors%s\n", desc_count, (desc_count == 0) ? "." : " :");
		for (i = 0; i < desc_count; i++) {
			printf(" #%02u : start block %u, block count %u, OS=%04x\n",
			       i, readu32(buffer+18+i*8), readu16(buffer+20+i*8),
			       readu32(buffer+22+i*8));
		}
	}
#endif

	do {
		unsigned int start, size;
		unsigned int start_l, size_l;
		fread(buffer, 1, sizeof(buffer), f);
		hexdump(buffer, 136, 0);
		printf("=== partition %u ===\n", i);
		if(readu16(buffer) != 0x504D) {	// signature
			printf("bad signature\n");
			break;
		}
		count = readu32(buffer + 4);
		printf("total number of partitions = %u\n", count);
		start = readu32(buffer + 8);
		size = readu32(buffer + 12);
		printf("starting sector=%u (offset %08x) size %u (%u bytes)\n",
			start, start * SECTOR_SIZE, size, size * SECTOR_SIZE);
		start_l = readu32(buffer + 80);
		size_l = readu32(buffer + 84);
		printf("logical starting sector=%u (offset %08x) size %u (%u bytes)\n",
			start_l, start_l * SECTOR_SIZE, size_l, size_l * SECTOR_SIZE);
		printf(" name = '%s' type = '%s'\n", buffer + 16, buffer + 48);
		if(strcmp((char *)buffer + 48, "Apple_HFS") == 0) {
			printf("---\n");
			hfs_part_sector = start;
			hfs_part_sector_count = size;
		}
		i++;
	} while(i < count);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq %rdi, -0x8(%rbp)
movl $0x0, -0x214(%rbp)
movl $0x0, -0x218(%rbp)
movw $0x0, -0x21a(%rbp)
movl $0x0, -0x220(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x10f0
leaq -0x210(%rbp), %rdi
movq -0x8(%rbp), %rcx
movl $0x1, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x1060
leaq -0x210(%rbp), %rdi
movl $0x20, %esi
xorl %edx, %edx
callq 0x1970
leaq -0x210(%rbp), %rdi
callq 0x1ab0
movzwl %ax, %eax
cmpl $0x4552, %eax           # imm = 0x4552
je 0x36fb
leaq 0x1206(%rip), %rdi      # 0x48f5
movb $0x0, %al
callq 0x1080
jmp 0x38d6
leaq 0x121e(%rip), %rdi      # 0x4920
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0x2, %rdi
callq 0x1ab0
movw %ax, -0x21a(%rbp)
leaq -0x210(%rbp), %rdi
addq $0x4, %rdi
callq 0x1af0
movl %eax, -0x220(%rbp)
movl -0x220(%rbp), %eax
movl %eax, %esi
movzwl -0x21a(%rbp), %edx
movl -0x220(%rbp), %eax
movl %eax, %ecx
movzwl -0x21a(%rbp), %eax
imulq %rax, %rcx
leaq 0x11e2(%rip), %rdi      # 0x4941
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0x8, %rdi
callq 0x1ab0
movzwl %ax, %eax
movl %eax, -0x240(%rbp)
leaq -0x210(%rbp), %rdi
addq $0xa, %rdi
callq 0x1ab0
movzwl %ax, %eax
movl %eax, -0x23c(%rbp)
leaq -0x210(%rbp), %rdi
addq $0xc, %rdi
callq 0x1af0
movl -0x240(%rbp), %esi
movl -0x23c(%rbp), %edx
movl %eax, %ecx
leaq 0x11af(%rip), %rdi      # 0x496c
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0x10, %rdi
callq 0x1ab0
movzwl %ax, %eax
movl %eax, -0x228(%rbp)
movl -0x228(%rbp), %esi
movl -0x228(%rbp), %ecx
leaq 0x11b7(%rip), %rdx      # 0x49a7
leaq 0x11ae(%rip), %rax      # 0x49a5
cmpl $0x0, %ecx
cmoveq %rax, %rdx
leaq 0x118e(%rip), %rdi      # 0x4993
movb $0x0, %al
callq 0x1080
movl $0x0, -0x224(%rbp)
movl -0x224(%rbp), %eax
cmpl -0x228(%rbp), %eax
jae 0x38d4
movl -0x224(%rbp), %eax
movl %eax, -0x24c(%rbp)
leaq -0x210(%rbp), %rdi
addq $0x12, %rdi
movl -0x224(%rbp), %eax
shll $0x3, %eax
movl %eax, %eax
addq %rax, %rdi
callq 0x1af0
movl %eax, -0x248(%rbp)
leaq -0x210(%rbp), %rdi
addq $0x14, %rdi
movl -0x224(%rbp), %eax
shll $0x3, %eax
movl %eax, %eax
addq %rax, %rdi
callq 0x1ab0
movzwl %ax, %eax
movl %eax, -0x244(%rbp)
leaq -0x210(%rbp), %rdi
addq $0x16, %rdi
movl -0x224(%rbp), %eax
shll $0x3, %eax
movl %eax, %eax
addq %rax, %rdi
callq 0x1af0
movl -0x24c(%rbp), %esi
movl -0x248(%rbp), %edx
movl -0x244(%rbp), %ecx
movl %eax, %r8d
leaq 0x10f1(%rip), %rdi      # 0x49aa
movb $0x0, %al
callq 0x1080
movl -0x224(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x224(%rbp)
jmp 0x3816
jmp 0x38d6
jmp 0x38d8
leaq -0x210(%rbp), %rdi
movq -0x8(%rbp), %rcx
movl $0x1, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x1060
leaq -0x210(%rbp), %rdi
movl $0x88, %esi
xorl %edx, %edx
callq 0x1970
movl -0x214(%rbp), %esi
leaq 0x10ca(%rip), %rdi      # 0x49dc
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
callq 0x1ab0
movzwl %ax, %eax
cmpl $0x504d, %eax           # imm = 0x504D
je 0x3942
leaq 0x10bc(%rip), %rdi      # 0x49f2
movb $0x0, %al
callq 0x1080
jmp 0x3aa7
leaq -0x210(%rbp), %rdi
addq $0x4, %rdi
callq 0x1af0
movl %eax, -0x218(%rbp)
movl -0x218(%rbp), %esi
leaq 0x109c(%rip), %rdi      # 0x4a01
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0x8, %rdi
callq 0x1af0
movl %eax, -0x22c(%rbp)
leaq -0x210(%rbp), %rdi
addq $0xc, %rdi
callq 0x1af0
movl %eax, -0x230(%rbp)
movl -0x22c(%rbp), %esi
movl -0x22c(%rbp), %edx
shll $0x9, %edx
movl -0x230(%rbp), %ecx
movl -0x230(%rbp), %r8d
shll $0x9, %r8d
leaq 0x106b(%rip), %rdi      # 0x4a2a
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0x50, %rdi
callq 0x1af0
movl %eax, -0x234(%rbp)
leaq -0x210(%rbp), %rdi
addq $0x54, %rdi
callq 0x1af0
movl %eax, -0x238(%rbp)
movl -0x234(%rbp), %esi
movl -0x234(%rbp), %edx
shll $0x9, %edx
movl -0x238(%rbp), %ecx
movl -0x238(%rbp), %r8d
shll $0x9, %r8d
leaq 0x1009(%rip), %rdi      # 0x4a22
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rsi
addq $0x10, %rsi
leaq -0x210(%rbp), %rdx
addq $0x30, %rdx
leaq 0x1022(%rip), %rdi      # 0x4a5f
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0x30, %rdi
leaq 0x1023(%rip), %rsi      # 0x4a79
callq 0x10b0
cmpl $0x0, %eax
jne 0x3a86
leaq 0x101c(%rip), %rdi      # 0x4a83
movb $0x0, %al
callq 0x1080
movl -0x22c(%rbp), %eax
movl %eax, 0x3642(%rip)      # 0x70bc
movl -0x230(%rbp), %eax
movl %eax, 0x363a(%rip)      # 0x70c0
movl -0x214(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x214(%rbp)
movl -0x214(%rbp), %eax
cmpl -0x218(%rbp), %eax
jb 0x38d8
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq