// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-data.c
// Function: de_utf8_to_uchar
int de_utf8_to_uchar(const u8 *utf8buf, i64 buflen,
	de_rune *p_uchar, i64 *p_utf8len)
{
	i32 u0=0;
	i32 u1=0;
	i32 u2=0;
	i32 u3=0;

	if(buflen<1) return 0;
	u0 = (i32)utf8buf[0];
	if(u0<=0x7f) { // 1-byte UTF-8 char
		*p_utf8len = 1;
		*p_uchar = u0;
		return 1;
	}
	if(buflen<2) return 0;
	if((utf8buf[1]&0xc0)!=0x80) return 0;
	u1 = (i32)utf8buf[1];
	if(u0<=0xdf) { // 2-byte UTF-8 char
		*p_utf8len = 2;
		*p_uchar = ((u0&0x1f)<<6) | (u1&0x3f);
		return 1;
	}
	if(buflen<3) return 0;
	if((utf8buf[2]&0xc0)!=0x80) return 0;
	u2 = (i32)utf8buf[2];
	if(u0<=0xef) { // 3-byte UTF-8 char
		*p_utf8len = 3;
		*p_uchar = ((u0&0x0f)<<12) | ((u1&0x3f)<<6) | (u2&0x3f);
		return 1;
	}
	if(buflen<4) return 0;
	if((utf8buf[3]&0xc0)!=0x80) return 0;
	u3 = (i32)utf8buf[3];
	if(u0<=0xf7) { // 4-byte UTF-8 char
		*p_utf8len = 4;
		*p_uchar = ((u0&0x07)<<18) | ((u1&0x3f)<<12) | ((u2&0x3f)<<6) | (u3&0x3f);
		return 1;
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
cmpq $0x1, -0x18(%rbp)
jge 0x160d43
movl $0x0, -0x4(%rbp)
jmp 0x160ef1
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x7f, -0x2c(%rbp)
jg 0x160d73
movq -0x28(%rbp), %rax
movq $0x1, (%rax)
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x160ef1
cmpq $0x2, -0x18(%rbp)
jge 0x160d86
movl $0x0, -0x4(%rbp)
jmp 0x160ef1
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
je 0x160da6
movl $0x0, -0x4(%rbp)
jmp 0x160ef1
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %eax
movl %eax, -0x30(%rbp)
cmpl $0xdf, -0x2c(%rbp)
jg 0x160de8
movq -0x28(%rbp), %rax
movq $0x2, (%rax)
movl -0x2c(%rbp), %ecx
andl $0x1f, %ecx
shll $0x6, %ecx
movl -0x30(%rbp), %eax
andl $0x3f, %eax
orl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x160ef1
cmpq $0x3, -0x18(%rbp)
jge 0x160dfb
movl $0x0, -0x4(%rbp)
jmp 0x160ef1
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
je 0x160e1b
movl $0x0, -0x4(%rbp)
jmp 0x160ef1
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %eax
movl %eax, -0x34(%rbp)
cmpl $0xef, -0x2c(%rbp)
jg 0x160e68
movq -0x28(%rbp), %rax
movq $0x3, (%rax)
movl -0x2c(%rbp), %ecx
andl $0xf, %ecx
shll $0xc, %ecx
movl -0x30(%rbp), %eax
andl $0x3f, %eax
shll $0x6, %eax
orl %eax, %ecx
movl -0x34(%rbp), %eax
andl $0x3f, %eax
orl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x160ef1
cmpq $0x4, -0x18(%rbp)
jge 0x160e78
movl $0x0, -0x4(%rbp)
jmp 0x160ef1
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
je 0x160e95
movl $0x0, -0x4(%rbp)
jmp 0x160ef1
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
movl %eax, -0x38(%rbp)
cmpl $0xf7, -0x2c(%rbp)
jg 0x160eea
movq -0x28(%rbp), %rax
movq $0x4, (%rax)
movl -0x2c(%rbp), %ecx
andl $0x7, %ecx
shll $0x12, %ecx
movl -0x30(%rbp), %eax
andl $0x3f, %eax
shll $0xc, %eax
orl %eax, %ecx
movl -0x34(%rbp), %eax
andl $0x3f, %eax
shll $0x6, %eax
orl %eax, %ecx
movl -0x38(%rbp), %eax
andl $0x3f, %eax
orl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x160ef1
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)