#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);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char card_name[3];
  int count = 0;
  while (card_name[0] != 'X') {
    puts("Enter the card_name: ");
    scanf("%2s", 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':
      continue;
    default:
      val = atoi(card_name);
    }
    if (val < 1 || val > 10) {
      puts("Card value is out of the range, please start over");
      continue;
    }
    if ((val > 2) && (val < 7)) {
      count++;
    } else if (val == 10) {
      count--;
    }
    printf("Current count: %i/n", count);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movsbl -0x7(%rbp),%eax
cmp    $0x58,%eax
je     124c <main+0x10c>
lea    0xef6(%rip),%rdi
call   1030 <puts@plt>
lea    0xf00(%rip),%rdi
lea    -0x7(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0x10(%rbp)
movsbl -0x7(%rbp),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x17,%eax
ja     11cd <main+0x8d>
mov    -0x18(%rbp),%rax
lea    0xe59(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xa,-0x10(%rbp)
jmp    11d9 <main+0x99>
movl   $0xb,-0x10(%rbp)
jmp    11d9 <main+0x99>
jmp    1156 <main+0x16>
lea    -0x7(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jl     11ed <main+0xad>
cmpl   $0xa,-0x10(%rbp)
jle    11fe <main+0xbe>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
jmp    1156 <main+0x16>
cmpl   $0x2,-0x10(%rbp)
jle    1220 <main+0xe0>
cmpl   $0x7,-0x10(%rbp)
jge    1220 <main+0xe0>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1238 <main+0xf8>
cmpl   $0xa,-0x10(%rbp)
jne    1233 <main+0xf3>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1238 <main+0xf8>
mov    -0xc(%rbp),%esi
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
jmp    1156 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r13d,%r13d
lea    0xf0b(%rip),%r14
lea    0xf1a(%rip),%r15
lea    0x5(%rsp),%rbx
lea    0xe98(%rip),%r12
jmp    1185 <main+0x45>
nopw   0x0(%rax,%rax,1)
lea    0xf03(%rip),%rdi
call   1030 <puts@plt>
movzbl 0x5(%rsp),%eax
cmp    $0x58,%al
je     11f5 <main+0xb5>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
movsbl 0x5(%rsp),%eax
lea    -0x41(%rax),%ecx
cmp    $0x17,%ecx
ja     11d1 <main+0x91>
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
lea    0x1(%r13),%ebp
xor    %ecx,%ecx
add    $0xffffffff,%r13d
test   %cl,%cl
cmove  %r13d,%ebp
lea    0xee7(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %ebp,%r13d
jmp    117c <main+0x3c>
mov    %rbx,%rdi
call   1060 <atoi@plt>
lea    -0xb(%rax),%ecx
cmp    $0xfffffff5,%ecx
jbe    1170 <main+0x30>
lea    -0x3(%rax),%ecx
cmp    $0x4,%ecx
setb   %cl
lea    0x1(%r13),%ebp
cmp    $0xa,%eax
je     11b4 <main+0x74>
jmp    11b8 <main+0x78>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Enter the card_name: \00"
@.str.1 = [4 x i8] c"%2s\00"
@.str.2 = [50 x i8] c"Card value is out of the range, please start over\00"
@.str.3 = [20 x i8] c"Current count: %i/n\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %5
5: ; preds = %47, %29, %19, %0
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 88
br i1 %9, label %10, label %50
10: ; preds = %5
%11 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%13 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %12)
store i32 0, i32* %4
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %20 [
i32 75, label %17
i32 81, label %17
i32 74, label %17
i32 65, label %18
i32 88, label %19
]
17: ; preds = %10, %10, %10
store i32 10, i32* %4
br label %23
18: ; preds = %10
store i32 11, i32* %4
br label %23
19: ; preds = %10
br label %5
20: ; preds = %10
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %4
br label %23
23: ; preds = %20, %18, %17
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 1
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 10
br i1 %28, label %29, label %31
29: ; preds = %26, %23
%30 = call i32 @puts(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
br label %5
31: ; preds = %26
%32 = load i32, i32* %4
%33 = icmp sgt i32 %32, 2
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load i32, i32* %4
%36 = icmp slt i32 %35, 7
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %47
40: ; preds = %34, %31
%41 = load i32, i32* %4
%42 = icmp eq i32 %41, 10
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32, i32* %3
%45 = add nsw i32 %44, -1
store i32 %45, i32* %3
br label %46
46: ; preds = %43, %40
br label %47
47: ; preds = %46, %37
%48 = load i32, i32* %3
%49 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %48)
br label %5
50: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Enter the card_name: \00"
@.str.1 = [4 x i8] c"%2s\00"
@.str.2 = [50 x i8] c"Card value is out of the range, please start over\00"
@.str.3 = [20 x i8] c"Current count: %i/n\00"
define i32 @main() {
%1 = alloca [3 x i8]
%2 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %35
%4 = phi i32 [ %37, %35 ], [ 0, %0 ]
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%7 = load i8, i8* %2
%8 = sext i8 %7 to i32
switch i32 %8, label %11 [
i32 75, label %9
i32 81, label %9
i32 74, label %9
i32 65, label %15
i32 88, label %35
]
9: ; preds = %3, %3, %3
%10 = add nsw i32 %4, 1
br label %22
11: ; preds = %3
%12 = call i32 @atoi(i8* %2)
%13 = add i32 %12, -11
%14 = icmp ult i32 %13, -10
br i1 %14, label %15, label %17
15: ; preds = %3, %11
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
br label %32
17: ; preds = %11
%18 = add nsw i32 %12, -3
%19 = icmp ult i32 %18, 4
%20 = add nsw i32 %4, 1
%21 = icmp eq i32 %12, 10
br i1 %21, label %22, label %26
22: ; preds = %9, %17
%23 = phi i32 [ %10, %9 ], [ %20, %17 ]
%24 = phi i1 [ false, %9 ], [ %19, %17 ]
%25 = add nsw i32 %4, -1
br label %26
26: ; preds = %17, %22
%27 = phi i32 [ %23, %22 ], [ %20, %17 ]
%28 = phi i1 [ %24, %22 ], [ %19, %17 ]
%29 = phi i32 [ %25, %22 ], [ %4, %17 ]
%30 = select i1 %28, i32 %27, i32 %29
%31 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %15, %26
%33 = phi i32 [ %30, %26 ], [ %4, %15 ]
%34 = load i8, i8* %2
br label %35
35: ; preds = %32, %3
%36 = phi i8 [ %34, %32 ], [ %7, %3 ]
%37 = phi i32 [ %33, %32 ], [ %4, %3 ]
%38 = icmp eq i8 %36, 88
br i1 %38, label %39, label %3
39: ; preds = %35
ret i32 0
}