#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*/ printf(char *);
int get_card_val(int val, char card_name[]) {
  switch (card_name[0]) {
  case 'J':
  case 'Q':
  case 'K':
    val = 10;
    break;
  case 'X':
    val = 0;
  default:
    val = atoi(card_name);
    if (val < 1 || val > 10) {
      printf("Invalid card value. Try again\n");
      val = 0;
    }
  }
  return val;
}


x86 assembly (clang, -O0):
<get_card_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
add    $0xffffffb6,%eax
sub    $0x2,%eax
jb     116c <get_card_val+0x4c>
jmp    114a <get_card_val+0x2a>
mov    -0x14(%rbp),%eax
sub    $0x51,%eax
je     116c <get_card_val+0x4c>
jmp    115b <get_card_val+0x3b>
mov    -0x14(%rbp),%eax
sub    $0x58,%eax
je     1178 <get_card_val+0x58>
jmp    117f <get_card_val+0x5f>
movl   $0xa,-0x4(%rbp)
jmp    11b7 <get_card_val+0x97>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jl     119f <get_card_val+0x7f>
cmpl   $0xa,-0x4(%rbp)
jle    11b2 <get_card_val+0x92>
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <get_card_val+0x97>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_card_val>:
push   %rax
movsbl (%rsi),%ecx
add    $0xffffffb6,%ecx
cmp    $0x7,%ecx
ja     113d <get_card_val+0x1d>
mov    $0xa,%eax
mov    $0x83,%edx
bt     %ecx,%edx
jae    113d <get_card_val+0x1d>
pop    %rcx
ret
mov    %rsi,%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
add    $0xfffffff5,%ecx
cmp    $0xfffffff5,%ecx
ja     113b <get_card_val+0x1b>
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Invalid card value. Try again\0A\00"
define i32 @get_card_val(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
switch i32 %8, label %11 [
i32 74, label %9
i32 81, label %9
i32 75, label %9
i32 88, label %10
]
9: ; preds = %2, %2, %2
store i32 10, i32* %3
br label %22
10: ; preds = %2
store i32 0, i32* %3
br label %11
11: ; preds = %2, %10
%12 = load i8*, i8** %4
%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 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %21
21: ; preds = %19, %16
br label %22
22: ; preds = %21, %9
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@str = [30 x i8] c"Invalid card value. Try again\00"
define i32 @get_card_val(i32 %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = sext i8 %3 to i32
switch i32 %4, label %5 [
i32 74, label %11
i32 81, label %11
i32 75, label %11
]
5: ; preds = %2
%6 = tail call i32 @atoi(i8* %1)
%7 = add i32 %6, -11
%8 = icmp ult i32 %7, -10
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %2, %2, %2, %9, %5
%12 = phi i32 [ 0, %9 ], [ %6, %5 ], [ 10, %2 ], [ 10, %2 ], [ 10, %2 ]
ret i32 %12
}