// File: /workspace/github_c_makefile_star2_O2/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, 0x18(%rsp)
movq %rdi, %rbx
leaq 0x14(%rsp), %rsi
callq 0xdebae
pushq $0x60
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r12
movq %rax, %r14
movl %ebp, (%rax)
testl %ebp, %ebp
leaq 0xa17a4(%rip), %rax     # 0x13bdf3
leaq 0x98c21(%rip), %rdx     # 0x133277
cmoveq %rax, %rdx
leaq 0x8a7e1(%rip), %rsi     # 0x124e42
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %r15
movq %rbx, %rdi
movl %r15d, %esi
callq 0xdeba7
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3eb4
movb %al, 0x4(%r12)
movzbl %al, %edx
leaq 0x8a7b8(%rip), %rsi     # 0x124e52
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
cmpl $0x0, (%r12)
movzbl 0x4(%r12), %eax
je 0x9a6bb
testl %eax, %eax
jne 0x9a955
jmp 0x9a6e3
testl %eax, %eax
je 0x9a6e3
cmpl $0xff, %eax
je 0x9a95f
leaq 0x7afa6(%rip), %rsi     # 0x115677
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movl %r15d, %ebp
jmp 0x9a95f
movq %rbx, %rdi
callq 0xeac74
movq %rax, 0x38(%r14)
cmpl $0x0, (%r14)
movq 0x18(%rsp), %r15
jne 0x9a7a3
leaq 0x1(%r13), %rsi
movq 0x18(%rbx), %rdi
movl (%r15), %r9d
pushq $0x8
popq %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0xe4c9a
movq 0x38(%r14), %rdi
callq 0xead03
movq 0x38(%r14), %rdi
cmpq $0x0, 0x10(%rdi)
jne 0x9a733
pushq $0x5f
popq %rsi
callq 0xeada5
movq %rbx, %rdi
callq 0xeac74
movq %rax, %rbp
movq 0x18(%rbx), %rdi
leaq 0x9(%r13), %rsi
movl (%r15), %r9d
pushq $0x3
popq %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0xe4c9a
movq %rbp, %rdi
callq 0xead03
cmpq $0x0, 0x10(%rbp)
jle 0x9a77e
movq 0x38(%r14), %rdi
pushq $0x2e
popq %rsi
callq 0xeada5
movq 0x38(%r14), %rdi
movq %rbp, %rsi
callq 0xead71
movq %rbp, %rdi
callq 0xeaf3c
movq 0x38(%r14), %rdi
callq 0xeb877
leaq 0x942c8(%rip), %rsi     # 0x12ea5e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0xc(%r13), %rsi
callq 0xe3fa3
movq %rax, 0x10(%r14)
movq %rax, %rdx
shlq $0x7, %rdx
movq %rdx, 0x18(%r14)
leaq 0x8a69b(%rip), %rsi     # 0x124e61
movq %rbx, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0xde896
cmpl $0x0, (%r14)
je 0x9a7e3
cmpq %r13, 0x18(%r14)
jne 0x9a955
movq 0x18(%rbx), %rdi
leaq 0xe(%r13), %rsi
callq 0xe3fa3
movq %rax, 0x20(%r14)
leaq 0x8a684(%rip), %rsi     # 0x124e7f
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0x10(%r13), %rsi
callq 0xe3fa3
movl %eax, 0x8(%r14)
leaq 0x9d1bc(%rip), %rsi     # 0x1379dc
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0x12(%r13), %rsi
callq 0xe3fa3
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x14(%r13), %rsi
callq 0xe3fa3
movq %rax, 0x20(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x16(%r13), %rsi
callq 0xe3fa3
movq %rax, %r15
movq 0x18(%rbx), %rdi
leaq 0x18(%r13), %rsi
callq 0xe3fa3
movq %rax, %rbp
leaq 0x40(%r12), %rcx
leaq 0x86553(%rip), %r8      # 0x120dcf
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
movq %rcx, 0x8(%rsp)
callq 0x9aadc
addq $0x50, %r12
leaq 0x8a5fa(%rip), %r8      # 0x124e96
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
movq %rbp, %rdx
movq %r12, %rcx
callq 0x9aadc
movq 0x18(%rbx), %rdi
addq $0x1a, %r13
movq %r13, %rsi
callq 0xe3eb4
movb %al, 0x5(%r14)
movzbl %al, %edx
leaq 0x8a5db(%rip), %rsi     # 0x124ea8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movb 0x5(%r14), %al
testb %al, %al
sets %cl
movq 0x20(%r14), %rdx
testq %rdx, %rdx
setle %sil
orb %cl, %sil
cmpb $0x1, %sil
jne 0x9a8fb
movb $0x0, 0x5(%r14)
xorl %eax, %eax
shlq $0x7, %rdx
movq %rdx, 0x28(%r14)
movzbl %al, %eax
subq %rax, %rdx
movq %rdx, 0x30(%r14)
leaq 0x8a5a2(%rip), %rsi     # 0x124eb6
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x30(%r14), %rax
movq 0x18(%r14), %rcx
addq %rax, %rcx
movq 0x18(%rbx), %rdx
cmpq 0x18(%rdx), %rcx
movq 0x18(%rsp), %r15
jle 0x9a990
leaq 0x6b3b5(%rip), %rsi     # 0x105cf4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
xorl %ebp, %ebp
cmpl $0x0, (%r14)
sete %bpl
jmp 0x9a95f
movq %rbx, %rdi
callq 0x9aace
xorl %ebp, %ebp
movq 0x38(%r14), %rdi
callq 0xeaf3c
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, (%r14)
je 0x9a99a
movq %rax, 0x8(%r15)
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, %r13
cmpl $0x0, (%r14)
pushq $0x1
popq %rbp
je 0x9a9ba
movb $0x1, %al
movb %al, 0x9(%r13)
movb %al, 0xb(%r13)
jmp 0x9a9d0
movq 0x38(%r14), %rdx
movq %rbx, %rdi
movq %r13, %rsi
xorl %ecx, %ecx
callq 0xdfd55
movb $0x1, 0x8(%r13)
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
je 0x9a9e2
movups (%rax), %xmm0
movups %xmm0, 0x28(%r13)
cmpb $0x0, (%r12)
je 0x9a9f3
movups (%r12), %xmm0
movups %xmm0, 0x18(%r13)
movq %rbx, %rdi
xorl %esi, %esi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %r12
movq 0x10(%r15), %rdi
callq 0xe0e44
cmpl $0x0, (%r14)
movq 0x10(%r15), %rax
je 0x9aa51
movq 0x18(%rbx), %rsi
movq 0x18(%r14), %rdx
pushq $0x10
popq %rcx
movq %rax, %rdi
callq 0xe0f33
movq 0x10(%r15), %rdi
pushq $0x2
popq %rsi
callq 0xe0f29
movq 0x10(%r15), %rdi
movq 0x18(%rbx), %rsi
movq 0x18(%r14), %rdx
movq 0x28(%r14), %rcx
addq $0x12, %rdx
addq $-0x12, %rcx
jmp 0x9aa91
leaq 0x4b869(%rip), %rsi     # 0xe62c1
movq %r12, %rdi
movq %rax, %rdx
callq 0xe629a
movq 0x18(%rbx), %rdi
movq 0x18(%r14), %rsi
movq 0x30(%r14), %rdx
movq %r12, %rcx
callq 0xe45f4
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 0xe0f33
movq 0x10(%r15), %rdi
callq 0xe0e95
movl %eax, 0xc(%r14)
leaq 0x6d7ad(%rip), %rsi     # 0x108257
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movq %r13, %rsi
callq 0xdfd24
movq %r12, %rdi
callq 0xe5591
jmp 0x9a95f