// File: /workspace/github_cpp_makefile_star2_O3/WojciechMula[P]utf16utf8/src/random_utf8.cpp
// Function: RandomUTF8::generate(unsigned long)
std::vector<uint8_t> RandomUTF8::generate(size_t output_bytes)
{
    std::vector<uint8_t> result;
    result.reserve(output_bytes);
    uint8_t candidate, head;
    while (result.size() < output_bytes) {
        auto b = bytes_count(gen);
        switch (b) {
            case 0: // 1 byte
                candidate = val_7bit(gen);
                while(candidate == 0) {// though strictly speaking, a stream of nulls is UTF8, it tends to break some code
                    candidate = val_7bit(gen);
                }
                result.push_back(candidate);
                break;
            case 1: // 2 bytes
                candidate = 0xc0 | val_5bit(gen);
                while(candidate < 0xC2) {
                    candidate = 0xc0 | val_5bit(gen);
                }
                result.push_back(candidate);
                result.push_back(0x80 | val_6bit(gen));
                break;
            case 2: // 3 bytes
                head = 0xe0 | val_4bit(gen);
                result.push_back(head);
                candidate = 0x80 | val_6bit(gen);
                if(head == 0xE0) {
                    while(candidate < 0xA0) {
                        candidate = 0x80 | val_6bit(gen);
                    }
                } else if (head == 0xED) {
                    while(candidate > 0x9F) {
                        candidate = 0x80 | val_6bit(gen);
                    }
                }
                result.push_back(candidate);
                result.push_back(0x80 | val_6bit(gen));
                break;
            case 3: // 4 bytes
                head = 0xf0 | val_3bit(gen);
                while(head > 0xF4) {
                    head = 0xf0 | val_3bit(gen);
                }
                result.push_back(head);
                candidate = 0x80 | val_6bit(gen);
                if(head == 0xF0) {
                    while(candidate < 0x90) {
                        candidate = 0x80 | val_6bit(gen);
                    }
                } else if (head == 0xF4) {
                    while(candidate > 0x8F) {
                        candidate = 0x80 | val_6bit(gen);
                    }
                }
                result.push_back(candidate);
                result.push_back(0x80 | val_6bit(gen));
                result.push_back(0x80 | val_6bit(gen));
                break;
        }
    }
    result.push_back(0); // EOS for scalar code

    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
vxorps %xmm0, %xmm0, %xmm0
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq $0x0, 0x10(%rdi)
vmovups %xmm0, (%rdi)
movq %rdx, %rsi
callq 0x4436
movq 0x8(%rbx), %rsi
movq %r14, 0x20(%rsp)
movq %rsi, %rax
subq (%rbx), %rax
cmpq %r14, %rax
jae 0x4382
leaq 0x1388(%r15), %rax
leaq 0x13be(%r15), %rcx
leaq 0x13c0(%r15), %r13
leaq 0x13ba(%r15), %rbp
leaq 0x13bc(%r15), %r14
leaq 0x13b8(%r15), %r12
movq %rax, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq 0x18(%rsp), %rdi
movq %r15, %rsi
movq %rdi, %rdx
callq 0x37ac
cmpl $0x3, %eax
ja 0x435c
leaq 0x918b(%rip), %rcx      # 0xd200
movl %eax, %eax
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r12, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x44c8
movb %al, 0x9(%rsp)
testb %al, %al
jne 0x4142
movq %r12, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x44c8
jmp 0x408e
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %rdi, %rdx
callq 0x44c8
movq 0x8(%rbx), %rsi
orb $-0x20, %al
movb %al, 0xa(%rsp)
cmpq 0x10(%rbx), %rsi
je 0x417b
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x4188
movq %r13, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x44c8
orb $-0x10, %al
movb %al, 0xa(%rsp)
cmpb $-0xb, %al
jb 0x4129
movq %r13, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x44c8
jmp 0x40e7
movq %r14, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x44c8
orb $-0x40, %al
movb %al, 0x9(%rsp)
cmpb $-0x3f, %al
ja 0x4162
movq %r14, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x44c8
jmp 0x410f
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x423d
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x424a
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
jne 0x4356
leaq 0x9(%rsp), %rdx
movq %rbx, %rdi
callq 0x4596
jmp 0x435c
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x42be
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x42cb
leaq 0xa(%rsp), %rdx
movq %rbx, %rdi
callq 0x4596
movq %rbp, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x44c8
movb 0xa(%rsp), %cl
orb $-0x80, %al
movb %al, 0x9(%rsp)
cmpb $-0x20, %cl
jne 0x41c3
cmpb $-0x61, %al
ja 0x41ea
movq %rbp, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x44c8
orb $-0x80, %al
movb %al, 0x9(%rsp)
cmpb $-0x60, %al
jb 0x41a9
jmp 0x41ea
cmpb $-0x13, %cl
setne %cl
cmpb $-0x60, %al
setb %dl
orb %cl, %dl
jne 0x41ea
movq %rbp, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x44c8
orb $-0x80, %al
movb %al, 0x9(%rsp)
cmpb $-0x61, %al
ja 0x41d2
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x41fc
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x4209
leaq 0x9(%rsp), %rdx
movq %rbx, %rdi
callq 0x4596
movq %rbp, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x44c8
movq 0x8(%rbx), %rsi
orb $-0x80, %al
movb %al, 0xe(%rsp)
cmpq 0x10(%rbx), %rsi
jne 0x4356
leaq 0xe(%rsp), %rdx
movq %rbx, %rdi
callq 0x468a
jmp 0x435c
leaq 0xa(%rsp), %rdx
movq %rbx, %rdi
callq 0x4596
movq %rbp, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x44c8
movb 0xa(%rsp), %cl
orb $-0x80, %al
movb %al, 0x9(%rsp)
cmpb $-0x10, %cl
jne 0x4285
cmpb $-0x71, %al
ja 0x42ac
movq %rbp, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x44c8
orb $-0x80, %al
movb %al, 0x9(%rsp)
cmpb $-0x70, %al
jb 0x426b
jmp 0x42ac
cmpb $-0xc, %cl
setne %cl
cmpb $-0x70, %al
setb %dl
orb %cl, %dl
jne 0x42ac
movq %rbp, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x44c8
orb $-0x80, %al
movb %al, 0x9(%rsp)
cmpb $-0x71, %al
ja 0x4294
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x42f8
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x4305
leaq 0x9(%rsp), %rdx
movq %rbx, %rdi
callq 0x4596
movq %rbp, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x44c8
movq 0x8(%rbx), %rsi
orb $-0x80, %al
movb %al, 0xf(%rsp)
cmpq 0x10(%rbx), %rsi
jne 0x4356
leaq 0xf(%rsp), %rdx
movq %rbx, %rdi
callq 0x468a
jmp 0x435c
leaq 0x9(%rsp), %rdx
movq %rbx, %rdi
callq 0x4596
movq %rbp, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x44c8
movq 0x8(%rbx), %rsi
orb $-0x80, %al
movb %al, 0xd(%rsp)
cmpq 0x10(%rbx), %rsi
je 0x432b
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x4338
leaq 0xd(%rsp), %rdx
movq %rbx, %rdi
callq 0x468a
movq %rbp, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x44c8
movq 0x8(%rbx), %rsi
orb $-0x80, %al
movb %al, 0xc(%rsp)
cmpq 0x10(%rbx), %rsi
je 0x4373
movb %al, (%rsi)
incq 0x8(%rbx)
movq 0x8(%rbx), %rsi
movq %rsi, %rax
subq (%rbx), %rax
cmpq 0x20(%rsp), %rax
jb 0x4055
jmp 0x4382
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x468a
jmp 0x435c
movb $0x0, 0xb(%rsp)
cmpq 0x10(%rbx), %rsi
je 0x4396
movb $0x0, (%rsi)
incq 0x8(%rbx)
jmp 0x43a3
leaq 0xb(%rsp), %rdx
movq %rbx, %rdi
callq 0x468a
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x43cf
jmp 0x43cf
jmp 0x43cf
jmp 0x43cf
jmp 0x43cf
jmp 0x43cf
jmp 0x43cf
jmp 0x43cf
jmp 0x43cf
jmp 0x43cf
jmp 0x43cf
jmp 0x43cf
jmp 0x43cf
movq (%rbx), %rdi
movq %rax, %r14
testq %rdi, %rdi
je 0x43e6
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x21d0
movq %r14, %rdi
callq 0x22b0