// File: /workspace/github_c_makefile_star2_O2/miniupnp[P]hfsplustools/src/hfscommon.c
// Function: print_node
int print_node(const unsigned char * p)
{
	uint16_t num_records;
	uint16_t rec;
	uint8_t kind;
	const unsigned char * q;
	/* node descriptor */
	printf("fLink=%u ", readu32(p));
	printf("bLink=%u ", readu32(p+4));
	kind = p[8];
	printf("kind=%u ", kind);
	 /* kBTLeafNode       = -1,
    kBTIndexNode      =  0,
    kBTHeaderNode     =  1,
    kBTMapNode        =  2 */
	printf("height=%u ", p[9]);
	num_records = readu16(p+10);
	printf("numRecords=%u\n", num_records);
	q = p + 14;
	if(kind == 1) { /* header node */
		unsigned totalNodes;
		/* 1st : B-Tree Header Record */
		catalog_root_node = readu32(q + 2);
		catalog_first_leaf_node = readu32(q + 10);
		catalog_last_leaf_node = readu32(q + 14);
		printf("rootNode = %u\n", catalog_root_node);
		printf("leafRecords = %u\n", readu32(q + 6));
		printf("firstLeafNode = %u\n", catalog_first_leaf_node);
		printf("lastLeafNode = %u\n", catalog_last_leaf_node);
		catalog_node_size = readu16(q + 18);
		totalNodes = readu32(q + 22);
		printf("nodeSize=%u\n", catalog_node_size);
		printf("maxKeyLength=%u\n", readu16(q + 20));
		printf("totalNodes=%u (%u bytes)\n",
		       totalNodes, totalNodes * catalog_node_size);
		printf("freeNodes=%u\n", readu32(q + 26));
		printf("clumpSize=%u\n", readu32(q + 32));
		printf("btreeType=%u\n", q[36]);
		printf("keyCompareType=%u\n", q[37]);
		printf("attributes %08X\n", readu32(q + 38));
		if(catalog_block_count * block_size != totalNodes * catalog_node_size) {
			fprintf(stderr, "ERROR catalog size inconsistency ! (at offset %d=0x%0x in catalog)\n", (int)(q + 22 - p), (int)(q + 22 - p));
			return 0;
		}
		q = q + 106;
		/* 2nd : User Data Record. 128 bytes */
		printf("User Data Record : \n");
		hexdump(q, 128, 0);
		q = q + 128;
		/* 3rd : B-tree Map Record. nodeSize - 256 bytes */
		printf("B-tree Map Record (first 128 bytes...) :\n");
		hexdump(q, 128 /*catalog_node_size - 256*/, 0);
	} else if(kind == 0) {	/* index node */
		for(rec = 0; rec < num_records; rec++) {
			/* record */
			uint16_t key_length = readu16(q);
			uint32_t node_number = readu32(q + key_length + 2);
			printf("%3u ", rec);
			printf("length=%u\n", key_length);
			//hexdump(q + 2, key_length, 0);
			printf("    ");
			print_hfs_uni(q + 6);
			printf(" parentId=%u ", readu32(q + 2));
			printf("=> %u\n", node_number);
			q += key_length + 2 + 4;
		}
	} else if(kind == 255) {	/* leaf node */
		for(rec = 0; rec < num_records; rec++) {
			uint16_t key_length = readu16(q);
			uint16_t record_type;
			uint32_t parent_id = readu32(q + 2);
			printf("  %2hu ", rec);
			print_hfs_uni(q + 6);
			q += key_length + 2;
			record_type = readu16(q);
			switch(record_type) {
			case 1: /* folder record */
				printf(" folder parentId=%u\n", parent_id);
				q += 88;
				break;
			case 2: /* file record */
				printf(" file parentId=%u\n", parent_id);
				q += 248;
				break;
			case 3:	/* folder thread record */
			case 4: /* file thread record */
				printf(" %s thread ", record_type == 3 ? "folder" : "file");
				printf("%sId=%u ", record_type == 3 ? "folder" : "file", parent_id);
				q += 4;
				parent_id = readu32(q);
				q += 4;
				printf("parentId=%u ", parent_id);
				print_hfs_uni(q);
				q += 2 * (1 + readu16(q));
				printf("\n");
				break;
			default:
				printf("\nrecord type %u not recognized\n", record_type);
				return 0;
			}
		}
	} else {
		printf("unprocessed kind %u\n", kind);
	}
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
callq 0x188f
leaq 0x17da(%rip), %rdi      # 0x356f
movl %eax, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x4(%r14), %rdi
callq 0x188f
leaq 0x17cb(%rip), %rdi      # 0x3579
movl %eax, %esi
xorl %eax, %eax
callq 0x1090
movzbl 0x8(%r14), %ebx
leaq 0x17c0(%rip), %rdi      # 0x3583
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
movzbl 0x9(%r14), %esi
leaq 0x17b4(%rip), %rdi      # 0x358c
xorl %eax, %eax
callq 0x1090
movzwl 0xa(%r14), %eax
rolw $0x8, %ax
movzwl %ax, %esi
leaq 0x17a5(%rip), %rdi      # 0x3597
movl %esi, 0x4(%rsp)
xorl %eax, %eax
callq 0x1090
leaq 0xe(%r14), %rbp
testl %ebx, %ebx
je 0x20fb
cmpl $0x1, %ebx
je 0x1f48
cmpl $0xff, %ebx
jne 0x2199
leaq 0x18bd(%rip), %r14      # 0x36e2
pushq $0xa
popq %rbx
xorl %r15d, %r15d
cmpl %r15d, 0x4(%rsp)
je 0x21a9
movzwl (%rbp), %eax
rolw $0x8, %ax
movzwl %ax, %r13d
leaq 0x2(%rbp), %rdi
callq 0x188f
movl %eax, %r12d
movq %r14, %rdi
movl %r15d, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x6(%rbp), %rdi
callq 0x21f0
addq %r13, %rbp
addq $0x2, %rbp
movzwl (%rbp), %eax
rolw $0x8, %ax
movzwl %ax, %esi
leal -0x3(%rsi), %ecx
cmpl $0x2, %ecx
jb 0x1eaa
cmpl $0x2, %esi
je 0x1f28
cmpl $0x1, %esi
jne 0x21bd
leaq 0x1853(%rip), %rdi      # 0x36ea
movl %r12d, %esi
xorl %eax, %eax
callq 0x1090
addq $0x58, %rbp
jmp 0x1f40
cmpw $0x3, %ax
leaq 0x1870(%rip), %r13      # 0x3725
leaq 0x1862(%rip), %rax      # 0x371e
cmoveq %rax, %r13
leaq 0x184b(%rip), %rdi      # 0x3712
movq %r13, %rsi
xorl %eax, %eax
callq 0x1090
leaq 0x1852(%rip), %rdi      # 0x372a
movq %r13, %rsi
movl %r12d, %edx
xorl %eax, %eax
callq 0x1090
leaq 0x4(%rbp), %rdi
callq 0x188f
leaq 0x8(%rbp), %r12
leaq 0x17d5(%rip), %rdi      # 0x36ce
movl %eax, %esi
xorl %eax, %eax
callq 0x1090
movq %r12, %rdi
callq 0x21f0
movzbl 0x8(%rbp), %eax
movzbl 0x9(%rbp), %ecx
shll $0x9, %eax
leal (%rax,%rcx,2), %eax
addq %rax, %rbp
addq $0xa, %rbp
movl %ebx, %edi
callq 0x1040
jmp 0x1f40
leaq 0x17d0(%rip), %rdi      # 0x36ff
movl %r12d, %esi
xorl %eax, %eax
callq 0x1090
addq $0xf8, %rbp
incl %r15d
jmp 0x1e2b
leaq 0x10(%r14), %rdi
callq 0x188f
movl %eax, %ebx
movl %eax, 0x417f(%rip)      # 0x60d8
leaq 0x18(%r14), %rdi
callq 0x188f
movl %eax, 0x4174(%rip)      # 0x60dc
leaq 0x1c(%r14), %rdi
callq 0x188f
movl %eax, 0x4169(%rip)      # 0x60e0
leaq 0x1628(%rip), %rdi      # 0x35a6
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x14(%r14), %rdi
callq 0x188f
leaq 0x161e(%rip), %rdi      # 0x35b5
movl %eax, %esi
xorl %eax, %eax
callq 0x1090
movl 0x4136(%rip), %esi      # 0x60dc
leaq 0x161a(%rip), %rdi      # 0x35c7
xorl %eax, %eax
callq 0x1090
movl 0x4126(%rip), %esi      # 0x60e0
leaq 0x161a(%rip), %rdi      # 0x35db
xorl %eax, %eax
callq 0x1090
movzwl 0x20(%r14), %eax
rolw $0x8, %ax
movzwl %ax, %ebp
movl %ebp, 0x410a(%rip)      # 0x60e4
leaq 0x24(%r14), %rdi
callq 0x188f
movl %eax, %ebx
leaq 0x1602(%rip), %rdi      # 0x35ee
movl %ebp, %esi
xorl %eax, %eax
callq 0x1090
movzwl 0x22(%r14), %eax
rolw $0x8, %ax
movzwl %ax, %esi
leaq 0x15f3(%rip), %rdi      # 0x35fb
xorl %eax, %eax
callq 0x1090
movl 0x40cf(%rip), %edx      # 0x60e4
imull %ebx, %edx
leaq 0x15ed(%rip), %rdi      # 0x360c
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x28(%r14), %rdi
callq 0x188f
leaq 0x15ee(%rip), %rdi      # 0x3626
movl %eax, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x2e(%r14), %rdi
callq 0x188f
leaq 0x15e3(%rip), %rdi      # 0x3634
movl %eax, %esi
xorl %eax, %eax
callq 0x1090
movzbl 0x32(%r14), %esi
leaq 0x15dc(%rip), %rdi      # 0x3642
xorl %eax, %eax
callq 0x1090
movzbl 0x33(%r14), %esi
leaq 0x15d7(%rip), %rdi      # 0x3650
xorl %eax, %eax
callq 0x1090
leaq 0x34(%r14), %rdi
callq 0x188f
leaq 0x15d3(%rip), %rdi      # 0x3663
movl %eax, %esi
xorl %eax, %eax
callq 0x1090
movl 0x402d(%rip), %eax      # 0x60cc
imull 0x402e(%rip), %eax      # 0x60d4
imull 0x4037(%rip), %ebx      # 0x60e4
cmpl %ebx, %eax
jne 0x21cf
leaq 0x78(%r14), %rbx
leaq 0x1a23(%rip), %rdi      # 0x3ae3
callq 0x1060
movq %rbx, %rdi
movl $0x80, %esi
xorl %edx, %edx
callq 0x179c
addq $0xf8, %r14
leaq 0x1a15(%rip), %rdi      # 0x3af7
callq 0x1060
movq %r14, %rdi
movl $0x80, %esi
xorl %edx, %edx
callq 0x179c
jmp 0x21a9
leaq 0x15cb(%rip), %r12      # 0x36cd
leaq 0x15d2(%rip), %r13      # 0x36db
xorl %ebx, %ebx
cmpl %ebx, 0x4(%rsp)
je 0x21a9
movzwl (%rbp), %eax
rolw $0x8, %ax
movzwl %ax, %r14d
leaq (%r14,%rbp), %rdi
addq $0x2, %rdi
callq 0x188f
movl %eax, %r15d
leaq 0x1580(%rip), %rdi      # 0x36b8
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1575(%rip), %rdi      # 0x36bd
movl %r14d, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x156f(%rip), %rdi      # 0x36c8
xorl %eax, %eax
callq 0x1090
leaq 0x6(%rbp), %rdi
callq 0x21f0
leaq 0x2(%rbp), %rdi
callq 0x188f
movq %r12, %rdi
movl %eax, %esi
xorl %eax, %eax
callq 0x1090
movq %r13, %rdi
movl %r15d, %esi
xorl %eax, %eax
callq 0x1090
addq %r14, %rbp
addq $0x6, %rbp
incl %ebx
jmp 0x210b
leaq 0x15b3(%rip), %rdi      # 0x3753
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x156f(%rip), %rdi      # 0x3733
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1090
jmp 0x21ac
movq 0x3e22(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x1494(%rip), %rsi      # 0x3674
pushq $0x24
popq %rcx
movl %ecx, %edx
xorl %eax, %eax
callq 0x10c0
xorl %ebx, %ebx
jmp 0x21ac