// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rdi, %rbx
xorl %r14d, %r14d
subq %rax, %rsi
cmpq %r14, %rsi
je 0x4af3
cmpb $0x0, (%rax,%r14)
je 0x4af6
incq %r14
jmp 0x4ae2
movq %rsi, %r14
leaq 0x10(%rsp), %rdi
vxorps %xmm0, %xmm0, %xmm0
shlq $0x2, %rsi
andq $0x0, 0x10(%rdi)
vmovaps %xmm0, (%rdi)
callq 0x5230
movq (%rbx), %rdi
callq 0x4d47
movq (%rbx), %r12
movq 0x10(%rsp), %r13
testq %r12, %r12
je 0x4c0f
movq %rax, 0x40(%rsp)
movq %rbx, 0x48(%rsp)
testq %r13, %r13
jne 0x4b50
movq %r12, %rdi
callq 0x4d47
leaq 0x1(%rax), %rdi
pushq $0x2
popq %rsi
callq 0x20e0
movq %rax, %r13
pushq $0x1
popq %r15
leaq 0x28(%rsp), %rbp
xorl %edi, %edi
xorl %ebx, %ebx
movl %r15d, %eax
movq %rdi, 0x28(%rsp)
testl %eax, %eax
je 0x4c00
addq %r12, %rdi
movq %rbp, %rsi
callq 0x5033
testq %r13, %r13
je 0x4bdc
xorl %edx, %edx
cmpl $0x110000, %eax         # imm = 0x110000
movl %ebx, %ecx
leaq (%r13,%rcx,2), %rcx
setb %dl
addl %edx, %edx
cmpl $0x10000, %eax          # imm = 0x10000
cmovbl %r15d, %edx
cmpl $0x2, %edx
je 0x4bb0
cmpl $0x1, %edx
jne 0x4bd8
movw %ax, (%rcx)
testl %eax, %eax
je 0x4bdc
addq $0x2, %rcx
jmp 0x4bd8
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
andw $0x0, (%rcx)
movq 0x28(%rsp), %rdi
xorl %ecx, %ecx
cmpl $0x110000, %eax         # imm = 0x110000
setb %cl
addl %ecx, %ecx
cmpl $0x10000, %eax          # imm = 0x10000
cmovbl %r15d, %ecx
addl %ecx, %ebx
incq %rdi
jmp 0x4b60
movq 0x10(%rsp), %r13
movq 0x48(%rsp), %rbx
movq 0x40(%rsp), %rax
leaq (%r13,%rax,2), %rdx
leaq 0x28(%rsp), %rdi
leaq 0x50(%rsp), %rcx
movq %r13, %rsi
callq 0x5260
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x4c37
movq %rax, 0x18(%rsp)
movq 0x8(%rbx), %rsi
subq (%rbx), %rsi
shlq $0x3, %rsi
leaq 0x10(%rsp), %rdi
callq 0x5230
movq 0x10(%rsp), %rdx
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x3e58
movq 0x10(%rsp), %rsi
leaq (%rsi,%rax,2), %rdx
leaq 0x50(%rsp), %rdi
leaq 0xf(%rsp), %rcx
callq 0x5260
leaq 0x50(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x5294
movl %eax, %ebp
testb %al, %al
je 0x4cdb
leaq 0x659e(%rip), %rdi      # 0xb22e
xorl %eax, %eax
callq 0x2030
movq %rbx, %rdi
callq 0x529e
leaq 0x658f(%rip), %rdi      # 0xb235
xorl %eax, %eax
callq 0x2030
leaq 0x28(%rsp), %rdi
callq 0x513a
leaq 0x657e(%rip), %rdi      # 0xb23c
xorl %eax, %eax
callq 0x2030
leaq 0x50(%rsp), %rdi
callq 0x513a
leaq 0x663c(%rip), %rdi      # 0xb312
callq 0x21e0
leaq 0x50(%rsp), %rdi
xorb $0x1, %bpl
callq 0x2e22
leaq 0x28(%rsp), %rdi
callq 0x2e22
leaq 0x10(%rsp), %rdi
callq 0x2e22
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4d12
jmp 0x4d12
movq %rax, %rbx
jmp 0x4d2b
jmp 0x4d19
movq %rax, %rbx
jmp 0x4d35
leaq 0x50(%rsp), %rdi
movq %rax, %rbx
callq 0x2e22
leaq 0x28(%rsp), %rdi
callq 0x2e22
leaq 0x10(%rsp), %rdi
callq 0x2e22
movq %rbx, %rdi
callq 0x2220