#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 *);
int readVal(char buffer[4]) {
  int value = 0;
  if (buffer[0] >= 'A') {
    switch (buffer[0]) {
    case 'J': {
      value = 11;
    } break;
    case 'Q': {
      value = 12;
    } break;
    case 'K': {
      value = 13;
    } break;
    case 'A': {
      value = 14;
    } break;
    }
  } else {
    value = atoi(buffer);
  }
  return value;
}


x86 assembly (clang, -O0):
<readVal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x41,%eax
jl     1190 <readVal+0x80>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x10,%eax
ja     118b <readVal+0x7b>
mov    -0x18(%rbp),%rax
lea    0xea9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xb,-0xc(%rbp)
jmp    118b <readVal+0x7b>
movl   $0xc,-0xc(%rbp)
jmp    118b <readVal+0x7b>
movl   $0xd,-0xc(%rbp)
jmp    118b <readVal+0x7b>
movl   $0xe,-0xc(%rbp)
jmp    119c <readVal+0x8c>
mov    -0x8(%rbp),%rdi
call   1030 <atoi@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readVal>:
mov    (%rdi),%cl
cmp    $0x41,%cl
jl     113a <readVal+0x2a>
xor    %eax,%eax
add    $0xbf,%cl
cmp    $0x10,%cl
ja     1144 <readVal+0x34>
movzbl %cl,%ecx
lea    0xed5(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0xe,%eax
ret
jmp    1030 <atoi@plt>
mov    $0xb,%eax
ret
mov    $0xd,%eax
ret
mov    $0xc,%eax
ret

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

LLVM IR (-O2):
define i32 @readVal(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp sgt i8 %2, 64
br i1 %3, label %4, label %9
4: ; preds = %1
switch i8 %2, label %11 [
i8 74, label %5
i8 81, label %6
i8 75, label %7
i8 65, label %8
]
5: ; preds = %4
br label %11
6: ; preds = %4
br label %11
7: ; preds = %4
br label %11
8: ; preds = %4
br label %11
9: ; preds = %1
%10 = tail call i32 @atoi(i8* %0)
br label %11
11: ; preds = %5, %6, %7, %8, %4, %9
%12 = phi i32 [ 0, %4 ], [ 14, %8 ], [ 13, %7 ], [ 12, %6 ], [ 11, %5 ], [ %10, %9 ]
ret i32 %12
}