// File: /workspace/github_cpp_makefile_star2_O3/night-shift[P]Srl/src/lib/ToolsBtsConv.cpp
// Function: GLOBAL__sub_I_ToolsBtsConv.cpp
void Tools::hex_to_bytes(uint8_t* dest, size_t dest_size, const uint8_t* str, size_t str_len)
{
    if(str_len % 2 != 0) {
        throw Exception("Unable to convert hex string to binary data. Size of source must be even.");
    }

    if(dest_size < str_len / 2) {
        throw Exception("Unable to convert hex string to binary data. Destination buffer too small.");
    }

    const auto conv = [](uint8_t& c) {
        if(c >= '0' && c <= '9') {
            c -= '0';

        } else if(c >= 'A' && c <= 'F') {
            c = (c - 'A') + 10;

        } else if(c >= 'a' && c <= 'f') {
            c = (c - 'a') + 10;

        } else {
            throw Exception("Unable to convert hex string to binary data. String malformed.");
        }
    };

    uint8_t low = 0, high = 0;
    uint8_t packed = 0;

    for (size_t in_idx = 0, out_idx = 0; in_idx < str_len;
                in_idx += 2, out_idx++) {

        high = str[in_idx];
        low  = str[in_idx + 1];

        conv(high);
        conv(low);

        packed = (high << 4U) | low;
        dest[out_idx] = packed;
    }
}

// Assembly:
pushq %rbx
leaq 0x1aef8(%rip), %rax     # 0x28710
movq %rax, 0x1aee1(%rip)     # 0x28700
movl $0x6c6f6f42, 0x1aee7(%rip) # imm = 0x6C6F6F42
movl $0x4, %eax
movq %rax, 0x1aed3(%rip)     # 0x28708
xorl %ebx, %ebx
movb %bl, 0x1aed7(%rip)      # 0x28714
leaq 0x1aeec(%rip), %rcx     # 0x28730
movq %rcx, 0x1aed5(%rip)     # 0x28720
movw $0x3849, 0x1aedc(%rip)  # imm = 0x3849
movq $0x2, 0x1aec9(%rip) # 0x28728
movb %bl, 0x1aecd(%rip)      # 0x28732
leaq 0x1aee4(%rip), %rcx     # 0x28750
movq %rcx, 0x1aecd(%rip)     # 0x28740
movl $0x384955, 0x1aed3(%rip) # imm = 0x384955
movl $0x3, %ecx
movq %rcx, 0x1aebf(%rip)     # 0x28748
leaq 0x1aee0(%rip), %rdx     # 0x28770
movq %rdx, 0x1aec9(%rip)     # 0x28760
movl $0x363149, 0x1aecf(%rip) # imm = 0x363149
movq %rcx, 0x1aec0(%rip)     # 0x28768
leaq 0x1aee1(%rip), %rdx     # 0x28790
movq %rdx, 0x1aeca(%rip)     # 0x28780
movl $0x36314955, 0x1aed0(%rip) # imm = 0x36314955
movq %rax, 0x1aec1(%rip)     # 0x28788
movb %bl, 0x1aec7(%rip)      # 0x28794
leaq 0x1aedc(%rip), %rdx     # 0x287b0
movq %rdx, 0x1aec5(%rip)     # 0x287a0
movl $0x323349, 0x1aecb(%rip) # imm = 0x323349
movq %rcx, 0x1aebc(%rip)     # 0x287a8
leaq 0x1aedd(%rip), %rdx     # 0x287d0
movq %rdx, 0x1aec6(%rip)     # 0x287c0
movl $0x32334955, 0x1aecc(%rip) # imm = 0x32334955
movq %rax, 0x1aebd(%rip)     # 0x287c8
movb %bl, 0x1aec3(%rip)      # 0x287d4
leaq 0x1aed8(%rip), %rdx     # 0x287f0
movq %rdx, 0x1aec1(%rip)     # 0x287e0
movl $0x343649, 0x1aec7(%rip) # imm = 0x343649
movq %rcx, 0x1aeb8(%rip)     # 0x287e8
leaq 0x1aed9(%rip), %rcx     # 0x28810
movq %rcx, 0x1aec2(%rip)     # 0x28800
movl $0x34364955, 0x1aec8(%rip) # imm = 0x34364955
movq %rax, 0x1aeb9(%rip)     # 0x28808
movb %bl, 0x1aebf(%rip)      # 0x28814
leaq 0x1aed4(%rip), %rcx     # 0x28830
movq %rcx, 0x1aebd(%rip)     # 0x28820
movl $0x32335046, 0x1aec3(%rip) # imm = 0x32335046
movq %rax, 0x1aeb4(%rip)     # 0x28828
movb %bl, 0x1aeba(%rip)      # 0x28834
leaq 0x1aecf(%rip), %rcx     # 0x28850
movq %rcx, 0x1aeb8(%rip)     # 0x28840
movl $0x34365046, 0x1aebe(%rip) # imm = 0x34365046
movq %rax, 0x1aeaf(%rip)     # 0x28848
movb %bl, 0x1aeb5(%rip)      # 0x28854
leaq 0x1aeca(%rip), %rcx     # 0x28870
movq %rcx, 0x1aeb3(%rip)     # 0x28860
movl $0x6c6c754e, 0x1aeb9(%rip) # imm = 0x6C6C754E
movq %rax, 0x1aeaa(%rip)     # 0x28868
movb %bl, 0x1aeb0(%rip)      # 0x28874
leaq 0x1aec5(%rip), %rax     # 0x28890
movq %rax, 0x1aeae(%rip)     # 0x28880
movw $0x676e, 0x1aeb9(%rip)  # imm = 0x676E
movl $0x69727453, 0x1aeab(%rip) # imm = 0x69727453
movl $0x6, %eax
movq %rax, 0x1ae97(%rip)     # 0x28888
movb %bl, 0x1ae9f(%rip)      # 0x28896
leaq 0x1aeb2(%rip), %rcx     # 0x288b0
movq %rcx, 0x1ae9b(%rip)     # 0x288a0
movw $0x7972, 0x1aea6(%rip)  # imm = 0x7972
movl $0x616e6942, 0x1ae98(%rip) # imm = 0x616E6942
movq %rax, 0x1ae89(%rip)     # 0x288a8
movb %bl, 0x1ae91(%rip)      # 0x288b6
leaq 0x1aea4(%rip), %rcx     # 0x288d0
movq %rcx, 0x1ae8d(%rip)     # 0x288c0
movw $0x7463, 0x1ae98(%rip)  # imm = 0x7463
movl $0x656a624f, 0x1ae8a(%rip) # imm = 0x656A624F
movq %rax, 0x1ae7b(%rip)     # 0x288c8
movb %bl, 0x1ae83(%rip)      # 0x288d6
leaq 0x1ae96(%rip), %rax     # 0x288f0
movq %rax, 0x1ae7f(%rip)     # 0x288e0
movb $0x79, 0x1ae8c(%rip)    # 0x288f4
movl $0x61727241, 0x1ae7e(%rip) # imm = 0x61727241
movq $0x5, 0x1ae6b(%rip) # 0x288e8
movb %bl, 0x1ae72(%rip)      # 0x288f5
leaq 0x1ae86(%rip), %rax     # 0x28910
movq %rax, 0x1ae6f(%rip)     # 0x28900
movabsq $0x6e455f65706f6353, %rax # imm = 0x6E455F65706F6353
movq %rax, 0x1ae6e(%rip)     # 0x28910
movb $0x64, 0x1ae6f(%rip)    # 0x28918
movq $0x9, 0x1ae54(%rip) # 0x28908
movb %bl, 0x1ae5f(%rip)      # 0x28919
leaq -0x2f1(%rip), %rdi      # 0xd7d0
leaq 0x19d60(%rip), %rdx     # 0x27828
xorl %esi, %esi
callq 0xb840
leaq 0x105a9(%rip), %rax     # 0x1e07f
movq %rax, 0x1ae43(%rip)     # 0x28920
movl $0x3, 0x1ae41(%rip)     # 0x28928
movw $0x10c, %ax             # imm = 0x10C
movw %ax, 0x1ae3a(%rip)      # 0x2892c
movb %bl, 0x1ae36(%rip)      # 0x2892e
leaq 0x10557(%rip), %rcx     # 0x1e056
movq %rcx, 0x1ae2a(%rip)     # 0x28930
movl $0x5, %ecx
movl %ecx, 0x1ae27(%rip)     # 0x28938
movw %ax, 0x1ae24(%rip)      # 0x2893c
movb %bl, 0x1ae20(%rip)      # 0x2893e
leaq 0x10549(%rip), %rdx     # 0x1e06e
movq %rdx, 0x1ae14(%rip)     # 0x28940
movl %ecx, 0x1ae16(%rip)     # 0x28948
movw %ax, 0x1ae13(%rip)      # 0x2894c
movb %bl, 0x1ae0f(%rip)      # 0x2894e
leaq 0x10516(%rip), %rcx     # 0x1e05c
movq %rcx, 0x1ae03(%rip)     # 0x28950
movl $0x6, 0x1ae01(%rip)     # 0x28958
movw %ax, 0x1adfe(%rip)      # 0x2895c
movb %bl, 0x1adfa(%rip)      # 0x2895e
leaq 0x104f8(%rip), %rcx     # 0x1e063
movq %rcx, 0x1adee(%rip)     # 0x28960
movl $0x10, 0x1adec(%rip)    # 0x28968
movw %ax, 0x1ade9(%rip)      # 0x2896c
movb %bl, 0x1ade5(%rip)      # 0x2896e
leaq 0x104e4(%rip), %rcx     # 0x1e074
movq %rcx, 0x1add9(%rip)     # 0x28970
movl $0xe, 0x1add7(%rip)     # 0x28978
movw %ax, 0x1add4(%rip)      # 0x2897c
movb %bl, 0x1add0(%rip)      # 0x2897e
leaq 0x104ce(%rip), %rcx     # 0x1e083
movq %rcx, 0x1adc4(%rip)     # 0x28980
movl $0xb, 0x1adc2(%rip)     # 0x28988
movw %ax, 0x1adbf(%rip)      # 0x2898c
movb %bl, 0x1adbb(%rip)      # 0x2898e
movq $0x0, 0x1adb2(%rip) # 0x28990
movl $0x0, 0x1adb0(%rip)     # 0x28998
movw %ax, 0x1adad(%rip)      # 0x2899c
movb %bl, 0x1ada9(%rip)      # 0x2899e
popq %rbx
retq