// File: /workspace/github_c_makefile_star2_O2/mloar[P]charset/utf8.c
// Function: write_utf8
int write_utf8(charset_spec const *charset, long int input_chr,
	       charset_state *state,
	       void (*emit)(void *ctx, long int output),
	       void *emitctx)
{
    UNUSEDARG(charset);
    UNUSEDARG(state);

    if (input_chr == -1)
	return TRUE;		       /* stateless; no cleanup required */

    /*
     * Refuse to output any illegal code points.
     */
    if (input_chr == 0xFFFE || input_chr == 0xFFFF ||
	(input_chr >= 0xD800 && input_chr < 0xE000)) {
	return FALSE;
    } else if (input_chr < 0x80) {     /* one-byte character */
	emit(emitctx, input_chr);
	return TRUE;
    } else if (input_chr < 0x800) {    /* two-byte character */
	emit(emitctx, 0xC0 | (0x1F & (input_chr >>  6)));
	emit(emitctx, 0x80 | (0x3F & (input_chr      )));
	return TRUE;
    } else if (input_chr < 0x10000) {  /* three-byte character */
	emit(emitctx, 0xE0 | (0x0F & (input_chr >> 12)));
	emit(emitctx, 0x80 | (0x3F & (input_chr >>  6)));
	emit(emitctx, 0x80 | (0x3F & (input_chr      )));
	return TRUE;
    } else if (input_chr < 0x200000) { /* four-byte character */
	emit(emitctx, 0xF0 | (0x07 & (input_chr >> 18)));
	emit(emitctx, 0x80 | (0x3F & (input_chr >> 12)));
	emit(emitctx, 0x80 | (0x3F & (input_chr >>  6)));
	emit(emitctx, 0x80 | (0x3F & (input_chr      )));
	return TRUE;
    } else if (input_chr < 0x4000000) {/* five-byte character */
	emit(emitctx, 0xF8 | (0x03 & (input_chr >> 24)));
	emit(emitctx, 0x80 | (0x3F & (input_chr >> 18)));
	emit(emitctx, 0x80 | (0x3F & (input_chr >> 12)));
	emit(emitctx, 0x80 | (0x3F & (input_chr >>  6)));
	emit(emitctx, 0x80 | (0x3F & (input_chr      )));
	return TRUE;
    } else {			       /* six-byte character */
	emit(emitctx, 0xFC | (0x01 & (input_chr >> 30)));
	emit(emitctx, 0x80 | (0x3F & (input_chr >> 24)));
	emit(emitctx, 0x80 | (0x3F & (input_chr >> 18)));
	emit(emitctx, 0x80 | (0x3F & (input_chr >> 12)));
	emit(emitctx, 0x80 | (0x3F & (input_chr >>  6)));
	emit(emitctx, 0x80 | (0x3F & (input_chr      )));
	return TRUE;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq $0x1
popq %rbp
cmpq $-0x1, %rsi
je 0x9d2f
movq %rcx, %rbx
movq %rsi, %r15
movq %rsi, %rax
andq $-0x2, %rax
cmpq $0xfffe, %rax           # imm = 0xFFFE
sete %cl
movq %rsi, %rax
andq $-0x800, %rax           # imm = 0xF800
cmpq $0xd800, %rax           # imm = 0xD800
sete %dl
xorl %eax, %eax
orb %cl, %dl
jne 0x9d31
movq %r8, %r14
cmpq $0x80, %r15
jl 0x9d27
cmpq $0x7ff, %r15            # imm = 0x7FF
ja 0x9c32
movq %r15, %rsi
shrq $0x6, %rsi
orq $0xc0, %rsi
jmp 0x9d17
cmpq $0xffff, %r15           # imm = 0xFFFF
ja 0x9c63
movq %r15, %rsi
shrq $0xc, %rsi
orq $0xe0, %rsi
movq %r14, %rdi
callq *%rbx
movl %r15d, %esi
shrl $0x6, %esi
andl $0x3f, %esi
orq $0x80, %rsi
jmp 0x9d17
cmpq $0x1fffff, %r15         # imm = 0x1FFFFF
ja 0x9c90
movq %r15, %rsi
shrq $0x12, %rsi
orq $0xf0, %rsi
movq %r14, %rdi
callq *%rbx
movl %r15d, %esi
shrl $0xc, %esi
andl $0x3f, %esi
movl $0x80, %r12d
jmp 0x9d03
cmpq $0x3ffffff, %r15        # imm = 0x3FFFFFF
ja 0x9cbd
movq %r15, %rsi
shrq $0x18, %rsi
orq $0xf8, %rsi
movq %r14, %rdi
callq *%rbx
movl %r15d, %esi
shrl $0x12, %esi
andl $0x3f, %esi
movl $0x80, %r12d
jmp 0x9cf2
movl %r15d, %esi
shrl $0x1e, %esi
andl $0x1, %esi
orq $0xfc, %rsi
movq %r14, %rdi
callq *%rbx
movl %r15d, %esi
shrl $0x18, %esi
andl $0x3f, %esi
movl $0x80, %r12d
orq %r12, %rsi
movq %r14, %rdi
callq *%rbx
movl %r15d, %esi
shrl $0x12, %esi
andl $0x3f, %esi
orq %r12, %rsi
movq %r14, %rdi
callq *%rbx
movl %r15d, %esi
shrl $0xc, %esi
andl $0x3f, %esi
orq %r12, %rsi
movq %r14, %rdi
callq *%rbx
movl %r15d, %esi
shrl $0x6, %esi
andl $0x3f, %esi
orq %r12, %rsi
movq %r14, %rdi
callq *%rbx
andl $0x3f, %r15d
orq $0x80, %r15
movq %r14, %rdi
movq %r15, %rsi
callq *%rbx
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop