// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/psd.c
// Function: read_descriptor
static int read_descriptor(deark *c, lctx *d, zztype *zz, int has_version, const char *dscrname)
{
	de_ucstring *name_from_classid = NULL;
	struct flexible_id classid;
	i64 ver_pos = 0;
	i64 dscr_pos;
	i64 num_items;
	i64 i;
	int ret;
	int retval = 0;
	i64 dv = 16;
	zztype czz;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);

	if(has_version) {
		ver_pos = zz->pos;
		dv = psd_getu32zz(zz);
	}

	dscr_pos = zz->pos;

	if(has_version) {
		de_dbg(c, "descriptor%s at %d (version# at %d)", dscrname, (int)dscr_pos, (int)ver_pos);
	}
	else {
		de_dbg(c, "descriptor%s at %d", dscrname, (int)dscr_pos);
	}

	if(dv!=16) {
		de_warn(c, "Unsupported descriptor version: %d", (int)dv);
		goto done;
	}

	de_dbg_indent(c, 1);

	name_from_classid = ucstring_create(c);
	read_unicode_string(c, d, name_from_classid, zz);
	if(name_from_classid->len > 0) {
		de_dbg(c, "name from classID: \"%s\"", ucstring_getpsz_d(name_from_classid));
	}

	read_flexible_id_zz(c, d, zz, &classid);
	dbg_print_flexible_id(c, d, &classid, "classID");
	flexible_id_free_contents(c, &classid);

	num_items = psd_getu32zz(zz);
	de_dbg(c, "number of items in descriptor: %d", (int)num_items);

	// Descriptor items
	for(i=0; i<num_items; i++) {
		if(zz->pos >= zz->endpos) {
			de_dbg(c, "[Expected %d descriptor items, only found %d.]", (int)num_items, (int)i);
			goto done;
		}
		de_dbg(c, "item[%d] at %d (for descriptor@%d)", (int)i, (int)zz->pos, (int)dscr_pos);
		de_dbg_indent(c, 1);
		zz_init(&czz, zz);
		ret = do_descriptor_item(c, d, &czz);
		if(!ret) {
			de_dbg(c, "[Failed to fully decode descriptor item.]");
		}
		de_dbg_indent(c, -1);
		if(!ret) goto done;
		zz->pos += zz_used(&czz);
	}

	retval = 1;

done:
	de_dbg_indent_restore(c, saved_indent_level);
	ucstring_destroy(name_from_classid);
	return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %r8, (%rsp)
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x24(%rsp), %rsi
callq 0xe958c
testl %ebp, %ebp
movq %rbx, 0x10(%rsp)
je 0xa81c2
movq (%r14), %r12
movq 0x18(%rbx), %rdi
movl 0x4(%r15), %edx
movq %r12, %rsi
callq 0xef614
movq %rax, %r13
addq $0x4, (%r14)
jmp 0xa81cb
movl $0x10, %r13d
xorl %r12d, %r12d
movq (%r14), %rbx
testl %ebp, %ebp
je 0xa81f3
leaq 0x8b3d4(%rip), %rsi     # 0x1335ad
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq (%rsp), %rdx
movl %ebx, %ecx
movl %r12d, %r8d
xorl %eax, %eax
callq 0xe9226
jmp 0xa820f
leaq 0x8b3d7(%rip), %rsi     # 0x1335d1
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq (%rsp), %rdx
movl %ebx, %ecx
xorl %eax, %eax
callq 0xe9226
cmpq $0x10, %r13
jne 0xa843a
movq %rbx, (%rsp)
movl $0x1, %r13d
movq %rbp, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbp, %rdi
callq 0xf6870
movq %rax, %rbx
movq %rbp, %rdi
movq %r15, %rsi
movq %rax, %rdx
movq %r14, %rcx
callq 0xa803f
cmpq $0x0, 0x10(%rbx)
jle 0xa826f
movq %rbx, %rdi
callq 0xf7557
leaq 0x8b3a5(%rip), %rsi     # 0x133607
movq %rbp, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, 0x8(%rsp)
leaq 0x68(%rsp), %r12
movq %rbp, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0xa84c7
leaq 0x8b38e(%rip), %rdx     # 0x13361f
movq %rbp, %rdi
movq %r12, %rsi
callq 0xa85b9
movq %rbp, %rdi
movq %r12, %rsi
callq 0xa8605
movq 0x18(%rbp), %rdi
movl 0x4(%r15), %edx
movq (%r14), %rsi
callq 0xef614
movq %rax, %rbx
addq $0x4, (%r14)
leaq 0x8b362(%rip), %rsi     # 0x133627
movq %rbp, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, 0x28(%rsp)
testq %rbx, %rbx
jle 0xa8499
xorl %r12d, %r12d
movq (%rsp), %r8
movq %r14, 0x60(%rsp)
movq %r15, 0x18(%rsp)
movq (%r14), %rcx
cmpq 0x10(%r14), %rcx
jge 0xa847d
movq %rbp, %rdi
leaq 0x8b371(%rip), %rsi     # 0x133678
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbp, %rdi
movl $0x1, %esi
callq 0xe9585
movq (%r14), %rbx
movq 0x10(%r14), %rax
movq %rbx, 0x38(%rsp)
movq %rbx, 0x30(%rsp)
movq %rax, 0x40(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
leaq 0x30(%rsp), %rdx
leaq 0xb8(%rsp), %r14
movq %r14, %rcx
callq 0xa84c7
movq %rbp, %rdi
movq %r14, %rsi
leaq 0x7c16b(%rip), %rdx     # 0x1244c7
callq 0xa85b9
movq 0x30(%rsp), %r13
movq %r15, %rsi
movq 0x40(%rsp), %r15
movq %r13, 0x50(%rsp)
movq %r13, 0x48(%rsp)
movq %r15, 0x58(%rsp)
movq %rbp, %rdi
movq %r14, %rdx
leaq 0x48(%rsp), %rcx
movq %rbx, %r8
callq 0xa8646
movl %eax, %ebx
movq %rbp, %rdi
movq %r14, %rsi
callq 0xa8605
testl %ebx, %ebx
je 0xa8455
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %rsi
movq %rsi, %rax
subq %rcx, %rax
jle 0xa83c9
movq 0x48(%rsp), %rdx
cmpq %rsi, %rdx
jg 0xa83cb
subq %rcx, %rdx
movq %rdx, %rax
jmp 0xa83cb
xorl %eax, %eax
addq %r13, %rax
movq %rax, 0x30(%rsp)
testl %ebx, %ebx
je 0xa8455
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x38(%rsp), %rcx
movq %r15, %rax
subq %rcx, %rax
jle 0xa8411
movq 0x30(%rsp), %rdx
cmpq %r15, %rdx
movq (%rsp), %r8
jg 0xa840a
subq %rcx, %rdx
movq %rdx, %rax
movq 0x18(%rsp), %r15
jmp 0xa841c
xorl %eax, %eax
movq 0x18(%rsp), %r15
movq (%rsp), %r8
movq 0x60(%rsp), %r14
addq %rax, (%r14)
incq %r12
cmpq %r12, 0x28(%rsp)
jne 0xa82f0
movl $0x1, %r13d
jmp 0xa8499
leaq 0x8b1a3(%rip), %rsi     # 0x1335e4
xorl %ebx, %ebx
movq %rbp, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe9b27
xorl %r13d, %r13d
jmp 0xa849e
leaq 0x8b23f(%rip), %rsi     # 0x13369b
xorl %r13d, %r13d
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbp, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
jmp 0xa8499
leaq 0x8b1c5(%rip), %rsi     # 0x133649
xorl %r13d, %r13d
movq %rbp, %rdi
movq 0x28(%rsp), %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0xe9226
movq 0x8(%rsp), %rbx
movl 0x24(%rsp), %esi
movq %rbp, %rdi
callq 0xe9595
movq %rbx, %rdi
callq 0xf6bb0
movl %r13d, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq