// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-dbuf.c
// Function: dbuf_copy_slice_convert_to_utf8
void dbuf_copy_slice_convert_to_utf8(dbuf *inf, i64 pos, i64 len,
	de_ext_encoding input_ee, dbuf *outf, UI flags)
{
	deark *c = inf->c;
	de_encoding enc =  DE_EXTENC_GET_BASE(input_ee);
	int prepend_BOM = 0;
	int already_has_BOM = 0;
	struct textconvctx_struct tcctx;

	de_zeromem(&tcctx, sizeof(struct textconvctx_struct));
	dbuf_constrain_length(inf, pos, &len);

	if((flags & 0x4) && (enc==DE_ENCODING_UNKNOWN || enc==DE_ENCODING_ASCII)) {
		dbuf_copy(inf, pos, len, outf);
		goto done;
	}

	tcctx.outf = outf;
	de_encconv_init(&tcctx.es, input_ee);
	tcctx.tmpstr = ucstring_create(c);

	if(c->write_bom && outf->len==0) {
		if((flags & 0x3)!=0) {
			already_has_BOM = slice_has_BOM(inf, pos, len, enc);
		}

		if(flags & 0x1) {
			prepend_BOM = !already_has_BOM;
		}
		else if(flags & 0x2) {
			if(!already_has_BOM) {
				prepend_BOM = !slice_is_ascii_compatible(inf, pos, len, input_ee);
			}
		}
	}

	if(prepend_BOM) {
		dbuf_write_uchar_as_utf8(outf, 0xfeff);
	}

	dbuf_buffered_read(inf, pos, len, text2utf8_cbfn, (void*)&tcctx);

done:
	ucstring_destroy(tcctx.tmpstr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movl -0x1c(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
leaq -0x78(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x19140
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x18(%rbp), %rdx
callq 0x164c90
movl -0x2c(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x169e39
cmpl $0x0, -0x3c(%rbp)
je 0x169e1f
cmpl $0x1, -0x3c(%rbp)
jne 0x169e39
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x166070
jmp 0x169f28
movq -0x28(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x78(%rbp), %rdi
addq $0x10, %rdi
movl -0x1c(%rbp), %esi
callq 0x160150
movq -0x38(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rax
movzbl 0xcc(%rax), %eax
cmpl $0x0, %eax
je 0x169ef8
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x169ef8
movl -0x2c(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x169e9f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x3c(%rbp), %ecx
callq 0x169f40
movl %eax, -0x44(%rbp)
movl -0x2c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x169ebd
cmpl $0x0, -0x44(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x40(%rbp)
jmp 0x169ef6
movl -0x2c(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x169ef4
cmpl $0x0, -0x44(%rbp)
jne 0x169ef2
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
callq 0x16a060
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x40(%rbp)
jmp 0x169ef4
jmp 0x169ef6
jmp 0x169ef8
cmpl $0x0, -0x40(%rbp)
je 0x169f0c
movq -0x28(%rbp), %rdi
movl $0xfeff, %esi           # imm = 0xFEFF
callq 0x160cc0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0x1d1(%rip), %rcx       # 0x16a0f0
leaq -0x78(%rbp), %r8
callq 0x166260
movq -0x70(%rbp), %rdi
callq 0x171750
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)