// File: /workspace/github_c_makefile_star2_O0/miniupnp[P]hfsplustools/src/hfscommon.c
// Function: read_hfs_volume_header
int read_hfs_volume_header (FILE * f)
{
	unsigned char buffer[512];
	unsigned char a_buffer[512];
	uint32_t attributes;
	int i;
	uint32_t bsize;
	uint32_t bcount;

	if(fseek(f, hfs_part_sector * SECTOR_SIZE + HFS_VOLUME_HEADER_OFFSET, SEEK_SET) != 0) {
		perror("fseek");
		return 0;
	}
	if(fread(buffer, 1, sizeof(buffer), f) != sizeof(buffer)) {
		fprintf(stderr, "reading error\n");
		return 0;
	}
	printf("VOLUME HEADER (offset %08x)\n",
		hfs_part_sector * SECTOR_SIZE + HFS_VOLUME_HEADER_OFFSET);
	printf("SIGNATURE %c%c version %02x%02x (4=HFS+ 5=HFSX)\n",
	       buffer[0], buffer[1], buffer[2], buffer[3]);
	if(buffer[0] != 'H' || buffer[1] != '+') {
		printf("Not HFS+\n");
		return 0;
	}
	if(fseek(f, (hfs_part_sector + hfs_part_sector_count) * SECTOR_SIZE - HFS_VOLUME_HEADER_OFFSET, SEEK_SET) != 0) {
		perror("fseek");
		return 0;
	}
	if(fread(a_buffer, 1, sizeof(a_buffer), f) != sizeof(a_buffer)) {
		fprintf(stderr, "reading error\n");
		return 0;
	}
	printf("ALTERNATE VOLUME HEADER (offset %08x)\n",
		(hfs_part_sector + hfs_part_sector_count) * SECTOR_SIZE - HFS_VOLUME_HEADER_OFFSET);
	if(memcmp(buffer, a_buffer, sizeof(buffer)) != 0) {
		printf("WARNING: main and alternate Volume Headers differ\n");
		if(memcmp(buffer, a_buffer, 20) != 0) {
			fprintf(stderr, "ERROR: first 20 bytes of main and alternate Volume Headers differ\n");
			printf("Main:\n");
			hexdump(buffer, 32, 0);
			printf("Alternate:\n");
			hexdump(a_buffer, 32, 0);
			return 0;
		}
	}
	hexdump(buffer, 128, 0);
	attributes = readu32(buffer + 4);
	printf("attributes = %08x ", attributes);
	if(attributes&(1<<8)) printf("|kHFSVolumeUnmountedBit");
	if(attributes&(1<<9)) printf("|kHFSVolumeSparedBlocksBit");
	if(attributes&(1<<10)) printf("|kHFSVolumeNoCacheRequiredBit");
	if(attributes&(1<<11)) printf("|kHFSBootVolumeInconsistentBit");
	if(attributes&(1<<12)) printf("|kHFSCatalogNodeIDsReusedBit");
	if(attributes&(1<<13)) printf("|kHFSVolumeJournaledBit");
	if(attributes&(1<<15)) printf("|kHFSVolumeSoftwareLockBit");
	printf("\nlast mounted version '%c%c%c%c', ", buffer[8], buffer[9], buffer[10], buffer[11]);
	printf("journalInfoBlock %08x\n", readu32(buffer + 12));
	printf("createDate %08x, ", readu32(buffer + 16));
	printf("modifyDate %08x\n", readu32(buffer + 20));
	printf("backupDate %08x, ", readu32(buffer + 24));
	printf("checkedDate %08x\n", readu32(buffer + 28));
	printf("file count %u, ", readu32(buffer + 32));
	printf("folder count %u\n", readu32(buffer + 36));
	bsize = readu32(buffer + 40);
	block_size = bsize;
	bcount = readu32(buffer + 44);
	printf("block size %u, ", bsize);
	printf("total blocks %u (total %u bytes)\n",
		bcount, bsize * bcount);
	if(bsize * bcount != hfs_part_sector_count * SECTOR_SIZE)
		fprintf(stderr, "*** Partion size inconsistency with Partition Map ***\n");
	printf("free blocks %u, ", readu32(buffer + 48));
	printf("next catalog id %u\n", readu32(buffer + 64));
	for(i = 0; i < 8; i++) {
		printf("finderInfo[%d] = %08x", i, readu32(buffer + 80 + i * 4));
		if(i==2) printf(" directory ID auto Finder display");
		putchar('\n');
	}
	/* 80 + 8*4 = 112 */
	/* struct HFSPlusForkData {
    UInt64                  logicalSize;
    UInt32                  clumpSize;
    UInt32                  totalBlocks;
    HFSPlusExtentRecord     extents;
};
	8 + 4 + 4 + 8 * 8 = 16 + 64 = 80
	typedef HFSPlusExtentDescriptor HFSPlusExtentRecord[8];
	struct HFSPlusExtentDescriptor {
    UInt32                  startBlock;
    UInt32                  blockCount;
};
 */
	/* HFSPlusForkData     allocationFile;
    HFSPlusForkData     extentsFile;
    HFSPlusForkData     catalogFile;
    HFSPlusForkData     attributesFile;
    HFSPlusForkData     startupFile;*/
	printf("catalogFile:\n");
	//hexdump(buffer+112+80*2, 80, 0);
	catalog_start_block = readu32(buffer+112+80*2+16);
	catalog_block_count = readu32(buffer+112+80*2+20);
	printf("  startBlock = %08x (%u)", catalog_start_block, catalog_start_block);
	printf("\toffset 0x%08x\n", catalog_start_block * block_size);
	printf("  blockCount = %08x (%u)", catalog_block_count, catalog_block_count);
	printf("\tsize = %u bytes\n", catalog_block_count * block_size);
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x430, %rsp            # imm = 0x430
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movl 0x5573(%rip), %eax      # 0x70bc
shll $0x9, %eax
addl $0x400, %eax            # imm = 0x400
movl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x10f0
cmpl $0x0, %eax
je 0x1b79
leaq 0x249c(%rip), %rdi      # 0x4004
callq 0x1110
movl $0x0, -0x4(%rbp)
jmp 0x21d5
leaq -0x210(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x1, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x1060
cmpq $0x200, %rax            # imm = 0x200
je 0x1bbf
movq 0x5456(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x245e(%rip), %rsi      # 0x400a
movb $0x0, %al
callq 0x10c0
movl $0x0, -0x4(%rbp)
jmp 0x21d5
movl 0x54f7(%rip), %esi      # 0x70bc
shll $0x9, %esi
addl $0x400, %esi            # imm = 0x400
leaq 0x26af(%rip), %rdi      # 0x4284
movb $0x0, %al
callq 0x1080
movzbl -0x210(%rbp), %esi
movzbl -0x20f(%rbp), %edx
movzbl -0x20e(%rbp), %ecx
movzbl -0x20d(%rbp), %r8d
leaq 0x2649(%rip), %rdi      # 0x4249
movb $0x0, %al
callq 0x1080
movzbl -0x210(%rbp), %eax
cmpl $0x48, %eax
jne 0x1c1f
movzbl -0x20f(%rbp), %eax
cmpl $0x2b, %eax
je 0x1c39
leaq 0x2403(%rip), %rdi      # 0x4029
movb $0x0, %al
callq 0x1080
movl $0x0, -0x4(%rbp)
jmp 0x21d5
movq -0x10(%rbp), %rdi
movl 0x5479(%rip), %eax      # 0x70bc
addl 0x5477(%rip), %eax      # 0x70c0
shll $0x9, %eax
subl $0x400, %eax            # imm = 0x400
movl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x10f0
cmpl $0x0, %eax
je 0x1c79
leaq 0x239c(%rip), %rdi      # 0x4004
callq 0x1110
movl $0x0, -0x4(%rbp)
jmp 0x21d5
leaq -0x410(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x1, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x1060
cmpq $0x200, %rax            # imm = 0x200
je 0x1cbf
movq 0x5356(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x235e(%rip), %rsi      # 0x400a
movb $0x0, %al
callq 0x10c0
movl $0x0, -0x4(%rbp)
jmp 0x21d5
movl 0x53f7(%rip), %esi      # 0x70bc
addl 0x53f5(%rip), %esi      # 0x70c0
shll $0x9, %esi
subl $0x400, %esi            # imm = 0x400
leaq 0x259f(%rip), %rdi      # 0x427a
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
leaq -0x410(%rbp), %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x10a0
cmpl $0x0, %eax
je 0x1d96
leaq 0x2597(%rip), %rdi      # 0x42a1
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
leaq -0x410(%rbp), %rsi
movl $0x14, %edx
callq 0x10a0
cmpl $0x0, %eax
je 0x1d94
movq 0x52c3(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2595(%rip), %rsi      # 0x42d4
movb $0x0, %al
callq 0x10c0
leaq 0x25ca(%rip), %rdi      # 0x4317
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
movl $0x20, %esi
xorl %edx, %edx
callq 0x1970
leaq 0x25b0(%rip), %rdi      # 0x431e
movb $0x0, %al
callq 0x1080
leaq -0x410(%rbp), %rdi
movl $0x20, %esi
xorl %edx, %edx
callq 0x1970
movl $0x0, -0x4(%rbp)
jmp 0x21d5
jmp 0x1d96
leaq -0x210(%rbp), %rdi
movl $0x80, %esi
xorl %edx, %edx
callq 0x1970
leaq -0x210(%rbp), %rdi
addq $0x4, %rdi
callq 0x1af0
movl %eax, -0x414(%rbp)
movl -0x414(%rbp), %esi
leaq 0x255e(%rip), %rdi      # 0x432a
movb $0x0, %al
callq 0x1080
movl -0x414(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x1df1
leaq 0x2553(%rip), %rdi      # 0x433d
movb $0x0, %al
callq 0x1080
movl -0x414(%rbp), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x1e0f
leaq 0x254d(%rip), %rdi      # 0x4355
movb $0x0, %al
callq 0x1080
movl -0x414(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x1e2d
leaq 0x254a(%rip), %rdi      # 0x4370
movb $0x0, %al
callq 0x1080
movl -0x414(%rbp), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x1e4b
leaq 0x254a(%rip), %rdi      # 0x438e
movb $0x0, %al
callq 0x1080
movl -0x414(%rbp), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0x1e69
leaq 0x254b(%rip), %rdi      # 0x43ad
movb $0x0, %al
callq 0x1080
movl -0x414(%rbp), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x1e87
leaq 0x254a(%rip), %rdi      # 0x43ca
movb $0x0, %al
callq 0x1080
movl -0x414(%rbp), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x1ea5
leaq 0x2544(%rip), %rdi      # 0x43e2
movb $0x0, %al
callq 0x1080
movzbl -0x208(%rbp), %esi
movzbl -0x207(%rbp), %edx
movzbl -0x206(%rbp), %ecx
movzbl -0x205(%rbp), %r8d
leaq 0x2534(%rip), %rdi      # 0x43fd
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0xc, %rdi
callq 0x1af0
movl %eax, %esi
leaq 0x2537(%rip), %rdi      # 0x4420
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0x10, %rdi
callq 0x1af0
movl %eax, %esi
leaq 0x252e(%rip), %rdi      # 0x4437
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0x14, %rdi
callq 0x1af0
movl %eax, %esi
leaq 0x2520(%rip), %rdi      # 0x4449
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0x18, %rdi
callq 0x1af0
movl %eax, %esi
leaq 0x2511(%rip), %rdi      # 0x445a
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0x1c, %rdi
callq 0x1af0
movl %eax, %esi
leaq 0x2503(%rip), %rdi      # 0x446c
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0x20, %rdi
callq 0x1af0
movl %eax, %esi
leaq 0x24f5(%rip), %rdi      # 0x447e
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0x24, %rdi
callq 0x1af0
movl %eax, %esi
leaq 0x24e5(%rip), %rdi      # 0x448e
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0x28, %rdi
callq 0x1af0
movl %eax, -0x41c(%rbp)
movl -0x41c(%rbp), %eax
movl %eax, 0x50f2(%rip)      # 0x70c4
leaq -0x210(%rbp), %rdi
addq $0x2c, %rdi
callq 0x1af0
movl %eax, -0x420(%rbp)
movl -0x41c(%rbp), %esi
leaq 0x24aa(%rip), %rdi      # 0x449f
movb $0x0, %al
callq 0x1080
movl -0x420(%rbp), %esi
movl -0x41c(%rbp), %edx
imull -0x420(%rbp), %edx
leaq 0x2499(%rip), %rdi      # 0x44af
movb $0x0, %al
callq 0x1080
movl -0x41c(%rbp), %eax
imull -0x420(%rbp), %eax
movl 0x5090(%rip), %ecx      # 0x70c0
shll $0x9, %ecx
cmpl %ecx, %eax
je 0x204f
movq 0x4fba(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2489(%rip), %rsi      # 0x44d1
movb $0x0, %al
callq 0x10c0
leaq -0x210(%rbp), %rdi
addq $0x30, %rdi
callq 0x1af0
movl %eax, %esi
leaq 0x24a0(%rip), %rdi      # 0x4508
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0x40, %rdi
callq 0x1af0
movl %eax, %esi
leaq 0x2491(%rip), %rdi      # 0x4519
movb $0x0, %al
callq 0x1080
movl $0x0, -0x418(%rbp)
cmpl $0x8, -0x418(%rbp)
jge 0x2114
movl -0x418(%rbp), %eax
movl %eax, -0x424(%rbp)
leaq -0x210(%rbp), %rdi
addq $0x50, %rdi
movl -0x418(%rbp), %eax
shll $0x2, %eax
cltq
addq %rax, %rdi
callq 0x1af0
movl -0x424(%rbp), %esi
movl %eax, %edx
leaq 0x2452(%rip), %rdi      # 0x452d
movb $0x0, %al
callq 0x1080
cmpl $0x2, -0x418(%rbp)
jne 0x20f9
leaq 0x2451(%rip), %rdi      # 0x4543
movb $0x0, %al
callq 0x1080
movl $0xa, %edi
callq 0x1040
movl -0x418(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x418(%rbp)
jmp 0x2099
leaq 0x244a(%rip), %rdi      # 0x4565
movb $0x0, %al
callq 0x1080
leaq -0x210(%rbp), %rdi
addq $0x70, %rdi
addq $0xa0, %rdi
addq $0x10, %rdi
callq 0x1af0
movl %eax, 0x4f85(%rip)      # 0x70c8
leaq -0x210(%rbp), %rdi
addq $0x70, %rdi
addq $0xa0, %rdi
addq $0x14, %rdi
callq 0x1af0
movl %eax, 0x4f68(%rip)      # 0x70cc
movl 0x4f5e(%rip), %esi      # 0x70c8
movl 0x4f58(%rip), %edx      # 0x70c8
leaq 0x23fc(%rip), %rdi      # 0x4573
movb $0x0, %al
callq 0x1080
movl 0x4f44(%rip), %esi      # 0x70c8
imull 0x4f39(%rip), %esi      # 0x70c4
leaq 0x23fa(%rip), %rdi      # 0x458c
movb $0x0, %al
callq 0x1080
movl 0x4f2d(%rip), %esi      # 0x70cc
movl 0x4f27(%rip), %edx      # 0x70cc
leaq 0x23f0(%rip), %rdi      # 0x459c
movb $0x0, %al
callq 0x1080
movl 0x4f13(%rip), %esi      # 0x70cc
imull 0x4f04(%rip), %esi      # 0x70c4
leaq 0x23ee(%rip), %rdi      # 0x45b5
movb $0x0, %al
callq 0x1080
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x430, %rsp            # imm = 0x430
popq %rbp
retq
nopw %cs:(%rax,%rax)