#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 lowercase(int);
int strlen(char *);
int eval_digit(int c) {
  int i;
  char d[] = "0123456789abcdef";
  int dlen = strlen(d);
  for (i = 0; i < dlen; i++) {
    if (lowercase(c) == d[i]) {
      return i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<eval_digit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xecb(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xec9(%rip),%al
mov    %al,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11a3 <eval_digit+0x83>
mov    -0x8(%rbp),%edi
call   1040 <lowercase@plt>
movsbl %al,%eax
movslq -0xc(%rbp),%rcx
movsbl -0x20(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
jne    1190 <eval_digit+0x70>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11aa <eval_digit+0x8a>
jmp    1195 <eval_digit+0x75>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115d <eval_digit+0x3d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eval_digit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r15d
movaps 0xecc(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
mov    %rsp,%rdi
call   1030 <strlen@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
jle    117b <eval_digit+0x5b>
mov    %eax,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15d,%edi
call   1040 <lowercase@plt>
cmp    (%rsp,%rbp,1),%al
je     1178 <eval_digit+0x58>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <eval_digit+0x40>
jmp    117b <eval_digit+0x5b>
mov    %ebp,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.eval_digit.d = [17 x i8] c"0123456789abcdef\00"
define i32 @eval_digit(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [17 x i8]
%6 = alloca i32
store i32 %0, i32* %3
%7 = bitcast [17 x i8]* %5 to i8*
%8 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
store i32 0, i32* %4
br label %10
10: ; preds = %27, %1
%11 = load i32, i32* %4
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %30
14: ; preds = %10
%15 = load i32, i32* %3
%16 = call signext i8 @lowercase(i32 %15)
%17 = sext i8 %16 to i32
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %17, %22
br i1 %23, label %24, label %26
24: ; preds = %14
%25 = load i32, i32* %4
store i32 %25, i32* %2
br label %31
26: ; preds = %14
br label %27
27: ; preds = %26
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %10
30: ; preds = %10
store i32 -1, i32* %2
br label %31
31: ; preds = %30, %24
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@__const.eval_digit.d = [17 x i8] c"0123456789abcdef\00"
define i32 @eval_digit(i32 %0) {
%2 = alloca [17 x i8]
%3 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%4 = call i32 @strlen(i8* %3)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %19
6: ; preds = %1
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %14
%9 = phi i64 [ 0, %6 ], [ %15, %14 ]
%10 = call signext i8 @lowercase(i32 %0)
%11 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 %9
%12 = load i8, i8* %11
%13 = icmp eq i8 %10, %12
br i1 %13, label %17, label %14
14: ; preds = %8
%15 = add nuw nsw i64 %9, 1
%16 = icmp eq i64 %15, %7
br i1 %16, label %19, label %8
17: ; preds = %8
%18 = trunc i64 %9 to i32
br label %19
19: ; preds = %14, %17, %1
%20 = phi i32 [ -1, %1 ], [ %18, %17 ], [ -1, %14 ]
ret i32 %20
}