// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/os2ea.c
// Function: eadata_do_ea_sector_by_offset
static void eadata_do_ea_sector_by_offset(deark *c, struct eadata_ctx *d, i64 pos1,
	i64 *pbytes_consumed1)
{
	i64 n;
	i64 pos;
	struct easector_ctx *md = NULL;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	if(pbytes_consumed1) {
		*pbytes_consumed1 = 0;
	}
	md = de_malloc(c, sizeof(struct easector_ctx));

	if(!eadata_is_ea_sector_at_offset(c, d, pos1, 0)) {
		de_err(c, "EA sector not found at %"I64_FMT, pos1);
		goto done;
	}

	de_dbg(c, "EA sector at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);
	pos = pos1+2;
	n = de_getu16le_p(&pos);
	de_dbg(c, "sector number (consistency check): %u", (UI)n);

	pos += 4;

	md->fn = ucstring_create(c);
	dbuf_read_to_ucstring(c->infile, pos, 12, md->fn, DE_CONVFLAG_STOP_AT_NUL, d->input_encoding);
	de_dbg(c, "file name: \"%s\"", ucstring_getpsz_d(md->fn));
	pos += 12;

	pos += 2;
	pos += 4;

	eadata_do_ea_data(c, d, md, pos);
	pos += md->ea_data_len;

	if(pbytes_consumed1) {
		*pbytes_consumed1 = pos - pos1;
	}

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, 0x8(%rsp)
movq %rdi, %rbx
leaq 0x18(%rsp), %rsi
callq 0xe958c
testq %r15, %r15
je 0xa364e
movq $0x0, (%r15)
movl $0x10, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r13
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xef169
cmpl $0x4541, %eax           # imm = 0x4541
jne 0xa387b
movq %r15, 0x38(%rsp)
leaq 0x8f1f3(%rip), %rsi     # 0x132874
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq %r14, 0x30(%rsp)
leaq 0x2(%r14), %rax
leaq 0x20(%rsp), %r12
movq %rax, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef1ed
leaq 0x8f1c5(%rip), %rsi     # 0x132885
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
addq $0x4, (%r12)
movq %rbx, %rdi
callq 0xf6870
movq %rax, 0x8(%r13)
movq 0x18(%rbx), %rdi
movq (%r12), %rsi
movq 0x8(%rsp), %rcx
movl (%rcx), %r9d
movl $0xc, %edx
movq %rax, %rcx
movl $0x1, %r8d
callq 0xf01b0
movq 0x8(%r13), %rdi
callq 0xf7557
leaq 0x907be(%rip), %rsi     # 0x133ece
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq (%r12), %r15
leaq 0x12(%r15), %rbp
movq %rbp, (%r12)
leaq 0x10(%rsp), %r14
movq %rbp, (%r14)
leaq 0x1c(%rsp), %rsi
movq %rbx, %rdi
callq 0xe958c
leaq 0x8f166(%rip), %rsi     # 0x1328ab
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xef1ed
movq %rax, (%r13)
leaq 0x8f0d5(%rip), %rsi     # 0x13284b
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
addq $0x2, (%r14)
movq (%r13), %r12
movq %rbx, %rdi
callq 0xf6870
movq %rax, %rbp
movq %r13, 0x40(%rsp)
movq 0x8(%rsp), %rax
movq %r13, 0x18(%rax)
leaq (%r12,%r15), %r13
addq $0xe, %r13
movq (%r14), %rdx
cmpq %r13, %rdx
jge 0xa3833
addq %r15, %r12
addq $0x12, %r12
leaq 0x28(%rsp), %r14
movq $0x0, 0x28(%rsp)
movq %rbx, %rdi
leaq 0x8efeb(%rip), %rsi     # 0x1327be
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x10(%rsp), %rdx
movq %r12, %rcx
subq %rdx, %rcx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %rbp, %r8
movq %r14, %r9
callq 0xa38c3
movl %eax, %r15d
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
testl %r15d, %r15d
je 0xa3833
movq 0x28(%rsp), %rdx
testq %rdx, %rdx
jle 0xa3833
addq 0x10(%rsp), %rdx
movq %rdx, 0x10(%rsp)
cmpq %r13, %rdx
jl 0xa37c0
movq %rbp, %rdi
callq 0xf6bb0
movq 0x8(%rsp), %rax
movq $0x0, 0x18(%rax)
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movq 0x20(%rsp), %rax
movq 0x40(%rsp), %r13
addq (%r13), %rax
movq %rax, 0x20(%rsp)
movq 0x38(%rsp), %rcx
testq %rcx, %rcx
je 0xa388f
subq 0x30(%rsp), %rax
movq %rax, (%rcx)
jmp 0xa388f
leaq 0x8efd7(%rip), %rsi     # 0x132859
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xe9df7
testq %r13, %r13
je 0xa38a8
movq 0x8(%r13), %rdi
callq 0xf6bb0
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe9752
movl 0x18(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq