// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/hfs.c
// Function: do_node
static int do_node(deark *c, lctx *d, struct nodedata *nd, int pass)
{
	i64 pos;
	i64 i;
	int saved_indent_level;
	int retval = 0;

	de_dbg_indent_save(c, &saved_indent_level);
	d->nesting_level++;
	if(d->nesting_level>20) goto done;
	if(nd->nodenum==0 && !nd->expecting_header) goto done;

	if(pass==1) {
		if(!de_inthashtable_add_item(c, d->nodes_seen, nd->nodenum, NULL)) {
			de_err(c, "Invalid node list");
			goto done;
		}
	}
	retval = 1;

	nd->dpos = node_dpos(d, nd->nodenum);
	pos = nd->dpos;

	de_dbg(c, "node #%"I64_FMT" at %"I64_FMT, nd->nodenum, nd->dpos);
	de_dbg_indent(c, 1);

	// == 14-byte NodeDescriptor ==
	nd->f_link = de_getu32be_p(&pos);
	de_dbg(c, "fwd link: %"I64_FMT, nd->f_link);
	nd->b_link = de_getu32be_p(&pos);
	de_dbg(c, "bwd link: %"I64_FMT, nd->b_link);

	nd->node_type = (int)dbuf_geti8(c->infile, pos++);
	de_dbg(c, "node type: %d (%s)", nd->node_type, get_node_type_name(nd->node_type));
	nd->node_level = (int)dbuf_geti8(c->infile, pos++);
	de_dbg(c, "node level: %d", nd->node_level);
	nd->nrecs = (unsigned int)de_getu16be_p(&pos);
	de_dbg(c, "number of records: %u", nd->nrecs);
	if(nd->nrecs>250) goto done;
	pos += 2; // ndResv2

	// == The offset table at the end of the node ==
	nd->num_offsets = (i64)nd->nrecs+1;
	nd->offsets = de_mallocarray(c, nd->num_offsets, sizeof(unsigned int));

	pos = nd->dpos+512 - 2*nd->num_offsets;
	for(i=0; i<nd->num_offsets; i++) {
		char nbuf[32];
		i64 idx = nd->num_offsets - 1 - i;
		nd->offsets[idx] = (unsigned int)de_getu16be_p(&pos);
		if(i==0) de_strlcpy(nbuf, "free space", sizeof(nbuf));
		else de_snprintf(nbuf, sizeof(nbuf), "rec %u", (unsigned int)idx);
		de_dbg(c, "offset to %s: %u", nbuf, (unsigned int)nd->offsets[idx]);
	}

	if(nd->node_type == -1) {
		do_leaf_node(c, d, nd, pass);
	}
	else if(nd->node_type==1) {
		do_header_node(c, d, nd);
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
	d->nesting_level--;
	return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %ecx, %ebp
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %r14
leaq 0x24(%rsp), %rsi
callq 0xe958c
movl 0x4(%r15), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x4(%r15)
xorl %r13d, %r13d
cmpl $0x13, %eax
jg 0x562d1
movq 0x8(%r12), %rdx
testq %rdx, %rdx
jne 0x55b7e
cmpl $0x0, (%r12)
je 0x562d1
cmpl $0x1, %ebp
jne 0x55b9f
movq 0xa8(%r15), %rsi
xorl %r13d, %r13d
movq %r14, %rdi
xorl %ecx, %ecx
callq 0xeb96a
testl %eax, %eax
je 0x5611a
movq 0x8(%r12), %rdx
movq %rdx, %rsi
shlq $0x9, %rsi
movq 0x20(%r15), %rcx
movq 0x80(%r15), %rdi
imulq %rcx, %rdi
movq %rsi, %rax
subq %rdi, %rax
jge 0x55bd2
movq 0x30(%r15), %rax
imulq 0x8(%r15), %rax
imulq 0x78(%r15), %rcx
jmp 0x55bf6
movq 0x90(%r15), %r8
imulq %rcx, %r8
movq 0x30(%r15), %rsi
imulq 0x8(%r15), %rsi
movq %rax, %rdi
subq %r8, %rdi
jge 0x55bfe
imulq 0x88(%r15), %rcx
addq %rsi, %rcx
addq %rax, %rcx
jmp 0x55c0c
imulq 0x98(%r15), %rcx
addq %rsi, %rcx
addq %rdi, %rcx
movq %rcx, 0x10(%r12)
leaq 0x10(%rsp), %rbx
movq %rcx, (%rbx)
leaq 0xcafbc(%rip), %rsi     # 0x120bdc
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9226
movl $0x1, %r13d
movq %r14, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xef34e
movq %rax, 0x18(%r12)
leaq 0xcaf98(%rip), %rsi     # 0x120bed
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xef34e
movq %rax, 0x20(%r12)
leaq 0xcaf81(%rip), %rsi     # 0x120bfb
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
movq (%rbx), %rsi
leaq 0x1(%rsi), %rax
movq %rax, (%rbx)
callq 0xef135
movl %eax, 0x2c(%r12)
leal 0x1(%rax), %ecx
cmpl $0x3, %ecx
ja 0x55cb9
movl %ecx, %ecx
leaq 0xcb26c(%rip), %rdx     # 0x120f1c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmp 0x55cc0
leaq 0xd61a9(%rip), %rcx     # 0x12be69
leaq 0xcaf42(%rip), %rsi     # 0x120c09
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
leaq 0x10(%rsp), %rbx
movq (%rbx), %rsi
leaq 0x1(%rsi), %rax
movq %rax, (%rbx)
callq 0xef135
movl %eax, 0x30(%r12)
leaq 0xcaf25(%rip), %rsi     # 0x120c1c
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xef193
movl %eax, 0x28(%r12)
leaq 0xcaf10(%rip), %rsi     # 0x120c2b
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movl 0x28(%r12), %esi
cmpq $0xfa, %rsi
ja 0x562d1
movl %ebp, 0xc(%rsp)
movq %r15, 0x28(%rsp)
addq $0x2, 0x10(%rsp)
incq %rsi
movq %rsi, 0x40(%r12)
movl $0x4, %edx
movq %r14, %rdi
callq 0xea259
movq %rax, 0x48(%r12)
movq 0x10(%r12), %rax
movq 0x40(%r12), %rbp
leaq (,%rbp,2), %rcx
negq %rcx
addq %rcx, %rax
addq $0x200, %rax            # imm = 0x200
movq %rax, 0x10(%rsp)
testq %rbp, %rbp
jle 0x55e34
movq $-0x1, %r13
xorl %ebx, %ebx
movq %r14, 0x38(%rsp)
movq %rbp, %r15
addq %r13, %r15
movq 0x18(%r14), %rdi
leaq 0x10(%rsp), %rsi
callq 0xef193
movq %r12, %r14
movq 0x48(%r12), %rcx
movl %eax, (%rcx,%r15,4)
testq %rbx, %rbx
je 0x55de3
addl %r13d, %ebp
movl $0x20, %esi
leaq 0x40(%rsp), %rdi
leaq 0xcae6c(%rip), %rdx     # 0x120c41
movl %ebp, %ecx
movq %rdi, %rbp
xorl %eax, %eax
callq 0xe8d67
jmp 0x55dfc
movl $0x20, %edx
leaq 0x40(%rsp), %rbp
movq %rbp, %rdi
leaq 0xbf6c0(%rip), %rsi     # 0x1154b7
callq 0xe8ded
movq %r14, %r12
movq 0x48(%r14), %rax
movl (%rax,%r15,4), %ecx
movq 0x38(%rsp), %r14
movq %r14, %rdi
leaq 0xcae32(%rip), %rsi     # 0x120c48
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe9226
incq %rbx
movq 0x40(%r12), %rbp
decq %r13
cmpq %rbp, %rbx
jl 0x55d9c
movl 0x2c(%r12), %eax
cmpl $0x1, %eax
movq %r12, %rbp
je 0x56130
cmpl $-0x1, %eax
movq 0x28(%rsp), %r15
movl $0x1, %r13d
jne 0x562d1
cmpl $0x0, 0x28(%rbp)
je 0x562d1
xorl %r12d, %r12d
movq %rbp, 0x30(%rsp)
movl $0x20, %esi
movq %r14, %rdi
callq 0xe969b
movq %rax, %r13
movq 0x10(%rbp), %rcx
movq 0x48(%rbp), %rax
movl (%rax,%r12,4), %r8d
leaq (%rcx,%r8), %rdx
movq %rdx, (%r13)
movl 0x4(%rax,%r12,4), %r9d
subl %r8d, %r9d
movq %r14, %rdi
leaq 0xcadbd(%rip), %rsi     # 0x120c5e
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9226
movq %r14, %rdi
movl $0x1, %esi
callq 0xe9585
movq (%r13), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%r14), %rdi
leaq 0x18(%rsp), %rsi
callq 0xef14d
movzbl %al, %ebx
movq %r14, %rdi
leaq 0xcadab(%rip), %rsi     # 0x120c87
movl %ebx, %edx
xorl %eax, %eax
callq 0xe9226
testb %bl, %bl
je 0x55f52
movq %rbx, %rax
orq $-0x2, %rax
subq %rax, %rbx
addq (%r13), %rbx
movq %rbx, 0x8(%r13)
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xef135
movl %eax, 0x10(%r13)
leal -0x1(%rax), %edx
leaq 0xd5f54(%rip), %rcx     # 0x12be69
cmpl $0x3, %edx
ja 0x55f2a
movl %edx, %ecx
leaq 0xcb009(%rip), %rdx     # 0x120f2c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
movq %r14, %rdi
leaq 0xcad72(%rip), %rsi     # 0x120ca6
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movl 0xc(%rsp), %eax
cmpl $0x1, %eax
jne 0x55f68
cmpl $0x1, 0x10(%r13)
je 0x55f80
jmp 0x560db
movq %r14, %rdi
leaq 0xcad39(%rip), %rsi     # 0x120c95
xorl %eax, %eax
callq 0xe9226
jmp 0x560db
cmpl $0x2, %eax
jne 0x560db
movl 0x10(%r13), %eax
decl %eax
cmpl $0x1, %eax
ja 0x560db
incq 0x18(%rsp)
movq 0x18(%r14), %rdi
leaq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0xef34e
movl %eax, 0x14(%r13)
movq %r14, %rdi
leaq 0xcad13(%rip), %rsi     # 0x120cb7
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xef14d
movzbl %al, %ebx
movq %r14, %rdi
leaq 0xeea7c(%rip), %rsi     # 0x144a42
movl %ebx, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
movq 0x18(%rsp), %rsi
movl (%r15), %r9d
movq %rbx, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0xefe67
movq %rax, 0x18(%r13)
movq 0x18(%rax), %rdi
callq 0xf7557
movq %r14, %rdi
leaq 0xcc573(%rip), %rsi     # 0x122573
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movl 0x10(%r13), %eax
cmpl $0x2, %eax
je 0x560c6
cmpl $0x1, %eax
jne 0x560db
movl 0xc(%rsp), %eax
cmpl $0x1, %eax
jne 0x56113
movq 0x8(%r13), %rax
movq %rax, 0x40(%rsp)
movl $0x10, %esi
movq %r14, %rdi
callq 0xe969b
movq %rax, %rbx
addq $0x6, 0x40(%rsp)
movq 0x18(%r14), %rdi
leaq 0x40(%rsp), %rsi
callq 0xef34e
movq %rax, %rbp
movq %r14, %rdi
leaq 0xcac7a(%rip), %rsi     # 0x120ce1
movl %ebp, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r13), %rax
movq 0x18(%rax), %rdi
callq 0xf6b5c
movq %rax, 0x8(%rbx)
movq 0x10(%rax), %rcx
testq %rcx, %rcx
jle 0x560a5
movq 0x8(%rax), %rax
xorl %edx, %edx
cmpl $0x2f, (%rax,%rdx,4)
jne 0x5609d
movl $0x5f, (%rax,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x56090
movl 0x14(%r13), %eax
movl %eax, (%rbx)
movq 0xb0(%r15), %rsi
movl %ebp, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0xeb96a
movq 0x30(%rsp), %rbp
jmp 0x560db
cmpl $0x2, 0xc(%rsp)
jne 0x560db
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x563d1
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x18(%r13), %rsi
movq %r14, %rdi
callq 0xf00aa
movq %r14, %rdi
movq %r13, %rsi
callq 0xe9752
incq %r12
movl 0x28(%rbp), %eax
cmpq %rax, %r12
jb 0x55e6b
jmp 0x562cb
cmpl $0x2, %eax
je 0x560cd
jmp 0x560db
leaq 0xcaaa9(%rip), %rsi     # 0x120bca
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x562d1
cmpl $0x3, 0x28(%rbp)
movq 0x28(%rsp), %r15
movl $0x1, %r13d
jb 0x562d1
movq 0x10(%rbp), %rax
movq 0x48(%rbp), %rcx
movl (%rcx), %ecx
leaq (%rax,%rcx), %rdx
movq %rdx, 0x40(%rsp)
addq %rcx, %rax
addq $0x200, %rax            # imm = 0x200
movq 0x18(%r14), %rcx
cmpq 0x18(%rcx), %rax
jg 0x562d1
leaq 0xcacdb(%rip), %rsi     # 0x120e51
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9226
movq %r14, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%r14), %rdi
leaq 0x40(%rsp), %r13
movq %r13, %rsi
callq 0xef193
leaq 0xcacd5(%rip), %rsi     # 0x120e7a
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xef34e
leaq 0xcacc3(%rip), %rsi     # 0x120e88
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xef34e
leaq 0xcacb0(%rip), %rsi     # 0x120e95
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xef34e
movq %rax, 0x38(%rbp)
leaq 0xcac9a(%rip), %rsi     # 0x120ea3
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xef34e
leaq 0xcac88(%rip), %rsi     # 0x120eb1
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xef193
leaq 0xcac76(%rip), %rsi     # 0x120ebf
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xef193
leaq 0xcac67(%rip), %rsi     # 0x120ed0
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xef34e
leaq 0xcac56(%rip), %rsi     # 0x120edf
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
movq %r13, %rsi
movl $0x1, %r13d
callq 0xef34e
leaq 0xcac3f(%rip), %rsi     # 0x120eee
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq %r14, %rdi
movl $0x1, %esi
callq 0xe9585
jmp 0x562d1
movl $0x1, %r13d
movl 0x24(%rsp), %esi
movq %r14, %rdi
callq 0xe9595
decl 0x4(%r15)
movl %r13d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq