// File: /workspace/github_c_makefile_star2_O2/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 $0x58, %rsp
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
leaq 0x2c(%rsp), %rsi
callq 0xdebae
movl 0x4(%r15), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x4(%r15)
xorl %r12d, %r12d
cmpl $0x13, %eax
jg 0x5351c
movq 0x8(%rbx), %rdx
testq %rdx, %rdx
jne 0x52e08
cmpl $0x0, (%rbx)
je 0x5351c
cmpl $0x1, %ebp
jne 0x52e2d
movq 0xa8(%r15), %rsi
xorl %r12d, %r12d
movq %r14, %rdi
xorl %ecx, %ecx
callq 0xe0a0b
testl %eax, %eax
je 0x5336b
movq 0x8(%rbx), %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 0x52e61
movq 0x30(%r15), %rsi
imulq 0x8(%r15), %rsi
imulq 0x78(%r15), %rcx
addq %rax, %rcx
addq %rsi, %rcx
jmp 0x52e9e
movq 0x90(%r15), %r8
imulq %rcx, %r8
movq 0x30(%r15), %rax
imulq 0x8(%r15), %rax
movq %rsi, %rdi
subq %r8, %rdi
jge 0x52e8d
imulq 0x88(%r15), %rcx
addq %rsi, %rax
addq %rax, %rcx
jmp 0x52e9e
imulq 0x98(%r15), %rcx
addq %rcx, %rax
addq %rax, %rdi
movq %rdi, %rcx
movq %rcx, 0x10(%rbx)
movq %rbx, (%rsp)
leaq 0x18(%rsp), %rbx
movq %rcx, (%rbx)
leaq 0xc0d5f(%rip), %rsi     # 0x113c14
movq %r14, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %r12
movq %r14, %rdi
movl %r12d, %esi
callq 0xdeba7
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xe4071
movq (%rsp), %rcx
movq %rax, 0x18(%rcx)
leaq 0xc0d3c(%rip), %rsi     # 0x113c25
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xe4071
movq (%rsp), %rcx
movq %rax, 0x20(%rcx)
leaq 0xc0d22(%rip), %rsi     # 0x113c33
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
movq (%rbx), %rsi
leaq 0x1(%rsi), %rax
movq %rax, (%rbx)
callq 0xe3f12
movq (%rsp), %rcx
movl %eax, 0x2c(%rcx)
leal 0x1(%rax), %ecx
cmpl $0x3, %ecx
movl %ebp, 0xc(%rsp)
ja 0x52f56
movl %ecx, %ecx
leaq 0xc1007(%rip), %rdx     # 0x113f54
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmp 0x52f5d
leaq 0xcbf84(%rip), %rcx     # 0x11eee1
leaq 0xc0cdd(%rip), %rsi     # 0x113c41
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
leaq 0x18(%rsp), %rbx
movq (%rbx), %rsi
leaq 0x1(%rsi), %rax
movq %rax, (%rbx)
callq 0xe3f12
movq (%rsp), %r13
movl %eax, 0x30(%r13)
leaq 0xc0cbd(%rip), %rsi     # 0x113c54
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
movq %rbx, %rsi
movq %r13, %rbx
callq 0xe3f6e
movl %eax, 0x28(%r13)
leaq 0xc0ca6(%rip), %rsi     # 0x113c63
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movl 0x28(%r13), %esi
cmpq $0xfa, %rsi
ja 0x5351c
movq %r15, 0x10(%rsp)
leaq 0x18(%rsp), %r15
addq $0x2, (%r15)
incq %rsi
movq %rsi, 0x40(%rbx)
pushq $0x4
popq %rdx
movq %r14, %rdi
callq 0xdf66f
movq %rax, 0x48(%rbx)
movq 0x10(%rbx), %rax
movq 0x40(%rbx), %r13
leaq (,%r13,2), %rcx
negq %rcx
addq %rcx, %rax
addq $0x200, %rax            # imm = 0x200
movq %rax, (%r15)
pushq $-0x1
popq %rbx
leaq 0x30(%rsp), %r15
xorl %ebp, %ebp
cmpq %r13, %rbp
jge 0x530b1
leaq (%rbx,%r13), %r12
movq 0x18(%r14), %rdi
leaq 0x18(%rsp), %rsi
callq 0xe3f6e
movq (%rsp), %rcx
movq 0x48(%rcx), %rcx
movl %eax, (%rcx,%r12,4)
cmpq $-0x1, %rbx
je 0x53070
addl %ebx, %r13d
movq %r15, %rdi
pushq $0x20
popq %rsi
leaq 0xc0c15(%rip), %rdx     # 0x113c79
movl %r13d, %ecx
xorl %eax, %eax
callq 0xde40c
jmp 0x53082
movq %r15, %rdi
leaq 0xb545d(%rip), %rsi     # 0x1084d7
pushq $0x20
popq %rdx
callq 0xde492
movq (%rsp), %r13
movq 0x48(%r13), %rax
movl (%rax,%r12,4), %ecx
movq %r14, %rdi
leaq 0xc0be8(%rip), %rsi     # 0x113c80
movq %r15, %rdx
xorl %eax, %eax
callq 0xde896
incq %rbp
movq 0x40(%r13), %r13
decq %rbx
jmp 0x53027
movq (%rsp), %rbx
movl 0x2c(%rbx), %eax
cmpl $0x1, %eax
je 0x5338a
cmpl $-0x1, %eax
movq 0x10(%rsp), %r15
pushq $0x1
popq %r12
jne 0x5351c
leaq 0x20(%rsp), %r12
xorl %r13d, %r13d
movl 0x28(%rbx), %eax
cmpq %rax, %r13
jae 0x53381
movq %r14, %rdi
pushq $0x20
popq %rsi
callq 0xdecaf
movq %rax, %rbp
movq 0x10(%rbx), %rcx
movq 0x48(%rbx), %rax
movl (%rax,%r13,4), %r8d
leaq (%rcx,%r8), %rdx
movq %rdx, (%rbp)
movl 0x4(%rax,%r13,4), %r9d
subl %r8d, %r9d
movq %r14, %rdi
leaq 0xc0b7b(%rip), %rsi     # 0x113c96
movl %r13d, %edx
xorl %eax, %eax
callq 0xde896
movq %r14, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq (%rbp), %rax
movq %rax, 0x20(%rsp)
movq 0x18(%r14), %rdi
movq %r12, %rsi
callq 0xe3f2a
movzbl %al, %ebx
movq %r14, %rdi
leaq 0xc0b6d(%rip), %rsi     # 0x113cbf
movl %ebx, %edx
xorl %eax, %eax
callq 0xde896
testb %bl, %bl
je 0x531ca
movq %rbx, %rax
orq $-0x2, %rax
subq %rax, %rbx
addq (%rbp), %rbx
movq %rbx, 0x8(%rbp)
movq 0x18(%r14), %rdi
movq %rbx, %rsi
callq 0xe3f12
movl %eax, 0x10(%rbp)
leal -0x1(%rax), %edx
leaq 0xcbd57(%rip), %rcx     # 0x11eee1
cmpl $0x3, %edx
ja 0x5319f
movl %edx, %ecx
leaq 0xc0dcc(%rip), %rdx     # 0x113f64
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
movq %r14, %rdi
leaq 0xc0b35(%rip), %rsi     # 0x113cde
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movl 0xc(%rsp), %eax
cmpl $0x1, %eax
movq (%rsp), %rbx
jne 0x531e4
cmpl $0x1, 0x10(%rbp)
je 0x531fb
jmp 0x53341
movq %r14, %rdi
leaq 0xc0af9(%rip), %rsi     # 0x113ccd
xorl %eax, %eax
callq 0xde896
movq (%rsp), %rbx
jmp 0x53341
cmpl $0x2, %eax
jne 0x53341
movl 0x10(%rbp), %eax
decl %eax
cmpl $0x1, %eax
ja 0x53341
incq 0x20(%rsp)
movq 0x18(%r14), %rdi
movq %r12, %rsi
callq 0xe4071
movl %eax, 0x14(%rbp)
movq %r14, %rdi
leaq 0xc0ad6(%rip), %rsi     # 0x113cef
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
movq %r12, %rsi
callq 0xe3f2a
movzbl %al, %ebx
movq %r14, %rdi
leaq 0xe4897(%rip), %rsi     # 0x137ad2
movl %ebx, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
movq 0x20(%rsp), %rsi
movl (%r15), %r9d
movq %rbx, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0xe495c
movq %rax, 0x18(%rbp)
movq 0x18(%rax), %rdi
callq 0xeb877
movq %r14, %rdi
leaq 0xc2346(%rip), %rsi     # 0x1155bb
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movl 0x10(%rbp), %eax
cmpl $0x2, %eax
je 0x53328
cmpl $0x1, %eax
movq (%rsp), %rbx
jne 0x53341
cmpl $0x1, 0xc(%rsp)
jne 0x53333
movq 0x8(%rbp), %r15
movq %r14, %rdi
pushq $0x10
popq %rsi
callq 0xdecaf
movq %rax, %rbx
addq $0x6, %r15
movq %r15, 0x30(%rsp)
movq 0x18(%r14), %rdi
leaq 0x30(%rsp), %rsi
callq 0xe4071
movq %rax, %r15
movq %r14, %rdi
leaq 0xc0a40(%rip), %rsi     # 0x113d19
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0xeaf0b
movq %rax, 0x8(%rbx)
movq %rax, %rdi
xorl %esi, %esi
callq 0x53aa1
movl 0x14(%rbp), %eax
movl %eax, (%rbx)
movq 0x10(%rsp), %rax
movq 0xb0(%rax), %rsi
movl %r15d, %edx
movq 0x10(%rsp), %r15
movq %r14, %rdi
movq %rbx, %rcx
movq (%rsp), %rbx
callq 0xe0a0b
jmp 0x53341
cmpl $0x2, 0xc(%rsp)
movq (%rsp), %rbx
jne 0x53341
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x53612
movq %r14, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
movq 0x18(%rbp), %rsi
movq %r14, %rdi
callq 0xe4b94
movq %r14, %rdi
movq %rbp, %rsi
callq 0xded32
incq %r13
jmp 0x530db
leaq 0xc0890(%rip), %rsi     # 0x113c02
movq %r14, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x5351c
pushq $0x1
popq %r12
jmp 0x5351c
cmpl $0x3, 0x28(%rbx)
movq 0x10(%rsp), %r15
pushq $0x1
popq %r12
jb 0x5351c
movq 0x10(%rbx), %rax
movq 0x48(%rbx), %rcx
movl (%rcx), %ecx
leaq (%rax,%rcx), %rdx
movq %rdx, 0x30(%rsp)
addq %rcx, %rax
addq $0x200, %rax            # imm = 0x200
movq 0x18(%r14), %rcx
cmpq 0x18(%rcx), %rax
jg 0x5351c
leaq 0xc0abb(%rip), %rsi     # 0x113e89
movq %r14, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
callq 0xdeba7
movq 0x18(%r14), %rdi
leaq 0x30(%rsp), %r13
movq %r13, %rsi
callq 0xe3f6e
leaq 0xc0ab5(%rip), %rsi     # 0x113eb2
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xe4071
leaq 0xc0aa3(%rip), %rsi     # 0x113ec0
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xe4071
leaq 0xc0a90(%rip), %rsi     # 0x113ecd
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xe4071
movq %rax, 0x38(%rbx)
leaq 0xc0a7a(%rip), %rsi     # 0x113edb
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xe4071
leaq 0xc0a68(%rip), %rsi     # 0x113ee9
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xe3f6e
leaq 0xc0a56(%rip), %rsi     # 0x113ef7
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xe3f6e
leaq 0xc0a47(%rip), %rsi     # 0x113f08
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xe4071
leaq 0xc0a36(%rip), %rsi     # 0x113f17
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rdi
movq %r13, %rsi
pushq $0x1
popq %r12
callq 0xe4071
leaq 0xc0a21(%rip), %rsi     # 0x113f26
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq %r14, %rdi
movl %ebp, %esi
callq 0xdeba7
movl 0x2c(%rsp), %esi
movq %r14, %rdi
callq 0xdebb7
decl 0x4(%r15)
movl %r12d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq