// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movl $0x60, %esi
callq 0x15b780
movq %rax, -0x30(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl (%rax), %ecx
leaq 0xe92c8(%rip), %rdx     # 0x1d4e07
leaq 0xe06f1(%rip), %rax     # 0x1cc237
cmpl $0x0, %ecx
cmovneq %rax, %rdx
movq -0x18(%rbp), %rcx
leaq 0xd1f8d(%rip), %rsi     # 0x1bdae5
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x165060
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movzbl 0x4(%rax), %edx
leaq 0xd1f5b(%rip), %rsi     # 0x1bdaf5
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0xebbc5
movq -0x30(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x0, %eax
je 0xebbc5
movq -0x8(%rbp), %rdi
callq 0xebf50
jmp 0xebf12
movq -0x30(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0xff, %eax
jne 0xebbd9
jmp 0xebf12
movq -0x30(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x0, %eax
je 0xebc04
movq -0x8(%rbp), %rdi
leaq 0xc269b(%rip), %rsi     # 0x1ae28c
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x20(%rbp)
jmp 0xebf12
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xebc64
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rcx
addq $0x1, %rcx
callq 0xebf80
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x172650
movq -0x58(%rbp), %rdi
movq %rax, %rdx
leaq 0xdb926(%rip), %rsi     # 0x1c7583
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0xc, %rsi
callq 0x165280
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rcx
shlq $0x7, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rcx
leaq 0xd1e51(%rip), %rsi     # 0x1bdb04
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0xebcdf
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
cmpq -0x18(%rbp), %rax
je 0xebcdf
movq -0x8(%rbp), %rdi
callq 0xebf50
jmp 0xebf12
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0xe, %rsi
callq 0x165280
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0xd1e10(%rip), %rsi     # 0x1bdb22
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x10, %rsi
callq 0x165280
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0xe4c03(%rip), %rsi     # 0x1d094c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x12, %rsi
callq 0x165280
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x14, %rsi
callq 0x165280
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x16, %rsi
callq 0x165280
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x18, %rsi
callq 0x165280
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x30(%rbp), %r8
addq $0x40, %r8
leaq 0xcdd8a(%rip), %r9      # 0x1b9b5d
callq 0xec080
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %r8
addq $0x50, %r8
leaq 0xd1d42(%rip), %r9      # 0x1bdb39
callq 0xec080
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x1a, %rsi
callq 0x165060
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, 0x5(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movzbl 0x5(%rax), %edx
leaq 0xd1d1e(%rip), %rsi     # 0x1bdb4b
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
movzbl 0x5(%rax), %eax
cmpl $0x80, %eax
jge 0xebe4e
movq -0x30(%rbp), %rax
cmpq $0x1, 0x20(%rax)
jge 0xebe56
movq -0x30(%rbp), %rax
movb $0x0, 0x5(%rax)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rcx
shlq $0x7, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x30(%rbp), %rax
movzbl 0x5(%rax), %eax
subq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdx
leaq 0xd1cc1(%rip), %rsi     # 0x1bdb59
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rcx
addq 0x30(%rcx), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xebee1
movq -0x8(%rbp), %rdi
leaq 0xb2ef7(%rip), %rsi     # 0x19edbf
movb $0x0, %al
callq 0x15bfb0
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xebedf
movl $0x1, -0x20(%rbp)
jmp 0xebf12
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0xebefa
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x1, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0xec170
cmpq $0x0, -0x30(%rbp)
je 0xebf33
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x15b5a0
movl -0x20(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)