// File: /workspace/github_c_makefile_star2_O2/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 $0x118, %rsp            # imm = 0x118
movq %r8, %r14
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %rbx
leaq 0x24(%rsp), %rsi
callq 0xdebae
movq (%r15), %rcx
testl %ebp, %ebp
je 0xa1514
movq 0x18(%rbx), %rdi
movl 0x4(%r13), %edx
movq %r15, %rsi
movq %rcx, %rbp
callq 0x9fe70
movq %rax, 0x18(%rsp)
movq %r14, %rdx
movq %r13, %r14
movq (%r15), %r13
leaq 0x851f8(%rip), %rsi     # 0x1266cd
xorl %r12d, %r12d
movq %rbx, %rdi
movl %r13d, %ecx
movl %ebp, %r8d
xorl %eax, %eax
callq 0xde896
movq 0x18(%rsp), %rdx
movq %r13, 0x28(%rsp)
movq %r14, %r13
cmpq $0x10, %rdx
je 0xa152d
leaq 0x85202(%rip), %rsi     # 0x126704
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf05a
xorl %r14d, %r14d
jmp 0xa1786
leaq 0x851d6(%rip), %rsi     # 0x1266f1
movq %rbx, %rdi
movq %r14, %rdx
movq %rcx, 0x28(%rsp)
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %r12
movq %rbx, %rdi
movl %r12d, %esi
callq 0xdeba7
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r14
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
movq %r15, 0x10(%rsp)
movq %r15, %rcx
callq 0xa1369
cmpq $0x0, 0x10(%r14)
jle 0xa1580
movq %r14, %rdi
callq 0xeb877
leaq 0x851b4(%rip), %rsi     # 0x126727
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq %r14, 0x8(%rsp)
leaq 0x78(%rsp), %r14
movq %rbx, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %r15
movq %r15, %rdx
movq %r14, %rcx
callq 0xa17c1
leaq 0x85198(%rip), %rdx     # 0x12673f
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa18ab
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa18f7
movq 0x18(%rbx), %rdi
movq %r13, 0x68(%rsp)
movl 0x4(%r13), %edx
movq %r15, %rsi
callq 0x9fe70
movq %rax, %r13
leaq 0x8516b(%rip), %rsi     # 0x126747
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xde896
testq %r13, %r13
movq %r13, 0x60(%rsp)
cmovleq %r14, %r13
movq %r13, 0x70(%rsp)
xorl %eax, %eax
movq 0x68(%rsp), %rbp
cmpq %rax, 0x70(%rsp)
je 0xa1781
movq (%r15), %rcx
cmpq 0x10(%r15), %rcx
jge 0xa1745
movq %rbx, %rdi
leaq 0x85172(%rip), %rsi     # 0x126798
movq %rax, 0x18(%rsp)
movl %eax, %edx
movq 0x28(%rsp), %r8
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movl %r12d, %esi
callq 0xdeba7
movq (%r15), %r13
movq 0x10(%r15), %rax
movq %r13, 0x38(%rsp)
movq %r13, 0x30(%rsp)
movq %rax, 0x40(%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0x30(%rsp), %rdx
leaq 0xc8(%rsp), %r15
movq %r15, %rcx
callq 0xa17c1
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x75e65(%rip), %rdx     # 0x1174e7
callq 0xa18ab
movq 0x30(%rsp), %r14
movq 0x40(%rsp), %r12
movq %r14, 0x50(%rsp)
movq %r14, 0x48(%rsp)
movq %r12, 0x58(%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
leaq 0x48(%rsp), %rcx
movq %r13, %r8
callq 0xa1932
movl %eax, %r13d
movq %rbx, %rdi
movq %r15, %rsi
callq 0xa18f7
testl %r13d, %r13d
je 0xa1762
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rdx
movq %rdx, %r13
subq %rax, %r13
jle 0xa16f1
movq 0x48(%rsp), %rcx
cmpq %rdx, %rcx
jg 0xa16f4
subq %rax, %rcx
movq %rcx, %r13
jmp 0xa16f4
xorl %r13d, %r13d
addq %r14, %r13
movq %r13, 0x30(%rsp)
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
movq 0x38(%rsp), %rcx
movq %r12, %rax
subq %rcx, %rax
jle 0xa172a
cmpq %r12, %r13
movq 0x10(%rsp), %r15
jg 0xa1724
subq %rcx, %r13
movq %r13, %rax
pushq $0x1
popq %r12
jmp 0xa1735
xorl %eax, %eax
pushq $0x1
popq %r12
movq 0x10(%rsp), %r15
addq %rax, (%r15)
movq 0x18(%rsp), %rax
incq %rax
jmp 0xa1604
leaq 0x8501d(%rip), %rsi     # 0x126769
xorl %r12d, %r12d
movq %rbx, %rdi
movq 0x60(%rsp), %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0xde896
jmp 0xa1781
leaq 0x85052(%rip), %rsi     # 0x1267bb
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x8(%rsp), %r14
movl 0x24(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movq %r14, %rdi
callq 0xeaf3c
movl %r12d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq