// File: /workspace/github_c_makefile_star2_O2/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, %r12
movq %rdx, %r14
movq %rsi, 0x8(%rsp)
movq %rdi, %rbx
leaq 0x18(%rsp), %rsi
callq 0xdebae
testq %r12, %r12
je 0x9cf28
andq $0x0, (%r12)
pushq $0x10
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r13
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x9d64c
testl %eax, %eax
je 0x9d13c
movq %r12, 0x38(%rsp)
leaq 0x889b5(%rip), %rsi     # 0x12590c
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %r12
movq %rbx, %rdi
movl %r12d, %esi
callq 0xdeba7
movq %r14, 0x30(%rsp)
leaq 0x2(%r14), %rax
leaq 0x20(%rsp), %r14
movq %rax, (%r14)
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xe3fc4
leaq 0x88986(%rip), %rsi     # 0x12591d
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
addq $0x4, (%r14)
movq %rbx, %rdi
callq 0xeac74
movq %rax, 0x8(%r13)
movq 0x18(%rbx), %rdi
movq (%r14), %rsi
movq 0x8(%rsp), %rcx
movl (%rcx), %r9d
pushq $0xc
popq %rdx
movq %rax, %rcx
movl %r12d, %r8d
callq 0xe4c9a
movq 0x8(%r13), %rdi
callq 0xeb877
leaq 0x8a00e(%rip), %rsi     # 0x126fee
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq (%r14), %rbp
leaq 0x12(%rbp), %r15
movq %r15, (%r14)
leaq 0x10(%rsp), %r14
movq %r15, (%r14)
leaq 0x1c(%rsp), %rsi
movq %rbx, %rdi
callq 0xdebae
leaq 0x88930(%rip), %rsi     # 0x125943
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movl %r12d, %esi
callq 0xdeba7
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xe3fc4
movq %rax, (%r13)
leaq 0x888a1(%rip), %rsi     # 0x1258e3
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
addq $0x2, (%r14)
movq (%r13), %r15
leaq (%r15,%rbp), %r14
addq $0x12, %r14
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r12
movq %r13, 0x40(%rsp)
movq 0x8(%rsp), %rax
movq %r13, 0x18(%rax)
leaq 0xe(%r15,%rbp), %r15
leaq 0x10(%rsp), %rax
movq (%rax), %rdx
pushq $-0x1
popq %rbp
cmpq %r15, %rdx
jge 0x9d0f7
andq $0x0, 0x28(%rsp)
movq %rbx, %rdi
leaq 0x887b9(%rip), %rsi     # 0x125856
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x10(%rsp), %rdx
movq %r14, %rcx
subq %rdx, %rcx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %r8
leaq 0x28(%rsp), %r9
callq 0x9d184
movl %eax, %r13d
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
testl %r13d, %r13d
je 0x9d0f7
movq 0x28(%rsp), %rdx
testq %rdx, %rdx
jle 0x9d0f7
addq 0x10(%rsp), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x9d088
movq %r12, %rdi
callq 0xeaf3c
movq 0x8(%rsp), %rax
andq $0x0, 0x18(%rax)
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movq 0x20(%rsp), %rax
movq 0x40(%rsp), %r13
addq (%r13), %rax
movq %rax, 0x20(%rsp)
movq 0x38(%rsp), %rcx
testq %rcx, %rcx
je 0x9d155
subq 0x30(%rsp), %rax
movq %rax, (%rcx)
jmp 0x9d155
leaq 0x887ae(%rip), %rsi     # 0x1258f1
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xdf2a5
testq %r13, %r13
je 0x9d169
movq 0x8(%r13), %rdi
callq 0xeaf3c
movq %rbx, %rdi
movq %r13, %rsi
callq 0xded32
movl 0x18(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq