// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/lbr.c
// Function: do_entry
static int do_entry(deark *c, lctx *d, i64 pos1, int is_dir)
{
	int retval = 0;
	int saved_indent_level;
	struct member_data *md = NULL;
	i64 crdate, chdate, crtime, chtime;

	de_dbg_indent_save(c, &saved_indent_level);
	md = de_malloc(c, sizeof(struct member_data));
	md->is_dir = is_dir;

	de_dbg(c, "%s entry at %"I64_FMT, (md->is_dir?"dir":"file"), pos1);
	de_dbg_indent(c, 1);

	md->status = de_getbyte(pos1);
	de_dbg(c, "status: 0x%02x", (UI)md->status);
	if(md->is_dir && md->status!=0x00) {
		on_bad_dir(c);
		goto done;
	}
	if(md->status==0xff) { // unused entry - marks end of directory
		goto done;
	}
	if(md->status!=0x00) { // deleted entry (should be 0xfe)
		de_dbg(c, "[deleted]");
		retval = 1;
		goto done;
	}

	md->fn = ucstring_create(c);
	if(!md->is_dir) {
		read_8_3_filename(c, d, md, pos1+1);
		de_dbg(c, "filename: \"%s\"", ucstring_getpsz_d(md->fn));
	}

	md->pos_in_sectors = de_getu16le(pos1+12);
	md->pos_in_bytes = md->pos_in_sectors * LBR_SECTOR_SIZE;
	de_dbg(c, "data offset: %"I64_FMT" (sector %"I64_FMT")", md->pos_in_bytes, md->pos_in_sectors);
	if(md->is_dir && md->pos_in_bytes!=pos1) {
		on_bad_dir(c);
		goto done;
	}

	md->len_in_sectors = de_getu16le(pos1+14);
	de_dbg(c, "length in sectors: %"I64_FMT, md->len_in_sectors);

	md->crc_reported = (u32)de_getu16le(pos1+16);
	de_dbg(c, "crc (reported): 0x%04x", (UI)md->crc_reported);

	// 18-25: timestamps - TODO
	crdate = de_getu16le(pos1+18);
	chdate = de_getu16le(pos1+20);
	crtime = de_getu16le(pos1+22);
	chtime = de_getu16le(pos1+24);
	handle_timestamp(c, d, crdate, crtime, &md->create_timestamp, "creation time");
	handle_timestamp(c, d, chdate, chtime, &md->change_timestamp, "last changed time");

	md->pad_count = de_getbyte(pos1+26);
	de_dbg(c, "pad count: %u", (UI)md->pad_count);
	if(md->pad_count>=LBR_SECTOR_SIZE || md->len_in_sectors<1) {
		md->pad_count = 0;
	}

	md->len_in_bytes_withpadding = md->len_in_sectors*LBR_SECTOR_SIZE;
	md->len_in_bytes_nopadding = md->len_in_bytes_withpadding - (i64)md->pad_count;
	de_dbg(c, "length in bytes: %"I64_FMT, md->len_in_bytes_nopadding);

	if(md->pos_in_bytes + md->len_in_bytes_nopadding > c->infile->len) {
		de_err(c, "Unexpected end of file");
		if(!md->is_dir) {
			retval = 1;
		}
		goto done;
	}

	if(md->is_dir) {
		d->dir_len_in_bytes = md->len_in_bytes_nopadding;
	}
	retval = 1;

	do_extract_member(c, d, md);

done:
	if(md) {
		ucstring_destroy(md->fn);
		de_free(c, md);
	}
	de_dbg_indent_restore(c, saved_indent_level);
	return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %ebp
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %rbx
leaq 0xc(%rsp), %rsi
callq 0xe958c
movl $0x60, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r12
movq %rax, %r14
movl %ebp, (%rax)
testl %ebp, %ebp
leaq 0xa80ce(%rip), %rax     # 0x148d2b
leaq 0x9f583(%rip), %rdx     # 0x1401e7
cmoveq %rax, %rdx
leaq 0x9113b(%rip), %rsi     # 0x131daa
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef0d5
movb %al, 0x4(%r12)
movzbl %al, %edx
leaq 0x91114(%rip), %rsi     # 0x131dba
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
cmpl $0x0, (%r12)
je 0xa0cd6
cmpb $0x0, 0x4(%r14)
je 0xa0cd6
leaq 0x9116e(%rip), %rsi     # 0x131e33
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0xa10af
movzbl 0x4(%r14), %eax
testl %eax, %eax
je 0xa0d00
cmpl $0xff, %eax
je 0xa10af
leaq 0x8193e(%rip), %rsi     # 0x12262f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
jmp 0xa10aa
movq %rbx, %rdi
callq 0xf6870
movq %rax, 0x38(%r14)
cmpl $0x0, (%r14)
jne 0xa0dc3
leaq 0x1(%r13), %rsi
movq 0x18(%rbx), %rdi
movl (%r15), %r9d
movl $0x8, %edx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0xf01b0
movq 0x38(%r14), %rdi
callq 0xf6900
movq 0x38(%r14), %rdi
cmpq $0x0, 0x10(%rdi)
jne 0xa0d4f
movl $0x5f, %esi
callq 0xf69a2
movq %rbx, %rdi
callq 0xf6870
movq %rax, %rbp
movq 0x18(%rbx), %rdi
leaq 0x9(%r13), %rsi
movl (%r15), %r9d
movl $0x3, %edx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0xf01b0
movq %rbp, %rdi
callq 0xf6900
cmpq $0x0, 0x10(%rbp)
jle 0xa0d9e
movq 0x38(%r14), %rdi
movl $0x2e, %esi
callq 0xf69a2
movq 0x38(%r14), %rdi
movq %rbp, %rsi
callq 0xf6969
movq %rbp, %rdi
callq 0xf6bb0
movq 0x38(%r14), %rdi
callq 0xf7557
leaq 0x9ac1e(%rip), %rsi     # 0x13b9d4
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0xc(%r13), %rsi
callq 0xef1ca
movq %rax, 0x10(%r14)
movq %rax, %rdx
shlq $0x7, %rdx
movq %rdx, 0x18(%r14)
leaq 0x90fe3(%rip), %rsi     # 0x131dc9
movq %rbx, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0xe9226
cmpl $0x0, (%r14)
je 0xa0e03
cmpq %r13, 0x18(%r14)
jne 0xa0cbe
movq %r15, 0x20(%rsp)
movq 0x18(%rbx), %rdi
leaq 0xe(%r13), %rsi
callq 0xef1ca
movq %rax, 0x20(%r14)
leaq 0x90fc7(%rip), %rsi     # 0x131de7
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0x10(%r13), %rsi
callq 0xef1ca
movl %eax, 0x8(%r14)
leaq 0xa3b07(%rip), %rsi     # 0x14494c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0x12(%r13), %rsi
callq 0xef1ca
movq %rax, 0x10(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x14(%r13), %rsi
callq 0xef1ca
movq %rax, 0x18(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x16(%r13), %rsi
callq 0xef1ca
movq %rax, %rbp
movq 0x18(%rbx), %rdi
leaq 0x18(%r13), %rsi
callq 0xef1ca
movq %rax, %r15
leaq 0x40(%r12), %rax
leaq 0x8cea6(%rip), %r8      # 0x12dd47
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
movq %rax, %rbp
movq %rax, %rcx
callq 0xa10e0
addq $0x50, %r12
leaq 0x90f3c(%rip), %r8      # 0x131dfe
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0xa10e0
movq 0x18(%rbx), %rdi
addq $0x1a, %r13
movq %r13, %rsi
callq 0xef0d5
movb %al, 0x5(%r14)
movzbl %al, %edx
leaq 0x90f1d(%rip), %rsi     # 0x131e10
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
cmpb $0x0, 0x5(%r14)
js 0xa0f0b
cmpq $0x0, 0x20(%r14)
jg 0xa0f10
movb $0x0, 0x5(%r14)
movq 0x20(%r14), %rdx
shlq $0x7, %rdx
movq %rdx, 0x28(%r14)
movzbl 0x5(%r14), %eax
subq %rax, %rdx
movq %rdx, 0x30(%r14)
leaq 0x90eef(%rip), %rsi     # 0x131e1e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x30(%r14), %rax
movq 0x18(%r14), %rcx
addq %rax, %rcx
movq 0x18(%rbx), %rdx
cmpq 0x18(%rdx), %rcx
movq 0x20(%rsp), %r15
jle 0xa0f73
leaq 0x71daa(%rip), %rsi     # 0x112d04
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
xorl %ebp, %ebp
cmpl $0x0, (%r14)
sete %bpl
jmp 0xa10af
cmpl $0x0, (%r14)
je 0xa0f7d
movq %rax, 0x8(%r15)
movq %rbx, %rdi
callq 0xea9a9
movq %rax, %r13
cmpl $0x0, (%r14)
je 0xa0f9a
movb $0x1, %al
movb %al, 0x9(%r13)
movb %al, 0xb(%r13)
jmp 0xa0fb0
movq 0x38(%r14), %rdx
movq %rbx, %rdi
movq %r13, %rsi
xorl %ecx, %ecx
callq 0xea9e4
movb $0x1, 0x8(%r13)
cmpb $0x0, (%rbp)
je 0xa0fbf
movups (%rbp), %xmm0
movups %xmm0, 0x28(%r13)
cmpb $0x0, (%r12)
je 0xa0fd0
movups (%r12), %xmm0
movups %xmm0, 0x18(%r13)
movq %rbx, %rdi
xorl %esi, %esi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xf037a
movq %rax, %r12
movq 0x10(%r15), %rdi
callq 0xebdc3
cmpl $0x0, (%r14)
movq 0x10(%r15), %rax
je 0xa1032
movq 0x18(%rbx), %rsi
movq 0x18(%r14), %rdx
movl $0x10, %ecx
movq %rax, %rdi
callq 0xebf09
movq 0x10(%r15), %rdi
movl $0x2, %esi
callq 0xebec6
movq 0x10(%r15), %rdi
movq 0x18(%rbx), %rsi
movq 0x18(%r14), %rdx
movq 0x28(%r14), %rcx
addq $0x12, %rdx
addq $-0x12, %rcx
jmp 0xa1072
leaq 0x50a18(%rip), %rsi     # 0xf1a51
movq %r12, %rdi
movq %rax, %rdx
callq 0xf1a12
movq 0x18(%rbx), %rdi
movq 0x18(%r14), %rsi
movq 0x30(%r14), %rdx
movq %r12, %rcx
callq 0xefabc
movq 0x10(%r15), %rdi
movq 0x18(%rbx), %rsi
movq 0x28(%r14), %rcx
movq 0x30(%r14), %rax
movq 0x18(%r14), %rdx
addq %rax, %rdx
subq %rax, %rcx
callq 0xebf09
movq 0x10(%r15), %rdi
callq 0xebe2a
movl %eax, 0xc(%r14)
leaq 0x741a8(%rip), %rsi     # 0x115233
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movq %r13, %rsi
callq 0xea9b3
movq %r12, %rdi
callq 0xf0b13
movl $0x1, %ebp
movq 0x38(%r14), %rdi
callq 0xf6bb0
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq