#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 */
int atoi(char *);
char *malloc(int);
int char_to_int(char cardValue) {
  int integerValue = 0;
  switch (cardValue) {
  case 'T':
    integerValue = 10;
    break;
  case 'J':
    integerValue = 11;
    break;
  case 'Q':
    integerValue = 12;
    break;
  case 'K':
    integerValue = 13;
    break;
  case 'A':
    integerValue = 14;
    break;
  default:
    if (cardValue >= 0x32 && cardValue <= 0x39) {
      char *str = malloc(sizeof(char) * 2);
      str[1] = '\0';
      str[0] = cardValue;
      integerValue = atoi(str);
    }
    break;
  }
  return integerValue;
}


x86 assembly (clang, -O0):
<char_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x0,-0x8(%rbp)
movsbl -0x1(%rbp),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x13,%eax
ja     119b <char_to_int+0x7b>
mov    -0x18(%rbp),%rax
lea    0xeaa(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xa,-0x8(%rbp)
jmp    11e5 <char_to_int+0xc5>
movl   $0xb,-0x8(%rbp)
jmp    11e5 <char_to_int+0xc5>
movl   $0xc,-0x8(%rbp)
jmp    11e5 <char_to_int+0xc5>
movl   $0xd,-0x8(%rbp)
jmp    11e5 <char_to_int+0xc5>
movl   $0xe,-0x8(%rbp)
jmp    11e5 <char_to_int+0xc5>
movsbl -0x1(%rbp),%eax
cmp    $0x32,%eax
jl     11e0 <char_to_int+0xc0>
movsbl -0x1(%rbp),%eax
cmp    $0x39,%eax
jg     11e0 <char_to_int+0xc0>
mov    $0x2,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x1(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x8(%rbp)
jmp    11e5 <char_to_int+0xc5>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_to_int>:
push   %rbx
mov    %edi,%ebx
lea    -0x41(%rbx),%ecx
cmp    $0x13,%ecx
ja     1147 <char_to_int+0x27>
mov    $0xa,%eax
lea    0xec9(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0xe,%eax
pop    %rbx
ret
lea    -0x32(%rbx),%ecx
xor    %eax,%eax
cmp    $0x7,%cl
ja     116f <char_to_int+0x4f>
mov    $0x2,%edi
call   1030 <malloc@plt>
movb   $0x0,0x1(%rax)
mov    %bl,(%rax)
mov    %rax,%rdi
pop    %rbx
jmp    1040 <atoi@plt>
mov    $0xb,%eax
pop    %rbx
ret
mov    $0xd,%eax
pop    %rbx
ret
mov    $0xc,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @char_to_int(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i8*
store i8 %0, i8* %2
store i32 0, i32* %3
%5 = load i8, i8* %2
%6 = sext i8 %5 to i32
switch i32 %6, label %12 [
i32 84, label %7
i32 74, label %8
i32 81, label %9
i32 75, label %10
i32 65, label %11
]
7: ; preds = %1
store i32 10, i32* %3
br label %30
8: ; preds = %1
store i32 11, i32* %3
br label %30
9: ; preds = %1
store i32 12, i32* %3
br label %30
10: ; preds = %1
store i32 13, i32* %3
br label %30
11: ; preds = %1
store i32 14, i32* %3
br label %30
12: ; preds = %1
%13 = load i8, i8* %2
%14 = sext i8 %13 to i32
%15 = icmp sge i32 %14, 50
br i1 %15, label %16, label %29
16: ; preds = %12
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = icmp sle i32 %18, 57
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = call i8* @malloc(i32 2)
store i8* %21, i8** %4
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 0, i8* %23
%24 = load i8, i8* %2
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 0
store i8 %24, i8* %26
%27 = load i8*, i8** %4
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %3
br label %29
29: ; preds = %20, %16, %12
br label %30
30: ; preds = %29, %11, %10, %9, %8, %7
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
define i32 @char_to_int(i8 signext %0) {
%2 = sext i8 %0 to i32
switch i32 %2, label %7 [
i32 84, label %14
i32 74, label %3
i32 81, label %4
i32 75, label %5
i32 65, label %6
]
3: ; preds = %1
br label %14
4: ; preds = %1
br label %14
5: ; preds = %1
br label %14
6: ; preds = %1
br label %14
7: ; preds = %1
%8 = add i8 %0, -50
%9 = icmp ult i8 %8, 8
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = tail call dereferenceable_or_null(2) i8* @malloc(i32 2)
%12 = getelementptr inbounds i8, i8* %11, i64 1
store i8 0, i8* %12
store i8 %0, i8* %11
%13 = tail call i32 @atoi(i8* %11)
br label %14
14: ; preds = %1, %7, %10, %6, %5, %4, %3
%15 = phi i32 [ %13, %10 ], [ 0, %7 ], [ 14, %6 ], [ 13, %5 ], [ 12, %4 ], [ 11, %3 ], [ 10, %1 ]
ret i32 %15
}