// File: /workspace/github_cpp_makefile_star2_O3/WojciechMula[P]utf16utf8/tests/unittest.cpp
// Function: validate_from_utf8(std::vector<unsigned char, std::allocator<unsigned char>>&)
bool validate_from_utf8(std::vector<uint8_t>& input) {
    size_t actual_length = input.size();
    for(size_t i = 0; i < input.size(); i++) {
        if(input[i] ==0) {
            actual_length = i;
            break;
        }
    }
    // reference
    std::vector<uint16_t> tmp;
    tmp.resize(4 * input.size());
    size_t len = strlen_utf8_to_utf16(input.data());
    utf8_to_utf16(input.data(), (uint16_t*)tmp.data());
    const std::vector<uint16_t> reference(tmp.data(), tmp.data() + len);

    // SSE
    tmp.clear();
    tmp.resize(8 * input.size());
    const size_t output_size = sse_convert_valid_utf8_to_utf16_lemire(input.data(), actual_length, (uint16_t*)tmp.data());
    const std::vector<uint16_t> sse(tmp.data(), tmp.data() + output_size);

    if( sse != reference ) {
        printf("input:");display<uint8_t>(input);
        printf("ref  :");display<uint16_t>(reference);
        printf("sse  :");display<uint16_t>(sse);
        printf("BUG\n");
        return false;
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq (%rdi), %rax
movq 0x8(%rdi), %rsi
xorl %r14d, %r14d
movq %rdi, %rbx
subq %rax, %rsi
je 0x5025
cmpb $0x0, (%rax,%r14)
je 0x5025
incq %r14
cmpq %r14, %rsi
jne 0x5013
movq %rsi, %r14
leaq 0x20(%rsp), %rdi
vxorps %xmm0, %xmm0, %xmm0
shlq $0x2, %rsi
vmovaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x58ea
movq (%rbx), %rbp
movq $0x0, 0x8(%rsp)
movq %rbx, 0x58(%rsp)
cmpb $0x0, (%rbp)
je 0x50a4
leaq 0x8(%rsp), %r15
movl $0x1, %r12d
xorl %ebx, %ebx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x567d
xorl %ecx, %ecx
cmpl $0x110000, %eax         # imm = 0x110000
setb %cl
addl %ecx, %ecx
cmpl $0x10000, %eax          # imm = 0x10000
movq 0x8(%rsp), %rax
cmovbq %r12, %rcx
addq %rcx, %rbx
leaq 0x1(%rax), %rcx
leaq 0x1(%rbp,%rax), %rdi
movq %rcx, 0x8(%rsp)
cmpb $0x0, (%rdi)
jne 0x506a
jmp 0x50a6
xorl %ebx, %ebx
movq 0x20(%rsp), %rax
movq %rax, %r12
movq %rax, 0x60(%rsp)
testq %rax, %rax
jne 0x512b
movq $0x0, 0x8(%rsp)
cmpb $0x0, (%rbp)
je 0x5115
leaq 0x8(%rsp), %r13
movl $0x1, %r15d
xorl %r12d, %r12d
movq %rbp, %rdi
movq %r13, %rsi
callq 0x567d
xorl %ecx, %ecx
cmpl $0x110000, %eax         # imm = 0x110000
setb %cl
addl %ecx, %ecx
cmpl $0x10000, %eax          # imm = 0x10000
movq 0x8(%rsp), %rax
cmovbq %r15, %rcx
addq %rcx, %r12
leaq 0x1(%rax), %rcx
leaq 0x1(%rbp,%rax), %rdi
movq %rcx, 0x8(%rsp)
cmpb $0x0, (%rdi)
jne 0x50d8
incq %r12
jmp 0x511b
movl $0x1, %r12d
movl $0x2, %esi
movq %r12, %rdi
callq 0x20e0
movq %rax, %r12
leaq 0x8(%rsp), %rax
movl $0x1, %r13d
xorl %r15d, %r15d
xorl %edi, %edi
movq $0x0, (%rax)
addq %rbp, %rdi
leaq 0x8(%rsp), %rsi
callq 0x567d
testq %r12, %r12
je 0x51b4
xorl %edx, %edx
cmpl $0x110000, %eax         # imm = 0x110000
movl %r15d, %ecx
leaq (%r12,%rcx,2), %rcx
setb %dl
addl %edx, %edx
cmpl $0x10000, %eax          # imm = 0x10000
cmovbl %r13d, %edx
cmpl $0x2, %edx
je 0x5187
cmpl $0x1, %edx
jne 0x51af
movw %ax, (%rcx)
testl %eax, %eax
je 0x51b4
addq $0x2, %rcx
jmp 0x51af
leal 0x3ff0000(%rax), %edx
shrl $0xa, %edx
addl $0xffffd800, %edx       # imm = 0xFFFFD800
movw %dx, (%rcx)
movl %eax, %edx
andl $0x3ff, %edx            # imm = 0x3FF
orl $0xdc00, %edx           # imm = 0xDC00
movw %dx, 0x2(%rcx)
addq $0x4, %rcx
movw $0x0, (%rcx)
movq 0x8(%rsp), %rdi
xorl %ecx, %ecx
cmpl $0x110000, %eax         # imm = 0x110000
setb %cl
addl %ecx, %ecx
cmpl $0x10000, %eax          # imm = 0x10000
cmovbl %r13d, %ecx
addl %ecx, %r15d
incq %rdi
movq %rdi, 0x8(%rsp)
testl %eax, %eax
jne 0x5142
movq 0x60(%rsp), %rsi
leaq (%rsi,%rbx,2), %rdx
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rcx
callq 0x591a
movq 0x20(%rsp), %rax
movq 0x58(%rsp), %rbx
cmpq %rax, 0x28(%rsp)
je 0x520f
movq %rax, 0x28(%rsp)
movq 0x8(%rbx), %rsi
subq (%rbx), %rsi
shlq $0x3, %rsi
leaq 0x20(%rsp), %rdi
callq 0x58ea
movq 0x20(%rsp), %rdx
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x41f0
movq 0x20(%rsp), %rsi
leaq (%rsi,%rax,2), %rdx
leaq 0x40(%rsp), %rdi
leaq 0x7(%rsp), %rcx
callq 0x591a
movq 0x48(%rsp), %rax
movq 0x40(%rsp), %r14
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rcx
movq %rax, %rdx
subq %r14, %rdx
subq %rsi, %rcx
cmpq %rcx, %rdx
jne 0x5282
movb $0x1, %bpl
cmpq %r14, %rax
je 0x52db
movq %r14, %rdi
callq 0x2180
testl %eax, %eax
je 0x52db
leaq 0x6135(%rip), %rdi      # 0xb3be
xorl %eax, %eax
callq 0x2030
movq %rbx, %rdi
callq 0x595d
leaq 0x6126(%rip), %rdi      # 0xb3c5
xorl %eax, %eax
callq 0x2030
leaq 0x8(%rsp), %rdi
callq 0x578b
leaq 0x6115(%rip), %rdi      # 0xb3cc
xorl %eax, %eax
callq 0x2030
leaq 0x40(%rsp), %rdi
callq 0x578b
leaq 0x61d3(%rip), %rdi      # 0xb4a2
callq 0x21d0
movq 0x40(%rsp), %r14
xorl %ebp, %ebp
testq %r14, %r14
je 0x52f0
movq 0x50(%rsp), %rsi
movq %r14, %rdi
subq %r14, %rsi
callq 0x2170
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x5307
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x531e
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5333
jmp 0x5333
movq %rax, %rbx
jmp 0x5359
jmp 0x533a
movq %rax, %rbx
jmp 0x5370
movq 0x40(%rsp), %rdi
movq %rax, %rbx
testq %rdi, %rdi
je 0x5359
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x5370
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x5387
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2210