// File: /workspace/github_c_makefile_star2_O3/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 0x15c9(%rip), %rdi      # 0x356f
xorl %eax, %eax
callq 0x1090
movl 0x4(%r14), %esi
bswapl %esi
leaq 0x15bf(%rip), %rdi      # 0x3579
xorl %eax, %eax
callq 0x1090
movzbl 0x8(%r14), %ebx
leaq 0x15b6(%rip), %rdi      # 0x3583
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
movzbl 0x9(%r14), %esi
leaq 0x15aa(%rip), %rdi      # 0x358c
xorl %eax, %eax
callq 0x1090
movzwl 0xa(%r14), %r15d
rolw $0x8, %r15w
movzwl %r15w, %ebp
leaq 0x1599(%rip), %rdi      # 0x3597
movl %ebp, %esi
xorl %eax, %eax
callq 0x1090
leaq 0xe(%r14), %r13
testl %ebx, %ebx
je 0x22e0
cmpl $0x1, %ebx
je 0x2155
cmpl $0xff, %ebx
jne 0x237a
movl $0x1, %ebx
testw %r15w, %r15w
je 0x238f
leaq 0x16a4(%rip), %r14      # 0x36e2
xorl %ebx, %ebx
movzwl (%r13), %eax
rolw $0x8, %ax
movzwl %ax, %r12d
movl 0x2(%r13), %r15d
bswapl %r15d
movq %r14, %rdi
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x6(%r13), %rdi
callq 0x23bb
addq %r12, %r13
addq $0x2, %r13
movzwl (%r13), %eax
rolw $0x8, %ax
movzwl %ax, %esi
leal -0x3(%rsi), %ecx
cmpl $0x2, %ecx
jb 0x20b0
cmpl $0x2, %esi
je 0x212e
cmpl $0x1, %esi
jne 0x23a0
leaq 0x164d(%rip), %rdi      # 0x36ea
movl %r15d, %esi
xorl %eax, %eax
callq 0x1090
addq $0x58, %r13
jmp 0x2146
cmpw $0x3, %ax
leaq 0x166a(%rip), %r12      # 0x3725
leaq 0x165c(%rip), %rax      # 0x371e
cmoveq %rax, %r12
leaq 0x1645(%rip), %rdi      # 0x3712
movq %r12, %rsi
xorl %eax, %eax
callq 0x1090
leaq 0x164c(%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 0x15d2(%rip), %rdi      # 0x36ce
xorl %eax, %eax
callq 0x1090
movq %r15, %rdi
callq 0x23bb
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 0x2146
leaq 0x15ca(%rip), %rdi      # 0x36ff
movl %r15d, %esi
xorl %eax, %eax
callq 0x1090
addq $0xf8, %r13
incl %ebx
cmpl %ebx, %ebp
jne 0x2040
jmp 0x238a
movl 0x10(%r14), %esi
bswapl %esi
movl %esi, 0x3f77(%rip)      # 0x60d8
movl 0x18(%r14), %eax
bswapl %eax
movl %eax, 0x3f6f(%rip)      # 0x60dc
movl 0x1c(%r14), %eax
bswapl %eax
movl %eax, 0x3f67(%rip)      # 0x60e0
leaq 0x1426(%rip), %rdi      # 0x35a6
xorl %eax, %eax
callq 0x1090
movl 0x14(%r14), %esi
bswapl %esi
leaq 0x1421(%rip), %rdi      # 0x35b5
xorl %eax, %eax
callq 0x1090
movl 0x3f3b(%rip), %esi      # 0x60dc
leaq 0x141f(%rip), %rdi      # 0x35c7
xorl %eax, %eax
callq 0x1090
movl 0x3f2b(%rip), %esi      # 0x60e0
leaq 0x141f(%rip), %rdi      # 0x35db
xorl %eax, %eax
callq 0x1090
movzwl 0x20(%r14), %eax
rolw $0x8, %ax
movzwl %ax, %esi
movl %esi, 0x3f0f(%rip)      # 0x60e4
movl 0x24(%r14), %ebx
bswapl %ebx
leaq 0x140c(%rip), %rdi      # 0x35ee
xorl %eax, %eax
callq 0x1090
movzwl 0x22(%r14), %eax
rolw $0x8, %ax
movzwl %ax, %esi
leaq 0x13ff(%rip), %rdi      # 0x35fb
xorl %eax, %eax
callq 0x1090
movl 0x3edb(%rip), %edx      # 0x60e4
imull %ebx, %edx
leaq 0x13f9(%rip), %rdi      # 0x360c
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
movl 0x28(%r14), %esi
bswapl %esi
leaq 0x13fd(%rip), %rdi      # 0x3626
xorl %eax, %eax
callq 0x1090
movl 0x2e(%r14), %esi
bswapl %esi
leaq 0x13f7(%rip), %rdi      # 0x3634
xorl %eax, %eax
callq 0x1090
movzbl 0x32(%r14), %esi
leaq 0x13f2(%rip), %rdi      # 0x3642
xorl %eax, %eax
callq 0x1090
movzbl 0x33(%r14), %esi
leaq 0x13ed(%rip), %rdi      # 0x3650
xorl %eax, %eax
callq 0x1090
movl 0x34(%r14), %esi
bswapl %esi
leaq 0x13ec(%rip), %rdi      # 0x3663
xorl %eax, %eax
callq 0x1090
movl 0x3e48(%rip), %eax      # 0x60cc
imull 0x3e49(%rip), %eax      # 0x60d4
imull 0x3e52(%rip), %ebx      # 0x60e4
cmpl %ebx, %eax
jne 0x23b2
leaq 0x78(%r14), %rbx
leaq 0x183e(%rip), %rdi      # 0x3ae3
callq 0x1060
movq %rbx, %rdi
movl $0x80, %esi
xorl %edx, %edx
callq 0x19e8
addq $0xf8, %r14
leaq 0x1830(%rip), %rdi      # 0x3af7
callq 0x1060
movq %r14, %rdi
movl $0x80, %esi
xorl %edx, %edx
callq 0x19e8
jmp 0x238a
movl $0x1, %ebx
testw %r15w, %r15w
je 0x238f
xorl %ebx, %ebx
movzwl (%r13), %eax
rolw $0x8, %ax
movzwl %ax, %r15d
leaq (%r15,%r13), %r12
addq $0x6, %r12
movl -0x4(%r12), %r14d
bswapl %r14d
leaq 0x13a3(%rip), %rdi      # 0x36b8
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1398(%rip), %rdi      # 0x36bd
movl %r15d, %esi
xorl %eax, %eax
callq 0x1090
leaq 0x1392(%rip), %rdi      # 0x36c8
xorl %eax, %eax
callq 0x1090
leaq 0x6(%r13), %rdi
callq 0x23bb
movl 0x2(%r13), %esi
bswapl %esi
leaq 0x137a(%rip), %rdi      # 0x36cd
xorl %eax, %eax
callq 0x1090
leaq 0x137a(%rip), %rdi      # 0x36db
movl %r14d, %esi
xorl %eax, %eax
callq 0x1090
incl %ebx
movq %r12, %r13
cmpl %ebx, %ebp
jne 0x22f1
jmp 0x238a
leaq 0x13d2(%rip), %rdi      # 0x3753
movl %ebx, %esi
xorl %eax, %eax
callq 0x1090
movl $0x1, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x138c(%rip), %rdi      # 0x3733
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1090
jmp 0x238f
callq 0x1377
xorl %ebx, %ebx
jmp 0x238f