// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movq (%rdi), %rax
movq 0x8(%rdi), %rsi
subq %rax, %rsi
movq %rsi, %r14
je 0x5078
xorl %r14d, %r14d
cmpb $0x0, (%rax,%r14)
je 0x5078
incq %r14
cmpq %r14, %rsi
jne 0x5066
movq %rsi, %r14
vxorps %xmm0, %xmm0, %xmm0
leaq 0x20(%rsp), %rdi
vmovaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
shlq $0x2, %rsi
callq 0x594a
movq %rbx, 0x58(%rsp)
movq (%rbx), %rbp
movq $0x0, 0x8(%rsp)
cmpb $0x0, (%rbp)
je 0x50f7
xorl %ebx, %ebx
leaq 0x8(%rsp), %r15
movl $0x1, %r12d
movq %rbp, %rdi
movq %r15, %rsi
callq 0x56d7
xorl %ecx, %ecx
cmpl $0x110000, %eax         # imm = 0x110000
setb %cl
addl %ecx, %ecx
cmpl $0x10000, %eax          # imm = 0x10000
cmovbq %r12, %rcx
addq %rcx, %rbx
movq 0x8(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rsp)
leaq 0x1(%rbp,%rax), %rdi
cmpb $0x0, (%rdi)
jne 0x50bd
jmp 0x50f9
xorl %ebx, %ebx
movq 0x20(%rsp), %rax
movq %rax, %r12
movq %rax, 0x60(%rsp)
testq %rax, %rax
jne 0x517e
movq $0x0, 0x8(%rsp)
cmpb $0x0, (%rbp)
je 0x5168
xorl %r12d, %r12d
leaq 0x8(%rsp), %r13
movl $0x1, %r15d
movq %rbp, %rdi
movq %r13, %rsi
callq 0x56d7
xorl %ecx, %ecx
cmpl $0x110000, %eax         # imm = 0x110000
setb %cl
addl %ecx, %ecx
cmpl $0x10000, %eax          # imm = 0x10000
cmovbq %r15, %rcx
addq %rcx, %r12
movq 0x8(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rsp)
leaq 0x1(%rbp,%rax), %rdi
cmpb $0x0, (%rdi)
jne 0x512b
incq %r12
jmp 0x516e
movl $0x1, %r12d
movl $0x2, %esi
movq %r12, %rdi
callq 0x20e0
movq %rax, %r12
leaq 0x8(%rsp), %rax
movq $0x0, (%rax)
xorl %r15d, %r15d
movl $0x1, %r13d
xorl %edi, %edi
addq %rbp, %rdi
leaq 0x8(%rsp), %rsi
callq 0x56d7
testq %r12, %r12
je 0x5207
movl %r15d, %ecx
leaq (%r12,%rcx,2), %rcx
xorl %edx, %edx
cmpl $0x110000, %eax         # imm = 0x110000
setb %dl
addl %edx, %edx
cmpl $0x10000, %eax          # imm = 0x10000
cmovbl %r13d, %edx
cmpl $0x2, %edx
je 0x51da
cmpl $0x1, %edx
jne 0x5202
movw %ax, (%rcx)
testl %eax, %eax
je 0x5207
addq $0x2, %rcx
jmp 0x5202
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)
xorl %ecx, %ecx
cmpl $0x110000, %eax         # imm = 0x110000
setb %cl
addl %ecx, %ecx
cmpl $0x10000, %eax          # imm = 0x10000
cmovbl %r13d, %ecx
addl %ecx, %r15d
movq 0x8(%rsp), %rdi
incq %rdi
movq %rdi, 0x8(%rsp)
testl %eax, %eax
jne 0x5195
movq 0x60(%rsp), %rsi
leaq (%rsi,%rbx,2), %rdx
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rcx
callq 0x597a
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
movq 0x58(%rsp), %rbx
je 0x5262
movq %rax, 0x28(%rsp)
movq 0x8(%rbx), %rsi
subq (%rbx), %rsi
shlq $0x3, %rsi
leaq 0x20(%rsp), %rdi
callq 0x594a
movq (%rbx), %rdi
movq 0x20(%rsp), %rdx
movq %r14, %rsi
callq 0x41ae
movq 0x20(%rsp), %rsi
leaq (%rsi,%rax,2), %rdx
leaq 0x40(%rsp), %rdi
leaq 0x7(%rsp), %rcx
callq 0x597a
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rax
movq %rax, %rdx
subq %rdi, %rdx
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rcx
subq %rsi, %rcx
movb $0x1, %bpl
cmpq %rcx, %rdx
jne 0x52d8
cmpq %rdi, %rax
je 0x52d6
callq 0x2180
testl %eax, %eax
setne %bpl
jmp 0x52d8
xorl %ebp, %ebp
testb %bpl, %bpl
je 0x532f
leaq 0x5f4a(%rip), %rdi      # 0xb22e
xorl %eax, %eax
callq 0x2030
movq %rbx, %rdi
callq 0x59bd
leaq 0x5f3b(%rip), %rdi      # 0xb235
xorl %eax, %eax
callq 0x2030
leaq 0x8(%rsp), %rdi
callq 0x57eb
leaq 0x5f2a(%rip), %rdi      # 0xb23c
xorl %eax, %eax
callq 0x2030
leaq 0x40(%rsp), %rdi
callq 0x57eb
leaq 0x5fe8(%rip), %rdi      # 0xb312
callq 0x21d0
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x5346
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x535d
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x5374
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
xorb $0x1, %bpl
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x538d
jmp 0x538d
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x53ae
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
jmp 0x53ae
jmp 0x53ab
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x53c5
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2210
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x5390
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
jmp 0x5390