// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x88(%rbp)
movl $0x0, -0xa8(%rbp)
movq $0x10, -0xb0(%rbp)
movq -0x8(%rbp), %rdi
leaq -0xcc(%rbp), %rsi
callq 0x15b580
cmpl $0x0, -0x1c(%rbp)
je 0xf5bd9
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
callq 0xf3330
movq %rax, -0xb0(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x90(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0xf5c18
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x90(%rbp), %rax
movl %eax, %ecx
movq -0x88(%rbp), %rax
movl %eax, %r8d
leaq 0xc97dd(%rip), %rsi     # 0x1bf3ec
movb $0x0, %al
callq 0x15b0d0
jmp 0xf5c37
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x90(%rbp), %rax
movl %eax, %ecx
leaq 0xc97e0(%rip), %rsi     # 0x1bf410
movb $0x0, %al
callq 0x15b0d0
cmpq $0x10, -0xb0(%rbp)
je 0xf5c61
movq -0x8(%rbp), %rdi
movq -0xb0(%rbp), %rax
movl %eax, %edx
leaq 0xc97ce(%rip), %rsi     # 0x1bf423
movb $0x0, %al
callq 0x15bc10
jmp 0xf5e69
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rcx
callq 0xf54d0
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jle 0xf5cc8
movq -0x8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x30(%rbp), %rdi
callq 0x172650
movq -0xd8(%rbp), %rdi
movq %rax, %rdx
leaq 0xc9785(%rip), %rsi     # 0x1bf446
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x80(%rbp), %rcx
callq 0xf5f70
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x80(%rbp), %rdx
leaq 0xc976e(%rip), %rcx     # 0x1bf45e
callq 0xf5fc0
movq -0x8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xf6050
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
callq 0xf3330
movq %rax, -0x98(%rbp)
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rax
movl %eax, %edx
leaq 0xc9731(%rip), %rsi     # 0x1bf466
movb $0x0, %al
callq 0x15b0d0
movq $0x0, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
cmpq -0x98(%rbp), %rax
jge 0xf5e5f
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jl 0xf5d95
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rax
movl %eax, %edx
movq -0xa0(%rbp), %rax
movl %eax, %ecx
leaq 0xc96ff(%rip), %rsi     # 0x1bf488
movb $0x0, %al
callq 0x15b0d0
jmp 0xf5e69
movq -0x8(%rbp), %rdi
movq -0xa0(%rbp), %rax
movl %eax, %edx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, %ecx
movq -0x90(%rbp), %rax
movl %eax, %r8d
leaq 0xc96fb(%rip), %rsi     # 0x1bf4b7
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x18(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0xf3580
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0xc8(%rbp), %rdx
callq 0xf60c0
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
jne 0xf5e16
movq -0x8(%rbp), %rdi
leaq 0xc96cb(%rip), %rsi     # 0x1bf4da
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
cmpl $0x0, -0xa4(%rbp)
jne 0xf5e2f
jmp 0xf5e69
leaq -0xc8(%rbp), %rdi
callq 0xf3820
movq %rax, %rcx
movq -0x18(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
jmp 0xf5d47
movl $0x1, -0xa8(%rbp)
movq -0x8(%rbp), %rdi
movl -0xcc(%rbp), %esi
callq 0x15b5a0
movq -0x30(%rbp), %rdi
callq 0x171750
movl -0xa8(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq