// File: /workspace/github_c_makefile_star2_O3/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, %r12
movl %ecx, %ebp
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x14(%rsp), %rsi
callq 0xe8a1c
movq (%r13), %r14
testl %ebp, %ebp
je 0xa77d8
movq 0x18(%rbx), %rdi
movl 0x4(%r15), %edx
movq %r14, %rsi
callq 0xeeff3
movq %r12, %rdx
movq %rax, %r12
movq (%r13), %rbp
addq $0x4, %rbp
movq %rbp, (%r13)
leaq 0x8c203(%rip), %rsi     # 0x1339a5
movq %rbx, %rdi
movl %ebp, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0xe8617
movq %rbp, %r14
cmpq $0x10, %r12
je 0xa77ef
leaq 0x8c21b(%rip), %rsi     # 0x1339dc
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8faa
xorl %r14d, %r14d
xorl %ebp, %ebp
jmp 0xa7a4f
leaq 0x8c1ea(%rip), %rsi     # 0x1339c9
movq %rbx, %rdi
movq %r12, %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0xe8617
movl $0x1, %ebp
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r12
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
movq %r13, %rcx
callq 0xa7614
cmpq $0x0, 0x10(%r12)
jle 0xa7841
movq %r12, %rdi
callq 0xf70f6
leaq 0x8c1cb(%rip), %rsi     # 0x1339ff
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq %r12, 0x8(%rsp)
leaq 0xb8(%rsp), %r12
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0xa7a77
leaq 0x8c1b1(%rip), %rdx     # 0x133a17
movq %rbx, %rdi
movq %r12, %rsi
callq 0xa7b69
movq %rbx, %rdi
movq %r12, %rsi
callq 0xa7bb5
movq 0x18(%rbx), %rdi
movl 0x4(%r15), %edx
movq (%r13), %rsi
callq 0xeeff3
movq %rax, %r12
addq $0x4, (%r13)
leaq 0x8c183(%rip), %rsi     # 0x133a1f
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
movq %r12, 0x18(%rsp)
testq %r12, %r12
jle 0xa7a4a
movq %r15, 0x58(%rsp)
movq (%r13), %rcx
xorl %eax, %eax
movq %r14, 0x50(%rsp)
cmpq 0x10(%r13), %rcx
jge 0xa7a0b
movq %rbx, %rdi
leaq 0x8c195(%rip), %rsi     # 0x133a70
movq %rax, 0x60(%rsp)
movl %eax, %edx
movl %r14d, %r8d
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq (%r13), %rbp
movq 0x10(%r13), %rax
movq %rbp, 0x28(%rsp)
movq %rbp, 0x20(%rsp)
movq %rax, 0x30(%rsp)
movq %rbx, %rdi
movq 0x58(%rsp), %r14
movq %r14, %rsi
leaq 0x20(%rsp), %rdx
leaq 0x68(%rsp), %r15
movq %r15, %rcx
callq 0xa7a77
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x7cdad(%rip), %rdx     # 0x1246e7
callq 0xa7b69
movq 0x20(%rsp), %r12
movq 0x30(%rsp), %r15
movq %r12, 0x40(%rsp)
movq %r12, 0x38(%rsp)
movq %r15, 0x48(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x68(%rsp), %rdx
leaq 0x38(%rsp), %rcx
movq %rbp, %r8
callq 0xa7bf6
movl %eax, %ebp
movq %rbx, %r14
movq %rbx, %rdi
leaq 0x68(%rsp), %rsi
callq 0xa7bb5
testl %ebp, %ebp
je 0xa7a27
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rdx
movq %rdx, %rbp
subq %rax, %rbp
jle 0xa79ae
movq 0x38(%rsp), %rcx
cmpq %rdx, %rcx
jg 0xa79b0
subq %rax, %rcx
movq %rcx, %rbp
jmp 0xa79b0
xorl %ebp, %ebp
movq %r14, %rbx
addq %r12, %rbp
movq %rbp, 0x20(%rsp)
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x28(%rsp), %rax
movq %r15, %rcx
subq %rax, %rcx
movq 0x50(%rsp), %r14
jle 0xa79e7
cmpq %r15, %rbp
jg 0xa79e9
subq %rax, %rbp
movq %rbp, %rcx
jmp 0xa79e9
xorl %ecx, %ecx
addq (%r13), %rcx
movq %rcx, (%r13)
movq 0x60(%rsp), %rax
incq %rax
cmpq %rax, 0x18(%rsp)
jne 0xa78c7
movl $0x1, %ebp
jmp 0xa7a4a
leaq 0x8c02f(%rip), %rsi     # 0x133a41
xorl %ebp, %ebp
movq %rbx, %rdi
movq 0x18(%rsp), %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0xe8617
jmp 0xa7a4a
leaq 0x8c065(%rip), %rsi     # 0x133a93
xorl %ebp, %ebp
movq %r14, %rbx
movq %r14, %rdi
xorl %eax, %eax
callq 0xe8617
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x8(%rsp), %r14
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq %r14, %rdi
callq 0xf6753
movl %ebp, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq