#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
char __tolower(char);
int hex_to_bin(char ch) {
  if ((ch >= '0') && (ch <= '9'))
    return ch - '0';
  ch = __tolower(ch);
  if ((ch >= 'a') && (ch <= 'f'))
    return ch - 'a' + 10;
  return -1;
}


x86 assembly (clang, -O0):
<hex_to_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x30,%eax
jl     1147 <hex_to_bin+0x37>
movsbl -0x5(%rbp),%eax
cmp    $0x39,%eax
jg     1147 <hex_to_bin+0x37>
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    1186 <hex_to_bin+0x76>
movsbl -0x5(%rbp),%edi
call   1030 <__tolower@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x61,%eax
jl     117f <hex_to_bin+0x6f>
movsbl -0x5(%rbp),%eax
cmp    $0x66,%eax
jg     117f <hex_to_bin+0x6f>
movsbl -0x5(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    1186 <hex_to_bin+0x76>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_to_bin>:
lea    -0x30(%rdi),%eax
cmp    $0x9,%al
ja     111f <hex_to_bin+0xf>
movzbl %dil,%eax
add    $0xffffffd0,%eax
ret
push   %rax
movsbl %dil,%edi
call   1030 <__tolower@plt>
mov    %eax,%ecx
lea    -0x61(%rcx),%edx
mov    $0xffffffff,%eax
cmp    $0x5,%dl
lea    0x8(%rsp),%rsp
ja     1143 <hex_to_bin+0x33>
movzbl %cl,%eax
add    $0xffffffa9,%eax
ret

LLVM IR (-O0):
define i32 @hex_to_bin(i8 signext %0) {
%2 = alloca i32
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = sext i8 %4 to i32
%6 = icmp sge i32 %5, 48
br i1 %6, label %7, label %15
7: ; preds = %1
%8 = load i8, i8* %3
%9 = sext i8 %8 to i32
%10 = icmp sle i32 %9, 57
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
%14 = sub nsw i32 %13, 48
store i32 %14, i32* %2
br label %31
15: ; preds = %7, %1
%16 = load i8, i8* %3
%17 = call signext i8 @__tolower(i8 signext %16)
store i8 %17, i8* %3
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = icmp sge i32 %19, 97
br i1 %20, label %21, label %30
21: ; preds = %15
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
%24 = icmp sle i32 %23, 102
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i8, i8* %3
%27 = sext i8 %26 to i32
%28 = sub nsw i32 %27, 97
%29 = add nsw i32 %28, 10
store i32 %29, i32* %2
br label %31
30: ; preds = %21, %15
store i32 -1, i32* %2
br label %31
31: ; preds = %30, %25, %11
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
define i32 @hex_to_bin(i8 signext %0) {
%2 = add i8 %0, -48
%3 = icmp ult i8 %2, 10
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = zext i8 %0 to i32
%6 = add nsw i32 %5, -48
br label %14
7: ; preds = %1
%8 = tail call signext i8 @__tolower(i8 signext %0)
%9 = add i8 %8, -97
%10 = icmp ult i8 %9, 6
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = zext i8 %8 to i32
%13 = add nsw i32 %12, -87
br label %14
14: ; preds = %7, %11, %4
%15 = phi i32 [ %6, %4 ], [ %13, %11 ], [ -1, %7 ]
ret i32 %15
}