#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 *, char);
int /*<<< orphan*/ puts(char *);
int getVal(char card) {
  int val = 0;
  char name[3];
  printf("%c\n", card);
  switch (card) {
  case 'K':
  case 'Q':
  case 'J':
    val = 10;
    break;
  case 'A':
    val = 10;
    break;
  case 'X':
    val = -2;
    break;
  default:
    name[0] = card;
    val = atoi(name);
    if ((val < 1) || (val > 10)) {
      puts("not valid");
      val = -1;
    }
  }
  return val;
}


x86 assembly (clang, -O0):
<getVal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x0,-0x8(%rbp)
movsbl -0x1(%rbp),%esi
lea    0xf10(%rip),%rdi
call   1040 <printf@plt>
movsbl -0x1(%rbp),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x17,%eax
ja     11a3 <getVal+0x73>
mov    -0x18(%rbp),%rax
lea    0xe8a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xa,-0x8(%rbp)
jmp    11e1 <getVal+0xb1>
movl   $0xa,-0x8(%rbp)
jmp    11e1 <getVal+0xb1>
movl   $0xfffffffe,-0x8(%rbp)
jmp    11e1 <getVal+0xb1>
mov    -0x1(%rbp),%al
mov    %al,-0xb(%rbp)
lea    -0xb(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     11c9 <getVal+0x99>
cmpl   $0xa,-0x8(%rbp)
jle    11dc <getVal+0xac>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffffff,-0x8(%rbp)
jmp    11e1 <getVal+0xb1>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getVal>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xec2(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
lea    -0x41(%rbx),%ecx
cmp    $0x17,%ecx
ja     1168 <getVal+0x38>
mov    $0xa,%eax
mov    $0x10601,%edx
bt     %ecx,%edx
jb     1191 <getVal+0x61>
cmp    $0x17,%ecx
jne    1168 <getVal+0x38>
mov    $0xfffffffe,%eax
jmp    1191 <getVal+0x61>
mov    %bl,0xd(%rsp)
lea    0xd(%rsp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
add    $0xfffffff5,%ecx
cmp    $0xfffffff5,%ecx
ja     1191 <getVal+0x61>
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%c\0A\00"
@.str.1 = [10 x i8] c"not valid\00"
define i32 @getVal(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca [3 x i8]
store i8 %0, i8* %2
store i32 0, i32* %3
%5 = load i8, i8* %2
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %5)
%7 = load i8, i8* %2
%8 = sext i8 %7 to i32
switch i32 %8, label %12 [
i32 75, label %9
i32 81, label %9
i32 74, label %9
i32 65, label %10
i32 88, label %11
]
9: ; preds = %1, %1, %1
store i32 10, i32* %3
br label %25
10: ; preds = %1
store i32 10, i32* %3
br label %25
11: ; preds = %1
store i32 -2, i32* %3
br label %25
12: ; preds = %1
%13 = load i8, i8* %2
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
store i8 %13, i8* %14
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 1
br i1 %18, label %22, label %19
19: ; preds = %12
%20 = load i32, i32* %3
%21 = icmp sgt i32 %20, 10
br i1 %21, label %22, label %24
22: ; preds = %19, %12
%23 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %24
24: ; preds = %22, %19
br label %25
25: ; preds = %24, %11, %10, %9
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [4 x i8] c"%c\0A\00"
@.str.1 = [10 x i8] c"not valid\00"
define i32 @getVal(i8 signext %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %0)
%5 = sext i8 %0 to i32
switch i32 %5, label %7 [
i32 75, label %13
i32 81, label %13
i32 74, label %13
i32 65, label %13
i32 88, label %6
]
6: ; preds = %1
br label %13
7: ; preds = %1
store i8 %0, i8* %3
%8 = call i32 @atoi(i8* %3)
%9 = add i32 %8, -11
%10 = icmp ult i32 %9, -10
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %1, %1, %1, %1, %11, %7, %6
%14 = phi i32 [ -1, %11 ], [ %8, %7 ], [ -2, %6 ], [ 10, %1 ], [ 10, %1 ], [ 10, %1 ], [ 10, %1 ]
ret i32 %14
}