// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x15b580
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
cmpl $0x14, 0x4(%rax)
jle 0x796da
jmp 0x79a42
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x796f3
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x796f3
jmp 0x79a42
cmpl $0x1, -0x1c(%rbp)
jne 0x79737
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x15e810
cmpl $0x0, %eax
jne 0x79735
movq -0x8(%rbp), %rdi
leaq 0x1330d2(%rip), %rsi    # 0x1ac7fb
movb $0x0, %al
callq 0x15bfb0
jmp 0x79a42
jmp 0x79737
movl $0x1, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x79ba0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
leaq 0x13308c(%rip), %rsi    # 0x1ac80d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1654b0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0x133059(%rip), %rsi    # 0x1ac81e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1654b0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0x133031(%rip), %rsi    # 0x1ac82c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
callq 0x165140
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x6c(%rbp)
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %edi
callq 0x79ca0
movq -0x78(%rbp), %rdi
movl -0x6c(%rbp), %edx
movq %rax, %rcx
leaq 0x132fe4(%rip), %rsi    # 0x1ac83a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
callq 0x165140
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x30(%rax), %edx
leaq 0x132fb9(%rip), %rsi    # 0x1ac84d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165210
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x28(%rax), %edx
leaq 0x132f95(%rip), %rsi    # 0x1ac85c
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
cmpl $0xfa, 0x28(%rax)
jbe 0x798e0
jmp 0x79a42
movq -0x28(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, %ecx
addq $0x1, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rsi
movl $0x4, %edx
callq 0x15c450
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
addq $0x200, %rax            # imm = 0x200
movq -0x18(%rbp), %rcx
movq 0x40(%rcx), %rcx
shlq %rcx
subq %rcx, %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jge 0x79a03
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
subq $0x1, %rax
subq -0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165210
movl %eax, %edx
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x68(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
cmpq $0x0, -0x30(%rbp)
jne 0x799b0
leaq -0x60(%rbp), %rdi
leaq 0x127a0b(%rip), %rsi    # 0x1a13af
movl $0x20, %edx
callq 0x15aa30
jmp 0x799cd
leaq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rax
movl %eax, %ecx
movl $0x20, %esi
leaq 0x132eac(%rip), %rdx    # 0x1ac872
movb $0x0, %al
callq 0x15a980
movq -0x8(%rbp), %rdi
leaq -0x60(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x68(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
leaq 0x132e8e(%rip), %rsi    # 0x1ac879
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x7994a
movq -0x18(%rbp), %rax
cmpl $-0x1, 0x2c(%rax)
jne 0x79a23
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
callq 0x79d30
jmp 0x79a40
movq -0x18(%rbp), %rax
cmpl $0x1, 0x2c(%rax)
jne 0x79a3e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x79d90
jmp 0x79a40
jmp 0x79a42
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x15b5a0
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x4(%rax)
movl -0x38(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)