#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 */
typedef size_t int8_t;

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const);
int /*<<< orphan*/ stderr;
size_t strlen(char const *);
int8_t _char2int(const char c) {
  static const char chr[] = "0123456789";
  for (size_t i = 0, l = strlen(chr); i < l; i++) {
    if (c == chr[i])
      return i;
  }
  fprintf(stderr, "assertion failure. unexpected char:%c\n", c);
  abort();
}


x86 assembly (clang, -O0):
<_char2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    119f <_char2int+0x6f>
movsbl -0x1(%rbp),%eax
mov    -0x10(%rbp),%rdx
lea    0xe8d(%rip),%rcx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    1189 <_char2int+0x59>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret
jmp    118e <_char2int+0x5e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1156 <_char2int+0x26>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
movsbl -0x1(%rbp),%edx
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>

x86 assembly (clang, -O2):
<_char2int>:
lea    -0x30(%rdi),%eax
cmp    $0xa,%al
jae    112b <_char2int+0xb>
movzbl %al,%eax
ret
push   %rax
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
movsbl %dil,%edx
lea    0xec0(%rip),%rsi
mov    %eax,%edi
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@_char2int.chr = internal constant [11 x i8] c"0123456789\00"
@stderr = global i32 0
@.str = [39 x i8] c"assertion failure. unexpected char:%c\0A\00"
define i64 @_char2int(i8 signext %0) {
%2 = alloca i8
%3 = alloca i64
%4 = alloca i64
store i8 %0, i8* %2
store i64 0, i64* %3
%5 = call i64 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @_char2int.chr, i64 0, i64 0))
store i64 %5, i64* %4
br label %6
6: ; preds = %21, %1
%7 = load i64, i64* %3
%8 = load i64, i64* %4
%9 = icmp ult i64 %7, %8
br i1 %9, label %10, label %24
10: ; preds = %6
%11 = load i8, i8* %2
%12 = sext i8 %11 to i32
%13 = load i64, i64* %3
%14 = getelementptr inbounds [11 x i8], [11 x i8]* @_char2int.chr, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %12, %16
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = load i64, i64* %3
ret i64 %19
20: ; preds = %10
br label %21
21: ; preds = %20
%22 = load i64, i64* %3
%23 = add i64 %22, 1
store i64 %23, i64* %3
br label %6
24: ; preds = %6
%25 = load i32, i32* @stderr
%26 = load i8, i8* %2
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8 signext %26)
%28 = call i32 (...) @abort()
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"assertion failure. unexpected char:%c\0A\00"
define i64 @_char2int(i8 signext %0) {
%2 = add i8 %0, -48
%3 = icmp ult i8 %2, 10
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8 signext %0)
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %1
%9 = zext i8 %2 to i64
ret i64 %9
}