// File: /workspace/github_c_makefile_star2_O0/Seclabs-htc[P]slip39/misc.c
// Function: fromhex
int fromhex(uint8_t *buf, uint32_t *buf_len, const char *str)
{
    size_t i, len = strlen(str) / 2;

    if (len > *buf_len)
        return -1;

    for (i = 0; i < len; i++) {
        uint8_t c = 0;
        if (str[i * 2] >= '0' && str[i*2] <= '9') c += (str[i * 2] - '0') << 4;
        if ((str[i * 2] & ~0x20) >= 'A' && (str[i*2] & ~0x20) <= 'F') c += (10 + (str[i * 2] & ~0x20) - 'A') << 4;
        if (str[i * 2 + 1] >= '0' && str[i * 2 + 1] <= '9') c += (str[i * 2 + 1] - '0');
        if ((str[i * 2 + 1] & ~0x20) >= 'A' && (str[i * 2 + 1] & ~0x20) <= 'F') c += (10 + (str[i * 2 + 1] & ~0x20) - 'A');
        buf[i] = c;
    }
    *buf_len = len;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x8040
shrq %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
cmpq %rcx, %rax
jbe 0xdfef
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe16b
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0xe158
movb $0x0, -0x31(%rbp)
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shlq %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x30, %eax
jl 0xe04f
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shlq %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x39, %eax
jg 0xe04f
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shlq %rcx
movsbl (%rax,%rcx), %ecx
subl $0x30, %ecx
shll $0x4, %ecx
movzbl -0x31(%rbp), %eax
addl %ecx, %eax
movb %al, -0x31(%rbp)
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shlq %rcx
movsbl (%rax,%rcx), %eax
andl $-0x21, %eax
cmpl $0x41, %eax
jl 0xe0a1
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shlq %rcx
movsbl (%rax,%rcx), %eax
andl $-0x21, %eax
cmpl $0x46, %eax
jg 0xe0a1
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shlq %rcx
movsbl (%rax,%rcx), %ecx
andl $-0x21, %ecx
addl $0xa, %ecx
subl $0x41, %ecx
shll $0x4, %ecx
movzbl -0x31(%rbp), %eax
addl %ecx, %eax
movb %al, -0x31(%rbp)
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shlq %rcx
movsbl 0x1(%rax,%rcx), %eax
cmpl $0x30, %eax
jl 0xe0e7
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shlq %rcx
movsbl 0x1(%rax,%rcx), %eax
cmpl $0x39, %eax
jg 0xe0e7
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shlq %rcx
movsbl 0x1(%rax,%rcx), %ecx
subl $0x30, %ecx
movzbl -0x31(%rbp), %eax
addl %ecx, %eax
movb %al, -0x31(%rbp)
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shlq %rcx
movsbl 0x1(%rax,%rcx), %eax
andl $-0x21, %eax
cmpl $0x41, %eax
jl 0xe139
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shlq %rcx
movsbl 0x1(%rax,%rcx), %eax
andl $-0x21, %eax
cmpl $0x46, %eax
jg 0xe139
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shlq %rcx
movsbl 0x1(%rax,%rcx), %ecx
andl $-0x21, %ecx
addl $0xa, %ecx
subl $0x41, %ecx
movzbl -0x31(%rbp), %eax
addl %ecx, %eax
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %dl
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0xdff7
movq -0x30(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)