#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*/ scanf(char *, char *);
int main(void) {
  char card_name[3];
  int val = 0;
  int count = 0;
  do {
    printf("Enter card name:\nEnter 'X' to exit!\n>>");
    scanf("%2s", card_name);
    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("Erroneous value, try again\n>>");
        continue;
      }
    }
    if (val >= 3 && val <= 6) {
      ++count;
      printf("Count has gone up\n");
    } else if (val == 10) {
      --count;
      printf("Count has gone down\n");
    }
    printf("Value of count = [%d]\n", count);
  } while (card_name[0] != 'X');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xf0c(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf25(%rip),%rdi
lea    -0x7(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0x7(%rbp),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x17,%eax
ja     11b2 <main+0x82>
mov    -0x18(%rbp),%rax
lea    0xe74(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xa,-0xc(%rbp)
jmp    11ea <main+0xba>
movl   $0xb,-0xc(%rbp)
jmp    11ea <main+0xba>
jmp    1251 <main+0x121>
lea    -0x7(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jl     11d2 <main+0xa2>
cmpl   $0xa,-0xc(%rbp)
jle    11e5 <main+0xb5>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1251 <main+0x121>
jmp    11ea <main+0xba>
cmpl   $0x3,-0xc(%rbp)
jl     121a <main+0xea>
cmpl   $0x6,-0xc(%rbp)
jg     121a <main+0xea>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1240 <main+0x110>
cmpl   $0xa,-0xc(%rbp)
jne    123b <main+0x10b>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1240 <main+0x110>
mov    -0x10(%rbp),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x7(%rbp),%eax
cmp    $0x58,%eax
jne    114d <main+0x1d>
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
lea    0xf0e(%rip),%r14
lea    0xf2e(%rip),%r15
lea    0x5(%rsp),%rbx
lea    0xf5b(%rip),%r12
lea    0xe94(%rip),%r13
xor    %ebp,%ebp
jmp    1194 <main+0x54>
add    %ecx,%ebp
call   1030 <puts@plt>
lea    0xf2b(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x5(%rsp),%eax
cmp    $0x58,%al
je     1216 <main+0xd6>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
movsbl 0x5(%rsp),%eax
lea    -0x41(%rax),%ecx
cmp    $0x17,%ecx
ja     11c8 <main+0x88>
movslq 0x0(%r13,%rcx,4),%rdx
add    %r13,%rdx
mov    $0xffffffff,%ecx
mov    %r12,%rdi
jmp    *%rdx
mov    %rbx,%rdi
call   1060 <atoi@plt>
lea    -0xb(%rax),%ecx
cmp    $0xfffffff5,%ecx
ja     11e8 <main+0xa8>
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1187 <main+0x47>
lea    -0x3(%rax),%edx
mov    $0x1,%ecx
lea    0xedd(%rip),%rdi
cmp    $0x4,%edx
jb     1170 <main+0x30>
mov    $0xffffffff,%ecx
mov    %r12,%rdi
cmp    $0xa,%eax
je     1170 <main+0x30>
jmp    1177 <main+0x37>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Enter card name:\0AEnter 'X' to exit!\0A>>\00"
@.str.1 = [4 x i8] c"%2s\00"
@.str.2 = [30 x i8] c"Erroneous value, try again\0A>>\00"
@.str.3 = [19 x i8] c"Count has gone up\0A\00"
@.str.4 = [21 x i8] c"Count has gone down\0A\00"
@.str.5 = [23 x i8] c"Value of count = [%d]\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
store i32 0, i32* %4
br label %5
5: ; preds = %47, %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
switch i32 %11, label %15 [
i32 75, label %12
i32 81, label %12
i32 74, label %12
i32 65, label %13
i32 88, label %14
]
12: ; preds = %5, %5, %5
store i32 10, i32* %3
br label %26
13: ; preds = %5
store i32 11, i32* %3
br label %26
14: ; preds = %5
br label %47
15: ; preds = %5
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 1
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = load i32, i32* %3
%22 = icmp sgt i32 %21, 10
br i1 %22, label %23, label %25
23: ; preds = %20, %15
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %47
25: ; preds = %20
br label %26
26: ; preds = %25, %13, %12
%27 = load i32, i32* %3
%28 = icmp sge i32 %27, 3
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i32, i32* %3
%31 = icmp sle i32 %30, 6
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %44
36: ; preds = %29, %26
%37 = load i32, i32* %3
%38 = icmp eq i32 %37, 10
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i32, i32* %4
%41 = add nsw i32 %40, -1
store i32 %41, i32* %4
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %43
43: ; preds = %39, %36
br label %44
44: ; preds = %43, %32
%45 = load i32, i32* %4
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %44, %23, %14
%48 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 88
br i1 %51, label %5, label %52
52: ; preds = %47
ret i32 0
}

LLVM IR (-O2):
@.str = [39 x i8] c"Enter card name:\0AEnter 'X' to exit!\0A>>\00"
@.str.1 = [4 x i8] c"%2s\00"
@.str.2 = [30 x i8] c"Erroneous value, try again\0A>>\00"
@.str.5 = [23 x i8] c"Value of count = [%d]\0A\00"
@str = [20 x i8] c"Count has gone down\00"
@str.6 = [18 x i8] c"Count has gone up\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 = %31, %0
%4 = phi i32 [ 0, %0 ], [ %33, %31 ]
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 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 %20
i32 81, label %20
i32 74, label %20
i32 65, label %25
i32 88, label %31
]
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 %15
13: ; preds = %9
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %28
15: ; preds = %9
%16 = add nsw i32 %10, -3
%17 = icmp ult i32 %16, 4
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = icmp eq i32 %10, 10
br i1 %19, label %20, label %25
20: ; preds = %18, %3, %3, %3, %15
%21 = phi i32 [ 1, %15 ], [ -1, %3 ], [ -1, %3 ], [ -1, %3 ], [ -1, %18 ]
%22 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0), %15 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0), %18 ]
%23 = add nsw i32 %4, %21
%24 = call i32 @puts(i8* dereferenceable(1) %22)
br label %25
25: ; preds = %20, %3, %18
%26 = phi i32 [ %4, %18 ], [ %4, %3 ], [ %23, %20 ]
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %13, %25
%29 = phi i32 [ %26, %25 ], [ %4, %13 ]
%30 = load i8, i8* %2
br label %31
31: ; preds = %28, %3
%32 = phi i8 [ %30, %28 ], [ %7, %3 ]
%33 = phi i32 [ %29, %28 ], [ %4, %3 ]
%34 = icmp eq i8 %32, 88
br i1 %34, label %35, label %3
35: ; preds = %31
ret i32 0
}