// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/applesd.c
// Function: do_finder_xattr
static void do_finder_xattr(deark *c, lctx *d, struct entry_struct *e)
{
	i64 total_size;
	i64 data_start;
	i64 data_length;
	i64 num_attrs;
	i64 k;
	unsigned int flags;
	i64 pos = e->offset;
	int saved_indent_level;
	struct de_stringreaderdata *name = NULL;

	de_dbg_indent_save(c, &saved_indent_level);
	pos += 32; // original finder data

	// At this point, we are most likely at file offset 82, and there are
	// normally 2 padding bytes for alignment. (This is really a hybrid format
	// that violates the AppleDouble conventions.)
	// I don't know for sure what we should do if we're somehow not at an
	// offset such that (offset mod 4)==2.
	pos = de_pad_to_4(pos);

	de_dbg(c, "xattr table at %"I64_FMT, pos);
	de_dbg_indent(c, 1);
	pos += 4; // magic "ATTR"
	pos += 4; // debug_tag
	total_size = de_getu32be_p(&pos);
	de_dbg(c, "total size: %"I64_FMT, total_size);
	data_start = de_getu32be_p(&pos);
	de_dbg(c, "data start: %"I64_FMT, data_start);
	data_length = de_getu32be_p(&pos);
	de_dbg(c, "data length: %"I64_FMT, data_length);
	pos += 3*4; // reserved
	flags = (unsigned int)de_getu16be_p(&pos);
	de_dbg(c, "flags: 0x%04x", flags);
	num_attrs = de_getu16be_p(&pos);
	de_dbg(c, "num attrs: %d", (int)num_attrs);

	for(k=0; k<num_attrs; k++) {
		i64 entry_dpos, entry_dlen, entry_nlen;
		unsigned int entry_flags;

		// "Entries are aligned on 4 byte boundaries"
		pos = de_pad_to_4(pos);

		if(pos >= c->infile->len) goto done;

		// TODO:  but I don't know
		// what that means for the decoder.

		de_dbg(c, "xattr entry[%d] at %"I64_FMT, (int)k, pos);
		de_dbg_indent(c, 1);
		entry_dpos = de_getu32be_p(&pos);
		de_dbg(c, "dpos: %"I64_FMT, entry_dpos);
		entry_dlen = de_getu32be_p(&pos);
		de_dbg(c, "dlen: %"I64_FMT, entry_dlen);
		entry_flags = (unsigned int)de_getu16be_p(&pos);
		de_dbg(c, "flags: 0x%04x", entry_flags);
		entry_nlen = (i64)de_getbyte_p(&pos);

		if(name) {
			de_destroy_stringreaderdata(c, name);
		}
		name = dbuf_read_string(c->infile, pos, entry_nlen, entry_nlen,
			DE_CONVFLAG_STOP_AT_NUL, DE_ENCODING_UTF8);
		de_dbg(c, "name: \"%s\"", ucstring_getpsz_d(name->str));

		do_xattr_entry(c, d, name, entry_dpos, entry_dlen);
		pos += entry_nlen;
		de_dbg_indent(c, -1);
	}

done:
	de_destroy_stringreaderdata(c, name);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x54(%rbp), %rsi
callq 0x15b580
movq -0x50(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x15ce30
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rdx
leaq 0x16566f(%rip), %rsi    # 0x1a2a5f
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x50(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x50(%rbp), %rsi
callq 0x1654b0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x165631(%rip), %rsi    # 0x1a2a72
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x50(%rbp), %rsi
callq 0x1654b0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x165616(%rip), %rsi    # 0x1a2a82
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x50(%rbp), %rsi
callq 0x1654b0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x1655fb(%rip), %rsi    # 0x1a2a92
movb $0x0, %al
callq 0x15b0d0
movq -0x50(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x50(%rbp), %rsi
callq 0x165210
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %edx
leaq 0x17778f(%rip), %rsi    # 0x1b4c5b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x50(%rbp), %rsi
callq 0x165210
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0x1655aa(%rip), %rsi    # 0x1a2aa3
movb $0x0, %al
callq 0x15b0d0
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0x3d6ac
movq -0x50(%rbp), %rdi
callq 0x15ce30
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0x3d53a
jmp 0x3d6ae
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
movq -0x50(%rbp), %rcx
leaq 0x165562(%rip), %rsi    # 0x1a2ab1
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x50(%rbp), %rsi
callq 0x1654b0
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rdx
leaq 0x1992b6(%rip), %rsi    # 0x1d683e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x50(%rbp), %rsi
callq 0x1654b0
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
movq -0x70(%rbp), %rdx
leaq 0x193df1(%rip), %rsi    # 0x1d13a4
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x50(%rbp), %rsi
callq 0x165210
movl %eax, -0x7c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x7c(%rbp), %edx
leaq 0x17767f(%rip), %rsi    # 0x1b4c5b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x50(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x3d60f
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x166830
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x50(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq -0x78(%rbp), %rcx
movl $0x1, %r8d
movl $0x2, %r9d
callq 0x1664c0
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x172650
movq -0x88(%rbp), %rdi
movq %rax, %rdx
leaq 0x170b6f(%rip), %rsi    # 0x1ae1d0
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x68(%rbp), %rcx
movq -0x70(%rbp), %r8
callq 0x3d6d0
movq -0x78(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x3d508
jmp 0x3d6ae
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x166830
movq -0x8(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x15b5a0
addq $0x90, %rsp
popq %rbp
retq