// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/hfs.c
// Function: do_leaf_node_record
static void do_leaf_node_record(deark *c, lctx *d, struct nodedata *nd, i64 idx, int pass)
{
	i64 pos1_rel, pos;
	i64 len;
	i64 ckrKeyLen;
	i64 nlen;
	struct recorddata *rd = NULL;

	rd = de_malloc(c, sizeof(struct recorddata));
	pos1_rel = nd->offsets[idx];
	rd->pos1 = nd->dpos + pos1_rel;
	len = nd->offsets[idx+1] - nd->offsets[idx];
	de_dbg(c, "leaf node record[%d] at %"I64_FMT"+%"I64_FMT", len=%"I64_FMT,
		(int)idx, nd->dpos, pos1_rel, len);
	de_dbg_indent(c, 1);

	// == Catalog File Key
	pos = rd->pos1;
	ckrKeyLen = (i64)de_getbyte_p(&pos);
	de_dbg(c, "ckrKeyLen: %d", (int)ckrKeyLen);
	if(ckrKeyLen==0) {
		de_dbg(c, "[deleted record]");
		goto done;
	}

	rd->datapos = rd->pos1 + 1 + ckrKeyLen;
	if((ckrKeyLen%2)==0) rd->datapos++; // padding

	// Look ahead to get the cdrType
	rd->cdrType = (int)dbuf_geti8(c->infile, rd->datapos);
	de_dbg(c, "cdrType: %d (%s)", rd->cdrType, get_cdrType_name(rd->cdrType));

	if(pass==1) {
		if(rd->cdrType!=CDRTYPE_DIR) goto done;
	}
	else if(pass==2) {
		if(rd->cdrType!=CDRTYPE_DIR && rd->cdrType!=CDRTYPE_FILE) goto done;
	}
	else {
		goto done;
	}

	pos++; // ckrResrv1
	rd->ParID = (u32)de_getu32be_p(&pos);
	de_dbg(c, "ckrParID: %u", (unsigned int)rd->ParID);

	nlen = (i64)de_getbyte_p(&pos);
	de_dbg(c, "name len: %d", (int)nlen);
	rd->name_srd = dbuf_read_string(c->infile, pos, nlen, nlen, 0, d->input_encoding);
	de_dbg(c, "name: \"%s\"", ucstring_getpsz_d(rd->name_srd->str));

	// == Catalog File Data Record

	switch(rd->cdrType) {
	case CDRTYPE_DIR:
		if(pass==1) {
			do_leaf_node_record_directory_pass1(c, d, nd, rd);
		}
		else if(pass==2) {
			do_leaf_node_record_extract_item(c, d, nd, rd);
		}
		break;
	case CDRTYPE_FILE:
		if(pass==2) {
			do_leaf_node_record_extract_item(c, d, nd, rd);
		}
		break;
	}

done:
	de_dbg_indent(c, -1);
	if(rd) {
		de_destroy_stringreaderdata(c, rd->name_srd);
		de_free(c, rd);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movl $0x20, %esi
callq 0x15b780
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
addq -0x30(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x20(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
movq 0x48(%rcx), %rcx
movq -0x20(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
leaq 0x13283a(%rip), %rsi    # 0x1ac88f
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
leaq 0x13281a(%rip), %rsi    # 0x1ac8b8
movb $0x0, %al
callq 0x15b0d0
cmpq $0x0, -0x48(%rbp)
jne 0x7a0c3
movq -0x8(%rbp), %rdi
leaq 0x13280f(%rip), %rsi    # 0x1ac8c6
movb $0x0, %al
callq 0x15b0d0
jmp 0x7a2e2
movq -0x58(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
addq -0x48(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x48(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x7a0fe
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x165140
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x58(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x7a320
movq -0x68(%rbp), %rdi
movl -0x5c(%rbp), %edx
movq %rax, %rcx
leaq 0x13278c(%rip), %rsi    # 0x1ac8d7
movb $0x0, %al
callq 0x15b0d0
cmpl $0x1, -0x24(%rbp)
jne 0x7a169
movq -0x58(%rbp), %rax
cmpl $0x1, 0x10(%rax)
je 0x7a167
jmp 0x7a2e2
jmp 0x7a191
cmpl $0x2, -0x24(%rbp)
jne 0x7a18a
movq -0x58(%rbp), %rax
cmpl $0x1, 0x10(%rax)
je 0x7a188
movq -0x58(%rbp), %rax
cmpl $0x2, 0x10(%rax)
je 0x7a188
jmp 0x7a2e2
jmp 0x7a18f
jmp 0x7a2e2
jmp 0x7a191
movq -0x38(%rbp), %rax
incq %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x38(%rbp), %rsi
movq %rsi, -0x88(%rbp)
callq 0x1654b0
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl 0x14(%rax), %edx
leaq 0x132719(%rip), %rsi    # 0x1ac8e8
xorl %eax, %eax
movl %eax, -0x7c(%rbp)
movb %al, -0x6d(%rbp)
callq 0x15b0d0
movq -0x88(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x165170
movb %al, %cl
movb -0x6d(%rbp), %al
movzbl %cl, %ecx
movq %rcx, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movl -0x50(%rbp), %edx
leaq 0x156838(%rip), %rsi    # 0x1d0a42
callq 0x15b0d0
movl -0x7c(%rbp), %r8d
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x50(%rbp), %rcx
movq -0x10(%rbp), %rax
movl (%rax), %r9d
movq %rcx, %rdx
callq 0x1664c0
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x172650
movq -0x78(%rbp), %rdi
movq %rax, %rdx
movb -0x6d(%rbp), %al
leaq 0x133f69(%rip), %rsi    # 0x1ae1d0
callq 0x15b0d0
movq -0x58(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x6c(%rbp)
subl $0x1, %eax
je 0x7a287
jmp 0x7a27d
movl -0x6c(%rbp), %eax
subl $0x2, %eax
je 0x7a2c3
jmp 0x7a2e0
cmpl $0x1, -0x24(%rbp)
jne 0x7a2a4
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x7a3b0
jmp 0x7a2c1
cmpl $0x2, -0x24(%rbp)
jne 0x7a2bf
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x7a4a0
jmp 0x7a2c1
jmp 0x7a2e0
cmpl $0x2, -0x24(%rbp)
jne 0x7a2de
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x7a4a0
jmp 0x7a2e0
jmp 0x7a2e2
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
cmpq $0x0, -0x58(%rbp)
je 0x7a315
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x166830
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x15b820
addq $0x90, %rsp
popq %rbp
retq
nop