#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)) {
        printf("%d is not a valid card.\n", val);
        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     1254 <main+0x114>
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    1206 <main+0xc6>
movl   $0xb,-0x10(%rbp)
jmp    1206 <main+0xc6>
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    1201 <main+0xc1>
mov    -0x10(%rbp),%esi
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
jmp    1156 <main+0x16>
jmp    1206 <main+0xc6>
cmpl   $0x2,-0x10(%rbp)
jle    1228 <main+0xe8>
cmpl   $0x7,-0x10(%rbp)
jge    1228 <main+0xe8>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1240 <main+0x100>
cmpl   $0xa,-0x10(%rbp)
jne    123b <main+0xfb>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1240 <main+0x100>
mov    -0xc(%rbp),%esi
lea    0xe49(%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    %ebx,%ebx
lea    0xf0c(%rip),%r14
lea    0xf1b(%rip),%r15
lea    0x5(%rsp),%r12
lea    0xf2c(%rip),%rbp
lea    0xe92(%rip),%r13
jmp    1186 <main+0x46>
add    $0xffffffff,%ebx
mov    %rbp,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
movzbl 0x5(%rsp),%eax
cmp    $0x58,%al
je     11e7 <main+0xa7>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
movsbl 0x5(%rsp),%eax
lea    -0x41(%rax),%ecx
cmp    $0x17,%ecx
ja     11b0 <main+0x70>
movslq 0x0(%r13,%rcx,4),%rcx
add    %r13,%rcx
jmp    *%rcx
mov    %r12,%rdi
call   1060 <atoi@plt>
lea    -0xb(%rax),%ecx
cmp    $0xfffffff5,%ecx
ja     11cb <main+0x8b>
lea    0xeb3(%rip),%rdi
mov    %eax,%esi
jmp    1178 <main+0x38>
lea    -0x3(%rax),%ecx
xor    %edx,%edx
cmp    $0xa,%eax
sete   %dl
neg    %edx
cmp    $0x4,%ecx
mov    $0x1,%eax
cmovb  %eax,%edx
add    %edx,%ebx
jmp    1173 <main+0x33>
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 = [25 x i8] c"%d is not a valid card.\0A\00"
@.str.3 = [19 x i8] c"Current count: %i\0A\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 = %48, %28, %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 %51
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 %32
18: ; preds = %10
store i32 11, i32* %4
br label %32
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
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 1
br i1 %24, label %28, label %25
25: ; preds = %20
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 10
br i1 %27, label %28, label %31
28: ; preds = %25, %20
%29 = load i32, i32* %4
%30 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %5
31: ; preds = %25
br label %32
32: ; preds = %31, %18, %17
%33 = load i32, i32* %4
%34 = icmp sgt i32 %33, 2
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = load i32, i32* %4
%37 = icmp slt i32 %36, 7
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %48
41: ; preds = %35, %32
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 10
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i32, i32* %3
%46 = add nsw i32 %45, -1
store i32 %46, i32* %3
br label %47
47: ; preds = %44, %41
br label %48
48: ; preds = %47, %38
%49 = load i32, i32* %3
%50 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %49)
br label %5
51: ; 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 = [25 x i8] c"%d is not a valid card.\0A\00"
@.str.3 = [19 x i8] c"Current count: %i\0A\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, %30
%4 = phi i32 [ %32, %30 ], [ 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 %9 [
i32 75, label %15
i32 81, label %15
i32 74, label %15
i32 65, label %24
i32 88, label %30
]
9: ; preds = %3
%10 = call i32 @atoi(i8* %2)
%11 = add i32 %10, -11
%12 = icmp ult i32 %11, -10
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %27
15: ; preds = %3, %3, %3
%16 = add nsw i32 %4, -1
br label %24
17: ; preds = %9
%18 = add nsw i32 %10, -3
%19 = icmp ult i32 %18, 4
%20 = icmp eq i32 %10, 10
%21 = sext i1 %20 to i32
%22 = select i1 %19, i32 1, i32 %21
%23 = add nsw i32 %22, %4
br label %24
24: ; preds = %17, %15, %3
%25 = phi i32 [ %4, %3 ], [ %16, %15 ], [ %23, %17 ]
%26 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %13, %24
%28 = phi i32 [ %25, %24 ], [ %4, %13 ]
%29 = load i8, i8* %2
br label %30
30: ; preds = %27, %3
%31 = phi i8 [ %29, %27 ], [ %7, %3 ]
%32 = phi i32 [ %28, %27 ], [ %4, %3 ]
%33 = icmp eq i8 %31, 88
br i1 %33, label %34, label %3
34: ; preds = %30
ret i32 0
}