// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-data.c
// Function: de_utf8_to_ascii
void de_utf8_to_ascii(const char *src, char *dst, size_t dstlen, unsigned int flags)
{
	size_t srcpos = 0;
	size_t dstpos = 0;
	unsigned char ch;
	i32 uchar;
	i64 code_len;
	int ret;

	while(1) {
		char sc; // substitution character 1
		char sc2 = 0; // substitution character 2

		if(dstpos >= dstlen-1) {
			dst[dstlen-1] = '\0';
			break;
		}

		ch = (unsigned char)src[srcpos];
		if(ch<0x80) {
			dst[dstpos++] = src[srcpos++];
			if(ch=='\0')
				break;
		}
		else { // Start of a multi-byte UTF8 char

			ret = de_utf8_to_uchar((const u8*)&src[srcpos], 4, &uchar, &code_len);
			if(ret) {
				srcpos += (size_t)code_len;
				switch(uchar) {
				case 0x00d7: sc='x'; break; // Multiplication sign
				case 0x2018: case 0x2019: sc='\''; break; // single quotes
				case 0x201c: case 0x201d: sc='"'; break; // double quotes
				case 0x2192: sc='-'; sc2='>'; break; // Rightwards arrow
				case 0x2264: sc='<'; sc2='='; break;
				case 0x2265: sc='>'; sc2='='; break;
				case 0x2502: sc='|'; break; // Box drawings light vertical
				default: sc = '_';
				}
			}
			else {
				srcpos += 1;
				sc = '?';
			}
			dst[dstpos++] = sc;
			if(sc2 && dstpos<dstlen-1) dst[dstpos++] = sc2;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movb $0x0, -0x46(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jb 0x160f51
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
movb $0x0, (%rax,%rcx)
jmp 0x1610db
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x31(%rbp)
movzbl -0x31(%rbp), %eax
cmpl $0x80, %eax
jge 0x160fa9
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rbp)
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x30(%rbp)
movb %dl, (%rax,%rcx)
movzbl -0x31(%rbp), %eax
cmpl $0x0, %eax
jne 0x160fa4
jmp 0x1610db
jmp 0x1610d6
movq -0x8(%rbp), %rdi
addq -0x28(%rbp), %rdi
movl $0x4, %esi
leaq -0x38(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x160d00
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x161078
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x4c(%rbp)
subl $0xd7, %eax
je 0x16103c
jmp 0x160fee
movl -0x4c(%rbp), %eax
addl $0xffffdfe8, %eax       # imm = 0xFFFFDFE8
subl $0x2, %eax
jb 0x161042
jmp 0x160ffd
movl -0x4c(%rbp), %eax
addl $0xffffdfe4, %eax       # imm = 0xFFFFDFE4
subl $0x2, %eax
jb 0x161048
jmp 0x16100c
movl -0x4c(%rbp), %eax
subl $0x2192, %eax           # imm = 0x2192
je 0x16104e
jmp 0x161018
movl -0x4c(%rbp), %eax
subl $0x2264, %eax           # imm = 0x2264
je 0x161058
jmp 0x161024
movl -0x4c(%rbp), %eax
subl $0x2265, %eax           # imm = 0x2265
je 0x161062
jmp 0x161030
movl -0x4c(%rbp), %eax
subl $0x2502, %eax           # imm = 0x2502
je 0x16106c
jmp 0x161072
movb $0x78, -0x45(%rbp)
jmp 0x161076
movb $0x27, -0x45(%rbp)
jmp 0x161076
movb $0x22, -0x45(%rbp)
jmp 0x161076
movb $0x2d, -0x45(%rbp)
movb $0x3e, -0x46(%rbp)
jmp 0x161076
movb $0x3c, -0x45(%rbp)
movb $0x3d, -0x46(%rbp)
jmp 0x161076
movb $0x3e, -0x45(%rbp)
movb $0x3d, -0x46(%rbp)
jmp 0x161076
movb $0x7c, -0x45(%rbp)
jmp 0x161076
movb $0x5f, -0x45(%rbp)
jmp 0x161088
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movb $0x3f, -0x45(%rbp)
movb -0x45(%rbp), %dl
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x30(%rbp)
movb %dl, (%rax,%rcx)
movsbl -0x46(%rbp), %eax
cmpl $0x0, %eax
je 0x1610d4
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x1610d4
movb -0x46(%rbp), %dl
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x30(%rbp)
movb %dl, (%rax,%rcx)
jmp 0x1610d6
jmp 0x160f27
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)