#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 /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  const char EXIT_FLAG = 'X';
  char card_name[3];
  int count = 0;
  do {
    puts("Enter the card name: ");
    scanf("%2s", card_name);
    if (card_name[0] == EXIT_FLAG)
      return 0;
    int val = 0;
    if (card_name[0] == 'A')
      val = 11;
    else if (card_name[0] == 'K' || card_name[0] == 'Q' || card_name[0] == 'J')
      val = 10;
    else {
      val = atoi(card_name);
      if (val > 10 || val < 2) {
        printf("Invalid card value.\n");
        continue;
      }
    }
    if (val >= 3 && val <= 6)
      count++;
    else if (val == 10)
      count--;
    printf("Current count: %i\n", count);
  } while (card_name[0] != EXIT_FLAG);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x58,-0x5(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
lea    -0x8(%rbp),%rsi
lea    0xea5(%rip),%rdi
call   1050 <scanf@plt>
movsbl -0x8(%rbp),%eax
cmp    $0x58,%eax
jne    118f <main+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    127e <main+0x13e>
movl   $0x0,-0x10(%rbp)
movsbl -0x8(%rbp),%eax
cmp    $0x41,%eax
jne    11af <main+0x6f>
movl   $0xb,-0x10(%rbp)
jmp    121f <main+0xdf>
movsbl -0x8(%rbp),%eax
cmp    $0x4b,%eax
je     11d6 <main+0x96>
movsbl -0x8(%rbp),%eax
cmp    $0x51,%eax
je     11d6 <main+0x96>
movsbl -0x8(%rbp),%eax
cmp    $0x4a,%eax
jne    11e2 <main+0xa2>
movl   $0xa,-0x10(%rbp)
jmp    121a <main+0xda>
lea    -0x8(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jg     1202 <main+0xc2>
cmpl   $0x2,-0x10(%rbp)
jge    1215 <main+0xd5>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126a <main+0x12a>
jmp    121a <main+0xda>
jmp    121f <main+0xdf>
cmpl   $0x3,-0x10(%rbp)
jl     1241 <main+0x101>
cmpl   $0x6,-0x10(%rbp)
jg     1241 <main+0x101>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1259 <main+0x119>
cmpl   $0xa,-0x10(%rbp)
jne    1254 <main+0x114>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1259 <main+0x119>
mov    -0xc(%rbp),%esi
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x8(%rbp),%eax
cmp    $0x58,%eax
jne    115a <main+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xf0e(%rip),%r14
lea    0xf1d(%rip),%r15
lea    0x5(%rsp),%rbx
lea    0xf15(%rip),%r13
lea    0xe94(%rip),%r12
xor    %ebp,%ebp
jmp    11a3 <main+0x63>
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,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmpb   $0x58,0x5(%rsp)
je     1203 <main+0xc3>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
movzbl 0x5(%rsp),%eax
add    $0xbf,%al
cmp    $0x17,%al
ja     11e0 <main+0xa0>
movzbl %al,%eax
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
add    $0xffffffff,%ebp
jmp    1190 <main+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <atoi@plt>
lea    -0xb(%rax),%ecx
cmp    $0xfffffff6,%ecx
ja     1170 <main+0x30>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
cmpb   $0x58,0x5(%rsp)
jne    11a3 <main+0x63>
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 = [21 x i8] c"Invalid card value.\0A\00"
@.str.3 = [19 x i8] c"Current count: %i\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [3 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i8 88, i8* %2
store i32 0, i32* %4
br label %6
6: ; preds = %68, %0
%7 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 88
br i1 %13, label %14, label %15
14: ; preds = %6
store i32 0, i32* %1
br label %74
15: ; preds = %6
store i32 0, i32* %5
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 65
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 11, i32* %5
br label %49
21: ; preds = %15
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 75
br i1 %25, label %36, label %26
26: ; preds = %21
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 81
br i1 %30, label %36, label %31
31: ; preds = %26
%32 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 74
br i1 %35, label %36, label %37
36: ; preds = %31, %26, %21
store i32 10, i32* %5
br label %48
37: ; preds = %31
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %5
%40 = load i32, i32* %5
%41 = icmp sgt i32 %40, 10
br i1 %41, label %45, label %42
42: ; preds = %37
%43 = load i32, i32* %5
%44 = icmp slt i32 %43, 2
br i1 %44, label %45, label %47
45: ; preds = %42, %37
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %68
47: ; preds = %42
br label %48
48: ; preds = %47, %36
br label %49
49: ; preds = %48, %20
%50 = load i32, i32* %5
%51 = icmp sge i32 %50, 3
br i1 %51, label %52, label %58
52: ; preds = %49
%53 = load i32, i32* %5
%54 = icmp sle i32 %53, 6
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32, i32* %4
%57 = add nsw i32 %56, 1
store i32 %57, i32* %4
br label %65
58: ; preds = %52, %49
%59 = load i32, i32* %5
%60 = icmp eq i32 %59, 10
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i32, i32* %4
%63 = add nsw i32 %62, -1
store i32 %63, i32* %4
br label %64
64: ; preds = %61, %58
br label %65
65: ; preds = %64, %55
%66 = load i32, i32* %4
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %65, %45
%69 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp ne i32 %71, 88
br i1 %72, label %6, label %73
73: ; preds = %68
store i32 0, i32* %1
br label %74
74: ; preds = %73, %14
%75 = load i32, i32* %1
ret i32 %75
}

LLVM IR (-O2):
@.str = [22 x i8] c"Enter the card name: \00"
@.str.1 = [4 x i8] c"%2s\00"
@.str.3 = [19 x i8] c"Current count: %i\0A\00"
@str = [20 x i8] c"Invalid card value.\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 = %26, %0
%4 = phi i32 [ 0, %0 ], [ %27, %26 ]
%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
switch i8 %7, label %8 [
i8 88, label %30
i8 65, label %23
i8 81, label %14
i8 75, label %14
i8 74, label %14
]
8: ; preds = %3
%9 = call i32 @atoi(i8* %2)
%10 = add i32 %9, -11
%11 = icmp ult i32 %10, -9
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %26
14: ; preds = %3, %3, %3
%15 = add nsw i32 %4, -1
br label %23
16: ; preds = %8
%17 = add nsw i32 %9, -3
%18 = icmp ult i32 %17, 4
%19 = icmp eq i32 %9, 10
%20 = sext i1 %19 to i32
%21 = select i1 %18, i32 1, i32 %20
%22 = add nsw i32 %21, %4
br label %23
23: ; preds = %16, %14, %3
%24 = phi i32 [ %4, %3 ], [ %15, %14 ], [ %22, %16 ]
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %23, %12
%27 = phi i32 [ %24, %23 ], [ %4, %12 ]
%28 = load i8, i8* %2
%29 = icmp eq i8 %28, 88
br i1 %29, label %30, label %3
30: ; preds = %3, %26
ret i32 0
}