// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/id3.c
// Function: id3v2_read_to_ucstring
static void id3v2_read_to_ucstring(deark *c, dbuf *f, i64 pos1, i64 len,
	de_ucstring *s, u8 id3_encoding)
{
	i64 pos = pos1;
	const char *bomdesc = "none";
	de_encoding encoding_to_use = DE_ENCODING_UNKNOWN;

	if(len<=0) goto done;

	if(id3_encoding==ID3ENC_ISO_8859_1) {
		encoding_to_use = DE_ENCODING_LATIN1;
	}
	else if(id3_encoding==ID3ENC_UTF16) {
		u32 bom_id;

		if(len<2) goto done;
		bom_id = (u32)dbuf_getu16be(f, pos);

		if(bom_id==0xfeff) {
			encoding_to_use = DE_ENCODING_UTF16BE;
			bomdesc = "BE";
		}
		else if(bom_id==0xfffe) {
			encoding_to_use = DE_ENCODING_UTF16LE;
			bomdesc = "LE";
		}
		else {
			// TODO: What should we do if there's no BOM?
			// v2.2.x does not say anything about a BOM, but it also does not
			// say anything about what byte order is used.
			// v2.3.x and 2.4.x require a BOM.
			goto done;
		}
		pos += 2;
	}
	else if(id3_encoding==ID3ENC_UTF16BE) {
		encoding_to_use = DE_ENCODING_UTF16BE;
	}
	else if(id3_encoding==ID3ENC_UTF8) { // UTF-8
		encoding_to_use = DE_ENCODING_UTF8;
	}
	else {
		goto done; // Error
	}

	// TODO: Maybe shouldn't use DE_DBG_MAX_STRLEN here.
	dbuf_read_to_ucstring_n(f, pos, pos1+len-pos, DE_DBG_MAX_STRLEN, s, 0, encoding_to_use);
	ucstring_truncate_at_NUL(s);

done:
	if(id3_encoding==ID3ENC_UTF16 && c->debug_level>=2) {
		de_dbg2(c, "BOM: %s", bomdesc);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %r9b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movb %al, -0x29(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq 0xf112c(%rip), %rax     # 0x19c70d
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
cmpq $0x0, -0x20(%rbp)
jg 0xab5f8
jmp 0xab6de
movzbl -0x29(%rbp), %eax
cmpl $0x0, %eax
jne 0xab60d
movl $0x5, -0x44(%rbp)
jmp 0xab6aa
movzbl -0x29(%rbp), %eax
cmpl $0x1, %eax
jne 0xab67e
cmpq $0x2, -0x20(%rbp)
jge 0xab622
jmp 0xab6de
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x1651d0
movl %eax, -0x48(%rbp)
cmpl $0xfeff, -0x48(%rbp)    # imm = 0xFEFF
jne 0xab64f
movl $0x4, -0x44(%rbp)
leaq 0x104a70(%rip), %rax    # 0x1b00b9
movq %rax, -0x40(%rbp)
jmp 0xab670
cmpl $0xfffe, -0x48(%rbp)    # imm = 0xFFFE
jne 0xab66c
movl $0x3, -0x44(%rbp)
leaq 0xfd0c0(%rip), %rax     # 0x1a8726
movq %rax, -0x40(%rbp)
jmp 0xab66e
jmp 0xab6de
jmp 0xab670
movq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
jmp 0xab6a8
movzbl -0x29(%rbp), %eax
cmpl $0x2, %eax
jne 0xab690
movl $0x4, -0x44(%rbp)
jmp 0xab6a6
movzbl -0x29(%rbp), %eax
cmpl $0x3, %eax
jne 0xab6a2
movl $0x2, -0x44(%rbp)
jmp 0xab6a4
jmp 0xab6de
jmp 0xab6a6
jmp 0xab6a8
jmp 0xab6aa
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x18(%rbp), %rdx
addq -0x20(%rbp), %rdx
subq -0x38(%rbp), %rdx
movq -0x28(%rbp), %r8
movl -0x44(%rbp), %eax
movl $0x1f4, %ecx            # imm = 0x1F4
xorl %r9d, %r9d
movl %eax, (%rsp)
callq 0x166a40
movq -0x28(%rbp), %rdi
callq 0x1712b0
movzbl -0x29(%rbp), %eax
cmpl $0x1, %eax
jne 0xab706
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jl 0xab706
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0x108000(%rip), %rsi    # 0x1b36ff
movb $0x0, %al
callq 0x15b350
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)