// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/iccprofile.c
// Function: typedec_desc
static void typedec_desc(deark *c, struct typedec_params *p)
{
	de_ucstring *s = NULL;
	i64 invdesclen, uloclen;
	i64 langcode;
	i64 lstrstartpos;
	i64 bytes_to_read;
	de_encoding encoding;
	i64 pos = p->pos1;

	if(p->len<12) goto done;

	pos += 8;

	// ASCII invariant description
	invdesclen = de_getu32be(pos); // invariant desc. len, including NUL byte
	pos += 4;
	s = ucstring_create(c);
	dbuf_read_to_ucstring_n(c->infile, pos, invdesclen, DE_DBG_MAX_STRLEN,
		s, 0, DE_ENCODING_ASCII);
	ucstring_truncate_at_NUL(s);
	de_dbg(c, "invariant desc.: \"%s\"", ucstring_getpsz(s));
	pos += invdesclen;
	if(pos >= p->pos1+p->len) goto done;

	// Unicode localizable description
	ucstring_empty(s);

	langcode = de_getu32be(pos);
	pos += 4;

	uloclen = de_getu32be(pos);
	pos += 4;

	if(uloclen>0) {
		// TODO: How to interpret the language code?
		de_dbg(c, "language code: %d", (int)langcode);
	}

	lstrstartpos = pos;
	bytes_to_read = uloclen*2;

	encoding = DE_ENCODING_UTF16BE;
	if(uloclen>=1) {
		i32 firstchar;
		// Check for a BOM. The spec doesn't say much about the format of
		// Unicode text in 'desc' tags. It does say that "All profile data must
		// be encoded as big-endian", so maybe that means UTF-16LE is not
		// allowed. In practice, some strings begin with a BOM.
		firstchar = (i32)de_getu16be(lstrstartpos);
		if(firstchar==0xfeff) { // UTF-16BE BOM
			lstrstartpos += 2;
			bytes_to_read -= 2;
		}
		else if(firstchar==0xffef) { // UTF-16LE BOM
			lstrstartpos += 2;
			bytes_to_read -= 2;
			encoding = DE_ENCODING_UTF16LE;
		}
	}

	dbuf_read_to_ucstring_n(c->infile, lstrstartpos, bytes_to_read, DE_DBG_MAX_STRLEN*2,
		s, 0, encoding);
	ucstring_truncate_at_NUL(s);
	if(s->len>0) {
		de_dbg(c, "localizable desc.: \"%s\"", ucstring_getpsz(s));
	}
	pos += uloclen*2;
	if(pos >= p->pos1+p->len) goto done;

	// Macintosh localizable description
	// (not implemented)

done:
	ucstring_destroy(s);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpq $0xc, 0x18(%rsi)
jge 0x72cae
xorl %ebx, %ebx
jmp 0x72e07
movq %rsi, %r15
movq %rdi, %r14
movq 0x10(%rsi), %rbp
leaq 0x8(%rbp), %rsi
movq 0x18(%rdi), %rdi
callq 0xeed0d
movq %rax, %r12
leaq 0xc(%rbp), %r13
movq %r14, %rdi
callq 0xf6410
movq %rax, %rbx
movq 0x18(%r14), %rdi
movl $0x1, (%rsp)
movl $0x1f4, %ecx            # imm = 0x1F4
movq %r13, %rsi
movq %r12, %rdx
movq %rax, %r8
xorl %r9d, %r9d
callq 0xefc2a
movq %rbx, %rdi
callq 0xf6461
movq %rbx, %rdi
callq 0xf705c
leaq 0xb420d(%rip), %rsi     # 0x126f1c
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq %rbp, %r12
addq $0xc, %r12
movq 0x18(%r15), %rax
addq 0x10(%r15), %rax
cmpq %rax, %r12
jge 0x72e07
movq %rbx, %rdi
callq 0xf6423
movq 0x18(%r14), %rdi
movq %r12, %rsi
callq 0xeed0d
movq %rax, %rbp
leaq 0x4(%r12), %rsi
movq 0x18(%r14), %rdi
callq 0xeed0d
movq %rax, %r15
leaq 0x8(%r12), %r13
testq %rax, %rax
jle 0x72da5
leaq 0xb41c5(%rip), %rsi     # 0x126f32
movq %r14, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
addq %r15, %r15
movq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0xeeb67
cmpl $0xffef, %eax           # imm = 0xFFEF
je 0x72daf
movl $0x4, %ecx
cmpl $0xfeff, %eax           # imm = 0xFEFF
jne 0x72dbf
addq $0xa, %r12
addq $-0x2, %r15
jmp 0x72dbc
addq %r15, %r15
movl $0x4, %ecx
jmp 0x72dbf
addq $0xa, %r12
addq $-0x2, %r15
movl $0x3, %ecx
movq %r12, %r13
movq 0x18(%r14), %rdi
movl %ecx, (%rsp)
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r13, %rsi
movq %r15, %rdx
movq %rbx, %r8
xorl %r9d, %r9d
callq 0xefc2a
movq %rbx, %rdi
callq 0xf6461
cmpq $0x0, 0x10(%rbx)
jle 0x72e07
movq %rbx, %rdi
callq 0xf705c
leaq 0xb414a(%rip), %rsi     # 0x126f44
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf6753