// File: /workspace/github_c_makefile_star2_O3/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 0xe8a1c
testq %r15, %r15
je 0xa2d95
movq $0x0, (%r15)
movl $0x10, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r13
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeeb67
cmpl $0x4541, %eax           # imm = 0x4541
jne 0xa2fc2
movq %r15, 0x38(%rsp)
leaq 0x8fe44(%rip), %rsi     # 0x132c0c
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %r14, 0x30(%rsp)
leaq 0x2(%r14), %rax
leaq 0x20(%rsp), %r12
movq %rax, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
leaq 0x8fe16(%rip), %rsi     # 0x132c1d
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
addq $0x4, (%r12)
movq %rbx, %rdi
callq 0xf6410
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 0xefbd7
movq 0x8(%r13), %rdi
callq 0xf70f6
leaq 0x9146f(%rip), %rsi     # 0x1342c6
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
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 0xe8a1c
leaq 0x8fdb7(%rip), %rsi     # 0x132c43
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeebeb
movq %rax, (%r13)
leaq 0x8fd26(%rip), %rsi     # 0x132be3
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq $0x2, (%r14)
movq (%r13), %r12
movq %rbx, %rdi
callq 0xf6410
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 0xa2f7a
addq %r15, %r12
addq $0x12, %r12
leaq 0x28(%rsp), %r14
movq $0x0, 0x28(%rsp)
movq %rbx, %rdi
leaq 0x8fc3c(%rip), %rsi     # 0x132b56
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x10(%rsp), %rdx
movq %r12, %rcx
subq %rdx, %rcx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %rbp, %r8
movq %r14, %r9
callq 0xa300a
movl %eax, %r15d
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
testl %r15d, %r15d
je 0xa2f7a
movq 0x28(%rsp), %rdx
testq %rdx, %rdx
jle 0xa2f7a
addq 0x10(%rsp), %rdx
movq %rdx, 0x10(%rsp)
cmpq %r13, %rdx
jl 0xa2f07
movq %rbp, %rdi
callq 0xf6753
movq 0x8(%rsp), %rax
movq $0x0, 0x18(%rax)
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq 0x20(%rsp), %rax
movq 0x40(%rsp), %r13
addq (%r13), %rax
movq %rax, 0x20(%rsp)
movq 0x38(%rsp), %rcx
testq %rcx, %rcx
je 0xa2fdb
subq 0x30(%rsp), %rax
movq %rax, (%rcx)
jmp 0xa2fdb
leaq 0x8fc28(%rip), %rsi     # 0x132bf1
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xe9295
testq %r13, %r13
je 0xa2fef
movq 0x8(%r13), %rdi
callq 0xf6753
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe8be2
movl 0x18(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq