// File: /workspace/github_c_makefile_star2_O1/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
movl (%rdi), %esi
bswapl %esi
leaq 0x15b7(%rip), %rdi      # 0x356f
xorl %eax, %eax
callq 0x1090
movl 0x4(%r14), %esi
bswapl %esi
leaq 0x15ad(%rip), %rdi      # 0x3579
xorl %eax, %eax
callq 0x1090
movzbl 0x8(%r14), %ebp
leaq 0x15a4(%rip), %rdi      # 0x3583
movl %ebp, %esi
xorl %eax, %eax
callq 0x1090
movzbl 0x9(%r14), %esi
leaq 0x1598(%rip), %rdi      # 0x358c
xorl %eax, %eax
callq 0x1090
movzwl 0xa(%r14), %r15d
rolw $0x8, %r15w
movzwl %r15w, %ebx
leaq 0x1587(%rip), %rdi      # 0x3597
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
leaq 0xe(%r14), %r13
testl %ebp, %ebp
je 0x2316
cmpl $0x1, %ebp
je 0x2181
cmpl $0xff, %ebp
jne 0x23ae
testw %r15w, %r15w
je 0x23be
leaq 0x1697(%rip), %r14      # 0x36e2
xorl %ebp, %ebp
movzwl (%r13), %eax
rolw $0x8, %ax
movzwl %ax, %r12d
movl 0x2(%r13), %r15d
bswapl %r15d
movq %r14, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x6(%r13), %rdi
callq 0x23dc
addq %r12, %r13
addq $0x2, %r13
movzwl (%r13), %eax
rolw $0x8, %ax
movzwl %ax, %esi
leal -0x3(%rsi), %ecx
cmpl $0x2, %ecx
jb 0x20bd
cmpl $0x2, %esi
je 0x213b
cmpl $0x1, %esi
jne 0x216e
leaq 0x1640(%rip), %rdi      # 0x36ea
movl %r15d, %esi
xorl %eax, %eax
callq 0x1090
addq $0x58, %r13
jmp 0x2153
cmpw $0x3, %ax
leaq 0x165d(%rip), %r12      # 0x3725
leaq 0x164f(%rip), %rax      # 0x371e
cmoveq %rax, %r12
leaq 0x1638(%rip), %rdi      # 0x3712
movq %r12, %rsi
xorl %eax, %eax
callq 0x1090
leaq 0x163f(%rip), %rdi      # 0x372a
movq %r12, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x1090
movl 0x4(%r13), %esi
bswapl %esi
leaq 0x8(%r13), %r15
leaq 0x15c5(%rip), %rdi      # 0x36ce
xorl %eax, %eax
callq 0x1090
movq %r15, %rdi
callq 0x23dc
movzbl 0x8(%r13), %eax
movzbl 0x9(%r13), %ecx
shll $0x9, %eax
leal (%rax,%rcx,2), %eax
addq %rax, %r13
addq $0xa, %r13
movl $0xa, %edi
callq 0x1040
jmp 0x2153
leaq 0x15bd(%rip), %rdi      # 0x36ff
movl %r15d, %esi
xorl %eax, %eax
callq 0x1090
addq $0xf8, %r13
movb $0x1, %r15b
testb %r15b, %r15b
je 0x230f
incl %ebp
cmpl %ebp, %ebx
jne 0x204d
jmp 0x23be
xorl %r15d, %r15d
leaq 0x15bb(%rip), %rdi      # 0x3733
xorl %eax, %eax
callq 0x1090
jmp 0x2156
movl 0x10(%r14), %esi
bswapl %esi
movl %esi, 0x3f4b(%rip)      # 0x60d8
movl 0x18(%r14), %eax
bswapl %eax
movl %eax, 0x3f43(%rip)      # 0x60dc
movl 0x1c(%r14), %eax
bswapl %eax
movl %eax, 0x3f3b(%rip)      # 0x60e0
leaq 0x13fa(%rip), %rdi      # 0x35a6
xorl %eax, %eax
callq 0x1090
movl 0x14(%r14), %esi
bswapl %esi
leaq 0x13f5(%rip), %rdi      # 0x35b5
xorl %eax, %eax
callq 0x1090
movl 0x3f0f(%rip), %esi      # 0x60dc
leaq 0x13f3(%rip), %rdi      # 0x35c7
xorl %eax, %eax
callq 0x1090
movl 0x3eff(%rip), %esi      # 0x60e0
leaq 0x13f3(%rip), %rdi      # 0x35db
xorl %eax, %eax
callq 0x1090
movzwl 0x20(%r14), %eax
rolw $0x8, %ax
movzwl %ax, %esi
movl %esi, 0x3ee3(%rip)      # 0x60e4
movl 0x24(%r14), %ebx
bswapl %ebx
leaq 0x13e0(%rip), %rdi      # 0x35ee
xorl %eax, %eax
callq 0x1090
movzwl 0x22(%r14), %eax
rolw $0x8, %ax
movzwl %ax, %esi
leaq 0x13d3(%rip), %rdi      # 0x35fb
xorl %eax, %eax
callq 0x1090
movl 0x3eaf(%rip), %edx      # 0x60e4
imull %ebx, %edx
leaq 0x13cd(%rip), %rdi      # 0x360c
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
movl 0x28(%r14), %esi
bswapl %esi
leaq 0x13d1(%rip), %rdi      # 0x3626
xorl %eax, %eax
callq 0x1090
movl 0x2e(%r14), %esi
bswapl %esi
leaq 0x13cb(%rip), %rdi      # 0x3634
xorl %eax, %eax
callq 0x1090
movzbl 0x32(%r14), %esi
leaq 0x13c6(%rip), %rdi      # 0x3642
xorl %eax, %eax
callq 0x1090
movzbl 0x33(%r14), %esi
leaq 0x13c1(%rip), %rdi      # 0x3650
xorl %eax, %eax
callq 0x1090
movl 0x34(%r14), %esi
bswapl %esi
leaq 0x13c0(%rip), %rdi      # 0x3663
xorl %eax, %eax
callq 0x1090
movl 0x3e1c(%rip), %ebp      # 0x60cc
imull 0x3e1d(%rip), %ebp      # 0x60d4
imull 0x3e26(%rip), %ebx      # 0x60e4
cmpl %ebx, %ebp
jne 0x23d2
leaq 0x78(%r14), %r15
leaq 0x1812(%rip), %rdi      # 0x3ae3
callq 0x1060
movq %r15, %rdi
movl $0x80, %esi
xorl %edx, %edx
callq 0x19e8
addq $0xf8, %r14
leaq 0x1804(%rip), %rdi      # 0x3af7
callq 0x1060
movq %r14, %rdi
movl $0x80, %esi
xorl %edx, %edx
callq 0x19e8
cmpl %ebx, %ebp
je 0x23be
xorl %eax, %eax
jmp 0x23c3
testw %r15w, %r15w
je 0x23be
xorl %r14d, %r14d
movzwl (%r13), %eax
rolw $0x8, %ax
movzwl %ax, %r12d
leaq (%r12,%r13), %rbp
addq $0x6, %rbp
movl -0x4(%rbp), %r15d
bswapl %r15d
leaq 0x1372(%rip), %rdi      # 0x36b8
movl %r14d, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1366(%rip), %rdi      # 0x36bd
movl %r12d, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1360(%rip), %rdi      # 0x36c8
xorl %eax, %eax
callq 0x1090
leaq 0x6(%r13), %rdi
callq 0x23dc
movl 0x2(%r13), %esi
bswapl %esi
leaq 0x1348(%rip), %rdi      # 0x36cd
xorl %eax, %eax
callq 0x1090
leaq 0x1348(%rip), %rdi      # 0x36db
movl %r15d, %esi
xorl %eax, %eax
callq 0x1090
incl %r14d
movq %rbp, %r13
cmpl %r14d, %ebx
jne 0x2323
jmp 0x23be
leaq 0x139e(%rip), %rdi      # 0x3753
movl %ebp, %esi
xorl %eax, %eax
callq 0x1090
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1377
jmp 0x2307