// File: /workspace/github_c_makefile_star2_O0/robertdavidgraham[P]wc2/wctool.c
// Function: ucs4_to_utf8
size_t ucs4_to_utf8(unsigned char *buf, size_t sizeof_buf, unsigned wchar)
{
	#if 0
    if (0xD800 <= wchar && wchar <= 0xDFFF) {
        /* surrogates must not be encoded */
        return 0;
    }
	#endif

    if (0x10000 <= wchar && wchar <= 0x10FFFF && sizeof_buf >= 4) {
        buf[0] = 0xF0 | ((wchar >> 18) & 0x07);
        buf[1] = 0x80 | ((wchar >> 12) & 0x3F);
        buf[2] = 0x80 | ((wchar >>  6) & 0x3F);
        buf[3] = 0x80 | ((wchar >>  0) & 0x3F);
        return 4;
    } else if (0x0800 <= wchar && wchar <= 0xFFFF && sizeof_buf >= 3) {
        buf[0] = 0xE0 | ((wchar >> 12) & 0x0F);
        buf[1] = 0x80 | ((wchar >>  6) & 0x3F);
        buf[2] = 0x80 | ((wchar >>  0) & 0x3F);
        return 3;
    } else if (0x0080 <= wchar && wchar <= 0x7FF && sizeof_buf >= 2) {
        buf[0] = 0xC0 | ((wchar >>  6) & 0x1F);
        buf[1] = 0x80 | ((wchar >>  0) & 0x3F);
        return 2;
    } else if (wchar <= 0x7F && sizeof_buf >= 1) {
        buf[0] = wchar;
        return 1;
    } else
        return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl $0x10000, %eax          # imm = 0x10000
cmpl -0x1c(%rbp), %eax
ja 0x1381
cmpl $0x10ffff, -0x1c(%rbp)  # imm = 0x10FFFF
ja 0x1381
cmpq $0x4, -0x18(%rbp)
jb 0x1381
movl -0x1c(%rbp), %eax
shrl $0x12, %eax
andl $0x7, %eax
orl $0xf0, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movl -0x1c(%rbp), %eax
shrl $0xc, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x1c(%rbp), %eax
shrl $0x6, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x2(%rax)
movl -0x1c(%rbp), %eax
shrl $0x0, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x3(%rax)
movq $0x4, -0x8(%rbp)
jmp 0x1464
movl $0x800, %eax            # imm = 0x800
cmpl -0x1c(%rbp), %eax
ja 0x13e9
cmpl $0xffff, -0x1c(%rbp)    # imm = 0xFFFF
ja 0x13e9
cmpq $0x3, -0x18(%rbp)
jb 0x13e9
movl -0x1c(%rbp), %eax
shrl $0xc, %eax
andl $0xf, %eax
orl $0xe0, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movl -0x1c(%rbp), %eax
shrl $0x6, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x1c(%rbp), %eax
shrl $0x0, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x2(%rax)
movq $0x3, -0x8(%rbp)
jmp 0x1464
movl $0x80, %eax
cmpl -0x1c(%rbp), %eax
ja 0x143a
cmpl $0x7ff, -0x1c(%rbp)     # imm = 0x7FF
ja 0x143a
cmpq $0x2, -0x18(%rbp)
jb 0x143a
movl -0x1c(%rbp), %eax
shrl $0x6, %eax
andl $0x1f, %eax
orl $0xc0, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movl -0x1c(%rbp), %eax
shrl $0x0, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x1(%rax)
movq $0x2, -0x8(%rbp)
jmp 0x1464
cmpl $0x7f, -0x1c(%rbp)
ja 0x145c
cmpq $0x1, -0x18(%rbp)
jb 0x145c
movl -0x1c(%rbp), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movq $0x1, -0x8(%rbp)
jmp 0x1464
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
popq %rbp
retq
nopw (%rax,%rax)