// File: /workspace/github_c_makefile_star2_O3/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 0x14(%rsp), %rsi
callq 0xe8a1c
movl $0x60, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r12
movq %rax, %r14
movl %ebp, (%rax)
testl %ebp, %ebp
leaq 0xa8f26(%rip), %rax     # 0x1492c3
leaq 0xa0243(%rip), %rdx     # 0x1405e7
cmoveq %rax, %rdx
leaq 0x91d7f(%rip), %rsi     # 0x13212e
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeead3
movb %al, 0x4(%r12)
movzbl %al, %edx
leaq 0x91d58(%rip), %rsi     # 0x13213e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
cmpl $0x0, (%r12)
movzbl 0x4(%r12), %eax
je 0xa0407
testl %eax, %eax
jne 0xa06a9
jmp 0xa042c
testl %eax, %eax
je 0xa042c
cmpl $0xff, %eax
je 0xa0800
leaq 0x8241a(%rip), %rsi     # 0x122837
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
jmp 0xa07fb
movq %rbx, %rdi
callq 0xf6410
movq %rax, 0x38(%r14)
cmpl $0x0, (%r14)
jne 0xa04ef
leaq 0x1(%r13), %rsi
movq 0x18(%rbx), %rdi
movl (%r15), %r9d
movl $0x8, %edx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0xefbd7
movq 0x38(%r14), %rdi
callq 0xf64a0
movq 0x38(%r14), %rdi
cmpq $0x0, 0x10(%rdi)
jne 0xa047b
movl $0x5f, %esi
callq 0xf6542
movq %rbx, %rdi
callq 0xf6410
movq %rax, %rbp
movq 0x18(%rbx), %rdi
leaq 0x9(%r13), %rsi
movl (%r15), %r9d
movl $0x3, %edx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0xefbd7
movq %rbp, %rdi
callq 0xf64a0
cmpq $0x0, 0x10(%rbp)
jle 0xa04ca
movq 0x38(%r14), %rdi
movl $0x2e, %esi
callq 0xf6542
movq 0x38(%r14), %rdi
movq %rbp, %rsi
callq 0xf6509
movq %rbp, %rdi
callq 0xf6753
movq 0x38(%r14), %rdi
callq 0xf70f6
leaq 0x9b86c(%rip), %rsi     # 0x13bd4e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0xc(%r13), %rsi
callq 0xeebc8
movq %rax, 0x10(%r14)
movq %rax, %rdx
shlq $0x7, %rdx
movq %rdx, 0x18(%r14)
leaq 0x91c3b(%rip), %rsi     # 0x13214d
movq %rbx, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0xe8617
cmpl $0x0, (%r14)
je 0xa052f
cmpq %r13, 0x18(%r14)
jne 0xa06a9
movq %r15, 0x20(%rsp)
movq 0x18(%rbx), %rdi
leaq 0xe(%r13), %rsi
callq 0xeebc8
movq %rax, 0x20(%r14)
leaq 0x91c1f(%rip), %rsi     # 0x13216b
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0x10(%r13), %rsi
callq 0xeebc8
movl %eax, 0x8(%r14)
leaq 0xa48bb(%rip), %rsi     # 0x144e2c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0x12(%r13), %rsi
callq 0xeebc8
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x14(%r13), %rsi
callq 0xeebc8
movq %rax, 0x18(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x16(%r13), %rsi
callq 0xeebc8
movq %rax, %r15
movq 0x18(%rbx), %rdi
leaq 0x18(%r13), %rsi
callq 0xeebc8
movq %rax, %rbp
leaq 0x40(%r12), %rcx
leaq 0x8da72(%rip), %r8      # 0x12e03f
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
movq %rcx, 0x8(%rsp)
callq 0xa0831
addq $0x50, %r12
leaq 0x91b95(%rip), %r8      # 0x132182
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movq %rbp, %rdx
movq %r12, %rcx
callq 0xa0831
movq 0x18(%rbx), %rdi
addq $0x1a, %r13
movq %r13, %rsi
callq 0xeead3
movb %al, 0x5(%r14)
movzbl %al, %edx
leaq 0x91b76(%rip), %rsi     # 0x132194
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
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 0xa064c
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 0x91b3d(%rip), %rsi     # 0x1321a2
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x30(%r14), %rax
movq 0x18(%r14), %rcx
addq %rax, %rcx
movq 0x18(%rbx), %rdx
cmpq 0x18(%rdx), %rcx
movq 0x20(%rsp), %r15
jle 0xa06c1
leaq 0x72684(%rip), %rsi     # 0x112d14
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
xorl %ebp, %ebp
cmpl $0x0, (%r14)
sete %bpl
jmp 0xa0800
leaq 0x91b07(%rip), %rsi     # 0x1321b7
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0xa0800
cmpl $0x0, (%r14)
je 0xa06cb
movq %rax, 0x8(%r15)
movq %rbx, %rdi
callq 0xea504
movq %rax, %r13
cmpl $0x0, (%r14)
je 0xa06e8
movb $0x1, %al
movb %al, 0x9(%r13)
movb %al, 0xb(%r13)
jmp 0xa06fe
movq 0x38(%r14), %rdx
movq %rbx, %rdi
movq %r13, %rsi
xorl %ecx, %ecx
callq 0xea53f
movb $0x1, 0x8(%r13)
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
je 0xa0710
movups (%rax), %xmm0
movups %xmm0, 0x28(%r13)
cmpb $0x0, (%r12)
je 0xa0721
movups (%r12), %xmm0
movups %xmm0, 0x18(%r13)
movq %rbx, %rdi
xorl %esi, %esi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xefda1
movq %rax, %r12
movq 0x10(%r15), %rdi
callq 0xeb7fe
cmpl $0x0, (%r14)
movq 0x10(%r15), %rax
je 0xa0783
movq 0x18(%rbx), %rsi
movq 0x18(%r14), %rdx
movl $0x10, %ecx
movq %rax, %rdi
callq 0xeb944
movq 0x10(%r15), %rdi
movl $0x2, %esi
callq 0xeb901
movq 0x10(%r15), %rdi
movq 0x18(%rbx), %rsi
movq 0x18(%r14), %rdx
movq 0x28(%r14), %rcx
addq $0x12, %rdx
addq $-0x12, %rcx
jmp 0xa07c3
leaq 0x50cc7(%rip), %rsi     # 0xf1451
movq %r12, %rdi
movq %rax, %rdx
callq 0xf1412
movq 0x18(%rbx), %rdi
movq 0x18(%r14), %rsi
movq 0x30(%r14), %rdx
movq %r12, %rcx
callq 0xef481
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 0xeb944
movq 0x10(%r15), %rdi
callq 0xeb865
movl %eax, 0xc(%r14)
leaq 0x74b07(%rip), %rsi     # 0x1152e3
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movq %r13, %rsi
callq 0xea50e
movq %r12, %rdi
callq 0xf052b
movl $0x1, %ebp
movq 0x38(%r14), %rdi
callq 0xf6753
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq