#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 /*<<< orphan*/ puts(char *);
int getVal(char *card_name) {
  int val = 0;
  switch (card_name[0]) {
  case 'K':
  case 'Q':
  case 'J':
    val = 10;
    break;
  case 'A':
    val = 11;
    break;
  case 'X':
    val = -1;
    break;
  default:
    val = atoi(card_name);
    if ((val < 1) || (val > 10)) {
      puts("I don't understand that value!");
      val = -1;
      break;
    }
  }
  return val;
}


x86 assembly (clang, -O0):
<getVal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x17,%eax
ja     1184 <getVal+0x64>
mov    -0x18(%rbp),%rax
lea    0xea9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xa,-0xc(%rbp)
jmp    11c1 <getVal+0xa1>
movl   $0xb,-0xc(%rbp)
jmp    11c1 <getVal+0xa1>
movl   $0xffffffff,-0xc(%rbp)
jmp    11c1 <getVal+0xa1>
mov    -0x8(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jl     11a4 <getVal+0x84>
cmpl   $0xa,-0xc(%rbp)
jle    11bc <getVal+0x9c>
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffffff,-0xc(%rbp)
jmp    11c1 <getVal+0xa1>
jmp    11c1 <getVal+0xa1>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getVal>:
push   %rax
movsbl (%rdi),%ecx
add    $0xffffffbf,%ecx
cmp    $0x17,%ecx
ja     1143 <getVal+0x23>
mov    $0xa,%eax
lea    0xec8(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
pop    %rcx
ret
call   1040 <atoi@plt>
mov    %eax,%ecx
add    $0xfffffff5,%ecx
cmp    $0xfffffff5,%ecx
ja     1141 <getVal+0x21>
lea    0xf07(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
mov    $0xb,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"I don't understand that value!\00"
define i32 @getVal(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
switch i32 %7, label %11 [
i32 75, label %8
i32 81, label %8
i32 74, label %8
i32 65, label %9
i32 88, label %10
]
8: ; preds = %1, %1, %1
store i32 10, i32* %3
br label %22
9: ; preds = %1
store i32 11, i32* %3
br label %22
10: ; preds = %1
store i32 -1, i32* %3
br label %22
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call i32 @atoi(i8* %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 1
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = load i32, i32* %3
%18 = icmp sgt i32 %17, 10
br i1 %18, label %19, label %21
19: ; preds = %16, %11
%20 = call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %22
21: ; preds = %16
br label %22
22: ; preds = %21, %19, %10, %9, %8
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [31 x i8] c"I don't understand that value!\00"
define i32 @getVal(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = sext i8 %2 to i32
switch i32 %3, label %6 [
i32 75, label %12
i32 81, label %12
i32 74, label %12
i32 65, label %4
i32 88, label %5
]
4: ; preds = %1
br label %12
5: ; preds = %1
br label %12
6: ; preds = %1
%7 = tail call i32 @atoi(i8* %0)
%8 = add i32 %7, -11
%9 = icmp ult i32 %8, -10
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %1, %1, %1, %6, %10, %5, %4
%13 = phi i32 [ -1, %10 ], [ %7, %6 ], [ -1, %5 ], [ 11, %4 ], [ 10, %1 ], [ 10, %1 ], [ 10, %1 ]
ret i32 %13
}