#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 EXIT_SUCCESS;
int checkMove(char *);
int /*<<< orphan*/ getchar();
int menu();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  int option;
  int turn = 0;
  int playing = 1;
  int error = 0;
  int check;
  char position[4];
  option = menu();
  if (option == 1) {
    printf("Choose the position: <number><letter>\n\n");
    for (turn = 0; playing; turn++) {
      if (turn % 2 == 0) {
        printf("Player 1: ");
        scanf("%s", position);
        getchar();
        do {
          check = checkMove(position);
          if (check == 1) {
            printf("\nThanks for playing!\n\n");
            return EXIT_SUCCESS;
          } else if (!check) {
            error = 0;
          } else {
            printf("Invalid position, try again.\n\n");
            error = 1;
          }
        } while (error);
      } else {
        printf("Player 2: ");
        scanf("%s", position);
        getchar();
      }
    }
  }
  printf("Thanks for playing!\n\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1030 <menu@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    128c <main+0x13c>
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1287 <main+0x137>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1251 <main+0x101>
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
lea    -0x1c(%rbp),%rsi
lea    0xe63(%rip),%rdi
call   1060 <scanf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
lea    -0x1c(%rbp),%rdi
call   1070 <checkMove@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    120f <main+0xbf>
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12a4 <main+0x154>
cmpl   $0x0,-0x18(%rbp)
jne    1225 <main+0xd5>
movl   $0x0,-0x14(%rbp)
jmp    1238 <main+0xe8>
lea    0xe21(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    123d <main+0xed>
jmp    1242 <main+0xf2>
cmpl   $0x0,-0x14(%rbp)
jne    11dc <main+0x8c>
jmp    1274 <main+0x124>
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
lea    -0x1c(%rbp),%rsi
lea    0xdcb(%rip),%rdi
call   1060 <scanf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
jmp    1279 <main+0x129>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119b <main+0x4b>
jmp    128c <main+0x13c>
lea    0xda4(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%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    %eax,%eax
call   1040 <menu@plt>
cmp    $0x1,%eax
jne    1215 <main+0xb5>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
lea    0xe72(%rip),%r14
lea    0xe76(%rip),%r15
lea    0x4(%rsp),%rbx
lea    0xe9f(%rip),%r12
lea    0xe66(%rip),%r13
xor    %ebp,%ebp
test   $0x1,%bpl
jne    11f0 <main+0x90>
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <checkMove@plt>
test   %eax,%eax
je     120a <main+0xaa>
cmp    $0x1,%eax
je     121e <main+0xbe>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    11d0 <main+0x70>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
add    $0x1,%ebp
test   $0x1,%bpl
jne    11f0 <main+0x90>
jmp    11b0 <main+0x50>
lea    0xe43(%rip),%rdi
jmp    1225 <main+0xc5>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Choose the position: <number><letter>\0A\0A\00"
@.str.1 = [11 x i8] c"Player 1: \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [23 x i8] c"\0AThanks for playing!\0A\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.4 = [31 x i8] c"Invalid position, try again.\0A\0A\00"
@.str.5 = [11 x i8] c"Player 2: \00"
@.str.6 = [22 x i8] c"Thanks for playing!\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [4 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
store i32 1, i32* %4
store i32 0, i32* %5
%8 = call i32 (...) @menu()
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %55
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %13
13: ; preds = %51, %11
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %54
16: ; preds = %13
%17 = load i32, i32* %3
%18 = srem i32 %17, 2
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %45
20: ; preds = %16
%21 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = call i32 (...) @getchar()
br label %25
25: ; preds = %41, %20
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%27 = call i32 @checkMove(i8* %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%32 = load i32, i32* @EXIT_SUCCESS
store i32 %32, i32* %1
br label %58
33: ; preds = %25
%34 = load i32, i32* %6
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %33
store i32 0, i32* %5
br label %39
37: ; preds = %33
%38 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %5
br label %39
39: ; preds = %37, %36
br label %40
40: ; preds = %39
br label %41
41: ; preds = %40
%42 = load i32, i32* %5
%43 = icmp ne i32 %42, 0
br i1 %43, label %25, label %44
44: ; preds = %41
br label %50
45: ; preds = %16
%46 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%47 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%48 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = call i32 (...) @getchar()
br label %50
50: ; preds = %45, %44
br label %51
51: ; preds = %50
%52 = load i32, i32* %3
%53 = add nsw i32 %52, 1
store i32 %53, i32* %3
br label %13
54: ; preds = %13
br label %55
55: ; preds = %54, %0
%56 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%57 = load i32, i32* @EXIT_SUCCESS
store i32 %57, i32* %1
br label %58
58: ; preds = %55, %30
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"Player 1: \00"
@.str.2 = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
@.str.5 = [11 x i8] c"Player 2: \00"
@str = [21 x i8] c"Thanks for playing!\0A\00"
@str.7 = [39 x i8] c"Choose the position: <number><letter>\0A\00"
@str.8 = [30 x i8] c"Invalid position, try again.\0A\00"
@str.9 = [22 x i8] c"\0AThanks for playing!\0A\00"
define i32 @main() {
%1 = alloca [4 x i8]
%2 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @menu()
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %27
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.7, i64 0, i64 0))
br label %7
7: ; preds = %25, %5
%8 = phi i32 [ 0, %5 ], [ %26, %25 ]
%9 = and i32 %8, 1
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %7
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%14 = call i32 (...) @getchar()
br label %15
15: ; preds = %19, %11
%16 = call i32 @checkMove(i8* %2)
switch i32 %16, label %19 [
i32 1, label %17
i32 0, label %25
]
17: ; preds = %15
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0))
br label %29
19: ; preds = %15
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.8, i64 0, i64 0))
br label %15
21: ; preds = %7
%22 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%24 = call i32 (...) @getchar()
br label %25
25: ; preds = %15, %21
%26 = add nuw nsw i32 %8, 1
br label %7
27: ; preds = %0
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %29
29: ; preds = %27, %17
%30 = load i32, i32* @EXIT_SUCCESS
ret i32 %30
}