#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 card_value(char card_name[]) {
  int val = 0;
  switch (card_name[0]) {
  case 'K':
  case 'Q':
  case 'J':
    val = 10;
    break;
  case 'A':
    val = 11;
    break;
  default:
    val = atoi(card_name);
    if (!(val > 0 && val < 11))
      val = 0;
  }
  return val;
}


x86 assembly (clang, -O0):
<card_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x10(%rbp)
sub    $0x41,%eax
je     116c <card_value+0x5c>
jmp    113b <card_value+0x2b>
mov    -0x10(%rbp),%eax
add    $0xffffffb6,%eax
sub    $0x2,%eax
jb     1160 <card_value+0x50>
jmp    114f <card_value+0x3f>
mov    -0x10(%rbp),%eax
sub    $0x51,%eax
jne    1178 <card_value+0x68>
jmp    1160 <card_value+0x50>
movl   $0xa,-0xc(%rbp)
jmp    11a4 <card_value+0x94>
movl   $0xb,-0xc(%rbp)
jmp    11a4 <card_value+0x94>
mov    -0x8(%rbp),%rdi
call   1030 <atoi@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1198 <card_value+0x88>
cmpl   $0xb,-0xc(%rbp)
jl     119f <card_value+0x8f>
movl   $0x0,-0xc(%rbp)
jmp    11a4 <card_value+0x94>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<card_value>:
push   %rax
movsbl (%rdi),%ecx
mov    $0xa,%eax
lea    -0x4a(%rcx),%edx
cmp    $0x2,%edx
jb     1144 <card_value+0x34>
cmp    $0x51,%ecx
je     1144 <card_value+0x34>
cmp    $0x41,%ecx
jne    1132 <card_value+0x22>
mov    $0xb,%eax
pop    %rcx
ret
call   1030 <atoi@plt>
mov    %eax,%ecx
lea    -0x1(%rcx),%edx
xor    %eax,%eax
cmp    $0xa,%edx
cmovb  %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @card_value(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 %10 [
i32 75, label %8
i32 81, label %8
i32 74, label %8
i32 65, label %9
]
8: ; preds = %1, %1, %1
store i32 10, i32* %3
br label %20
9: ; preds = %1
store i32 11, i32* %3
br label %20
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @atoi(i8* %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 11
br i1 %17, label %19, label %18
18: ; preds = %15, %10
store i32 0, i32* %3
br label %19
19: ; preds = %18, %15
br label %20
20: ; preds = %19, %9, %8
%21 = load i32, i32* %3
ret i32 %21
}

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