// File: /workspace/github_c_makefile_star2_O3/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 0x2c(%rsp), %rsi
callq 0xe8a1c
movl 0x4(%r15), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x4(%r15)
xorl %r13d, %r13d
cmpl $0x13, %eax
jg 0x561ef
movq 0x8(%r12), %rdx
testq %rdx, %rdx
jne 0x55a9b
cmpl $0x0, (%r12)
je 0x561ef
cmpl $0x1, %ebp
jne 0x55ac1
movq 0xa8(%r15), %rsi
xorl %r13d, %r13d
movq %r14, %rdi
xorl %ecx, %ecx
callq 0xeb3ad
testl %eax, %eax
je 0x56040
movq 0x8(%r12), %rdx
movq %rdx, %rax
shlq $0x9, %rax
movq 0x20(%r15), %rcx
movq 0x80(%r15), %rdi
imulq %rcx, %rdi
movq %rax, %rsi
subq %rdi, %rsi
jge 0x55af5
movq 0x30(%r15), %rsi
imulq 0x8(%r15), %rsi
imulq 0x78(%r15), %rcx
addq %rax, %rcx
addq %rsi, %rcx
jmp 0x55b32
movq 0x90(%r15), %r8
imulq %rcx, %r8
movq 0x30(%r15), %rax
imulq 0x8(%r15), %rax
movq %rsi, %rdi
subq %r8, %rdi
jge 0x55b21
imulq 0x88(%r15), %rcx
addq %rsi, %rax
addq %rax, %rcx
jmp 0x55b32
imulq 0x98(%r15), %rcx
addq %rcx, %rax
addq %rax, %rdi
movq %rdi, %rcx
movq %rcx, 0x10(%r12)
leaq 0x10(%rsp), %rbx
movq %rcx, (%rbx)
leaq 0xcb1be(%rip), %rsi     # 0x120d04
movq %r14, %rdi
xorl %eax, %eax
callq 0xe8617
movl $0x1, %r13d
movq %r14, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xeed31
movq %rax, 0x18(%r12)
leaq 0xcb19a(%rip), %rsi     # 0x120d15
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xeed31
movq %rax, 0x20(%r12)
leaq 0xcb183(%rip), %rsi     # 0x120d23
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
movq (%rbx), %rsi
leaq 0x1(%rsi), %rax
movq %rax, (%rbx)
callq 0xeeb33
movl %eax, 0x2c(%r12)
leal 0x1(%rax), %ecx
cmpl $0x3, %ecx
movl %ebp, 0xc(%rsp)
ja 0x55be3
movl %ecx, %ecx
leaq 0xcb46a(%rip), %rdx     # 0x121044
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmp 0x55bea
leaq 0xd6567(%rip), %rcx     # 0x12c151
leaq 0xcb140(%rip), %rsi     # 0x120d31
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
leaq 0x10(%rsp), %rbx
movq (%rbx), %rsi
leaq 0x1(%rsi), %rax
movq %rax, (%rbx)
callq 0xeeb33
movl %eax, 0x30(%r12)
leaq 0xcb123(%rip), %rsi     # 0x120d44
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xeeb91
movl %eax, 0x28(%r12)
leaq 0xcb10e(%rip), %rsi     # 0x120d53
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movl 0x28(%r12), %esi
cmpq $0xfa, %rsi
ja 0x561ef
movq %r15, 0x20(%rsp)
addq $0x2, 0x10(%rsp)
incq %rsi
movq %rsi, 0x40(%r12)
movl $0x4, %edx
movq %r14, %rdi
callq 0xe96f7
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 0x55d5a
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 0xeeb91
movq %r12, %r14
movq 0x48(%r12), %rcx
movl %eax, (%rcx,%r15,4)
testq %rbx, %rbx
je 0x55d09
addl %r13d, %ebp
movl $0x20, %esi
leaq 0x40(%rsp), %rdi
leaq 0xcb06e(%rip), %rdx     # 0x120d69
movl %ebp, %ecx
movq %rdi, %rbp
xorl %eax, %eax
callq 0xe8193
jmp 0x55d22
movl $0x20, %edx
leaq 0x40(%rsp), %rbp
movq %rbp, %rdi
leaq 0xbf84a(%rip), %rsi     # 0x115567
callq 0xe8219
movq %r14, %r12
movq 0x48(%r14), %rax
movl (%rax,%r15,4), %ecx
movq 0x38(%rsp), %r14
movq %r14, %rdi
leaq 0xcb034(%rip), %rsi     # 0x120d70
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe8617
incq %rbx
movq 0x40(%r12), %rbp
decq %r13
cmpq %rbp, %rbx
jl 0x55cc2
movl 0x2c(%r12), %eax
cmpl $0x1, %eax
movq %r12, %rbp
je 0x56056
cmpl $-0x1, %eax
movq 0x20(%rsp), %r15
movl $0x1, %r13d
jne 0x561ef
cmpl $0x0, 0x28(%rbp)
je 0x561ef
xorl %r12d, %r12d
movq %rbp, 0x30(%rsp)
movl $0x20, %esi
movq %r14, %rdi
callq 0xe8b2b
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 0xcafbf(%rip), %rsi     # 0x120d86
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
movq %r14, %rdi
movl $0x1, %esi
callq 0xe8a15
movq (%r13), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%r14), %rdi
leaq 0x18(%rsp), %rsi
callq 0xeeb4b
movzbl %al, %ebx
movq %r14, %rdi
leaq 0xcafad(%rip), %rsi     # 0x120daf
movl %ebx, %edx
xorl %eax, %eax
callq 0xe8617
testb %bl, %bl
je 0x55e78
movq %rbx, %rax
orq $-0x2, %rax
subq %rax, %rbx
addq (%r13), %rbx
movq %rbx, 0x8(%r13)
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xeeb33
movl %eax, 0x10(%r13)
leal -0x1(%rax), %edx
leaq 0xd6316(%rip), %rcx     # 0x12c151
cmpl $0x3, %edx
ja 0x55e50
movl %edx, %ecx
leaq 0xcb20b(%rip), %rdx     # 0x121054
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
movq %r14, %rdi
leaq 0xcaf74(%rip), %rsi     # 0x120dce
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movl 0xc(%rsp), %eax
cmpl $0x1, %eax
jne 0x55e8e
cmpl $0x1, 0x10(%r13)
je 0x55ea6
jmp 0x56002
movq %r14, %rdi
leaq 0xcaf3b(%rip), %rsi     # 0x120dbd
xorl %eax, %eax
callq 0xe8617
jmp 0x56002
cmpl $0x2, %eax
jne 0x56002
movl 0x10(%r13), %eax
decl %eax
cmpl $0x1, %eax
ja 0x56002
incq 0x18(%rsp)
movq 0x18(%r14), %rdi
leaq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0xeed31
movl %eax, 0x14(%r13)
movq %r14, %rdi
leaq 0xcaf15(%rip), %rsi     # 0x120ddf
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xeeb4b
movzbl %al, %ebx
movq %r14, %rdi
leaq 0xef036(%rip), %rsi     # 0x144f22
movl %ebx, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
movq 0x18(%rsp), %rsi
movl (%r15), %r9d
movq %rbx, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0xef87c
movq %rax, 0x18(%r13)
movq 0x18(%rax), %rdi
callq 0xf70f6
movq %r14, %rdi
leaq 0xcc855(%rip), %rsi     # 0x12277b
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movl 0x10(%r13), %eax
cmpl $0x2, %eax
je 0x55fed
cmpl $0x1, %eax
jne 0x56002
cmpl $0x1, 0xc(%rsp)
jne 0x55ff4
movq 0x8(%r13), %r15
movl $0x10, %esi
movq %r14, %rdi
callq 0xe8b2b
movq %rax, %rbx
addq $0x6, %r15
movq %r15, 0x40(%rsp)
movq 0x20(%rsp), %r15
movq 0x18(%r14), %rdi
leaq 0x40(%rsp), %rsi
callq 0xeed31
movq %rax, %rbp
movq %r14, %rdi
leaq 0xcae7b(%rip), %rsi     # 0x120e09
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r13), %rax
movq 0x18(%rax), %rdi
callq 0xf66ff
movq %rax, 0x8(%rbx)
movq 0x10(%rax), %rcx
testq %rcx, %rcx
jle 0x55fcc
movq 0x8(%rax), %rax
xorl %edx, %edx
cmpl $0x2f, (%rax,%rdx,4)
jne 0x55fc4
movl $0x5f, (%rax,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x55fb7
movl 0x14(%r13), %eax
movl %eax, (%rbx)
movq 0xb0(%r15), %rsi
movl %ebp, %edx
movq %r14, %rdi
movq %rbx, %rcx
callq 0xeb3ad
movq 0x30(%rsp), %rbp
jmp 0x56002
cmpl $0x2, 0xc(%rsp)
jne 0x56002
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x562ef
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x18(%r13), %rsi
movq %r14, %rdi
callq 0xefaca
movq %r14, %rdi
movq %r13, %rsi
callq 0xe8be2
incq %r12
movl 0x28(%rbp), %eax
cmpq %rax, %r12
jb 0x55d91
movl $0x1, %r13d
jmp 0x561ef
leaq 0xcacab(%rip), %rsi     # 0x120cf2
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x561ef
cmpl $0x3, 0x28(%rbp)
movq 0x20(%rsp), %r15
movl $0x1, %r13d
jb 0x561ef
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 0x561ef
leaq 0xcaedd(%rip), %rsi     # 0x120f79
movq %r14, %rdi
xorl %eax, %eax
callq 0xe8617
movq %r14, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%r14), %rdi
leaq 0x40(%rsp), %r13
movq %r13, %rsi
callq 0xeeb91
leaq 0xcaed7(%rip), %rsi     # 0x120fa2
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xeed31
leaq 0xcaec5(%rip), %rsi     # 0x120fb0
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xeed31
leaq 0xcaeb2(%rip), %rsi     # 0x120fbd
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xeed31
movq %rax, 0x38(%rbp)
leaq 0xcae9c(%rip), %rsi     # 0x120fcb
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xeed31
leaq 0xcae8a(%rip), %rsi     # 0x120fd9
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xeeb91
leaq 0xcae78(%rip), %rsi     # 0x120fe7
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xeeb91
leaq 0xcae69(%rip), %rsi     # 0x120ff8
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xeed31
leaq 0xcae58(%rip), %rsi     # 0x121007
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rdi
movq %r13, %rsi
movl $0x1, %r13d
callq 0xeed31
leaq 0xcae41(%rip), %rsi     # 0x121016
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq %r14, %rdi
movl $0x1, %esi
callq 0xe8a15
movl 0x2c(%rsp), %esi
movq %r14, %rdi
callq 0xe8a25
decl 0x4(%r15)
movl %r13d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq