// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/d64.c
// Function: do_dir_entry
static void do_dir_entry(deark *c, lctx *d, i64 pos)
{
	u8 file_type1, file_type;
	i64 ftrack, fsector;
	i64 nsectors;
	const char *file_type_str;
	char tmps[100];

	de_dbg(c, "directory entry at %d", (int)pos);
	de_dbg_indent(c, 1);

	file_type1 = de_getbyte(pos+2);
	file_type = file_type1 & 0x7;
	switch(file_type) {
	case FTYPE_DEL:
		if((file_type1&0x80)==0) {
			file_type_str = "scratched";
		}
		else {
			file_type_str = "DEL";
		}
		break;
	case FTYPE_SEQ: file_type_str = "SEQ"; break;
	case FTYPE_PRG: file_type_str = "PRG"; break;
	case FTYPE_USR: file_type_str = "USR"; break;
	case FTYPE_REL: file_type_str = "REL"; break;
	default: file_type_str = "unknown"; break;
	}

	de_dbg(c, "file type: 0x%02x (%s)", (unsigned int)file_type1, file_type_str);

	if(file_type==FTYPE_REL) {
		de_warn(c, "REL files are not supported");
		goto done;
	}
	if(file_type!=FTYPE_SEQ && file_type!=FTYPE_PRG && file_type!=FTYPE_USR) {
		goto done;
	}

	ftrack = (i64)de_getbyte(pos+3);
	fsector = (i64)de_getbyte(pos+4);
	de_dbg(c, "file starts at t=%d,s=%d", (int)ftrack, (int)fsector);

	nsectors = de_getu16le(pos+30);
	if(nsectors>0) {
		de_snprintf(tmps, sizeof(tmps), "%d to %d",
			(int)((nsectors-1)*254+1),
			(int)(nsectors*254));
	}
	else {
		de_strlcpy(tmps, "0", sizeof(tmps));
	}
	de_dbg(c, "number of sectors used: %d (expected file size=%s)",
		(int)nsectors, tmps);

	do_extract_file(c, d, pos, file_type, ftrack, fsector, nsectors);

done:
	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %edx
leaq 0x14f0a7(%rip), %rsi    # 0x1a61cc
xorl %eax, %eax
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x2, %rsi
callq 0x165060
movb %al, -0x19(%rbp)
movb -0x19(%rbp), %al
andb $0x7, %al
movb %al, -0x1a(%rbp)
movzbl -0x1a(%rbp), %eax
movq %rax, -0xb8(%rbp)
subq $0x4, %rax
ja 0x571de
movq -0xb8(%rbp), %rax
leaq 0x14efc3(%rip), %rcx    # 0x1a613c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzbl -0x19(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x5719d
leaq 0x14f04b(%rip), %rax    # 0x1a61e2
movq %rax, -0x40(%rbp)
jmp 0x571a8
leaq 0x14f048(%rip), %rax    # 0x1a61ec
movq %rax, -0x40(%rbp)
jmp 0x571e9
leaq 0x14f03f(%rip), %rax    # 0x1a61f0
movq %rax, -0x40(%rbp)
jmp 0x571e9
leaq 0x14f036(%rip), %rax    # 0x1a61f4
movq %rax, -0x40(%rbp)
jmp 0x571e9
leaq 0x148c13(%rip), %rax    # 0x19fdde
movq %rax, -0x40(%rbp)
jmp 0x571e9
leaq 0x14f020(%rip), %rax    # 0x1a61f8
movq %rax, -0x40(%rbp)
jmp 0x571e9
leaq 0x147377(%rip), %rax    # 0x19e55c
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x19(%rbp), %edx
movq -0x40(%rbp), %rcx
leaq 0x15ee8f(%rip), %rsi    # 0x1b608b
movb $0x0, %al
callq 0x15b0d0
movzbl -0x1a(%rbp), %eax
cmpl $0x4, %eax
jne 0x57223
movq -0x8(%rbp), %rdi
leaq 0x14efe5(%rip), %rsi    # 0x1a61fc
movb $0x0, %al
callq 0x15bc10
jmp 0x57353
movzbl -0x1a(%rbp), %eax
cmpl $0x1, %eax
je 0x57243
movzbl -0x1a(%rbp), %eax
cmpl $0x2, %eax
je 0x57243
movzbl -0x1a(%rbp), %eax
cmpl $0x3, %eax
je 0x57243
jmp 0x57353
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x3, %rsi
callq 0x165060
movzbl %al, %eax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x165060
movzbl %al, %eax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
movq -0x30(%rbp), %rax
movl %eax, %ecx
leaq 0x14ef86(%rip), %rsi    # 0x1a6218
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x1e, %rsi
callq 0x165280
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jle 0x572f5
leaq -0xb0(%rbp), %rdi
movq -0x38(%rbp), %rax
subq $0x1, %rax
imulq $0xfe, %rax, %rax
addq $0x1, %rax
movl %eax, %ecx
imulq $0xfe, -0x38(%rbp), %rax
movl %eax, %r8d
movl $0x64, %esi
leaq 0x14ef45(%rip), %rdx    # 0x1a6231
movb $0x0, %al
callq 0x15a980
jmp 0x5730d
leaq -0xb0(%rbp), %rdi
leaq 0x16d3fd(%rip), %rsi    # 0x1c4700
movl $0x64, %edx
callq 0x15aa30
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq -0xb0(%rbp), %rcx
leaq 0x14ef15(%rip), %rsi    # 0x1a623a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movb -0x1a(%rbp), %cl
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
movq -0x38(%rbp), %rax
movzbl %cl, %ecx
movq %rax, (%rsp)
callq 0x57370
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
addq $0xc0, %rsp
popq %rbp
retq
nopw (%rax,%rax)