#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 /*<<< orphan*/ askUserX(int *, char);
scalar_t__ checkWin(char **, int, int, char *);
int /*<<< orphan*/ clearGrid(char **);
int /*<<< orphan*/ displayGrid(char **);
int placeChip(char **, int, char);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char grid[9][9], chip = 'Y';
  int userX = 0, lastY = 0;
  printf("Connect four chips and win!\n");
  printf("Y are yellow chips and R are red chips.\n");
  printf("ONLY ENTER IN NUMBERS!!!\n\n");
  clearGrid(grid);
  displayGrid(grid);
  do {
    do {
      askUserX(&userX, chip);
      lastY = placeChip(grid, userX, chip);
      displayGrid(grid);
      if (lastY == -1)
        printf("The col is full!\n");
    } while (lastY == -1);
  } while (checkWin(grid, userX, lastY, &chip));
  printf("%c wins\n", chip);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x59,-0x61(%rbp)
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
call   1080 <clearGrid@plt>
lea    -0x60(%rbp),%rdi
call   1040 <displayGrid@plt>
jmp    11c2 <main+0x62>
lea    -0x68(%rbp),%rdi
movsbl -0x61(%rbp),%esi
call   1070 <askUserX@plt>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%esi
movsbl -0x61(%rbp),%edx
call   1030 <placeChip@plt>
mov    %eax,-0x6c(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <displayGrid@plt>
cmpl   $0xffffffff,-0x6c(%rbp)
jne    1203 <main+0xa3>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1208 <main+0xa8>
cmpl   $0xffffffff,-0x6c(%rbp)
je     11c2 <main+0x62>
jmp    1217 <main+0xb7>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%esi
mov    -0x6c(%rbp),%edx
lea    -0x61(%rbp),%rcx
call   1060 <checkWin@plt>
cmp    $0x0,%rax
jne    11bd <main+0x5d>
movsbl -0x61(%rbp),%esi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
movb   $0x59,0xb(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xe79(%rip),%rdi
call   1050 <puts@plt>
lea    0xe89(%rip),%rdi
call   1050 <puts@plt>
lea    0xea5(%rip),%rdi
call   1050 <puts@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <clearGrid@plt>
mov    %rbx,%rdi
call   1040 <displayGrid@plt>
mov    $0x59,%cl
lea    0xc(%rsp),%r14
lea    0xe97(%rip),%r15
lea    0xb(%rsp),%r12
jmp    11fa <main+0x8a>
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    %ebp,%edx
mov    %r12,%rcx
call   1070 <checkWin@plt>
mov    0xb(%rsp),%cl
test   %rax,%rax
je     1237 <main+0xc7>
movsbl %cl,%esi
nopl   (%rax)
mov    %r14,%rdi
call   1080 <askUserX@plt>
mov    0xc(%rsp),%esi
movsbl 0xb(%rsp),%edx
mov    %rbx,%rdi
call   1030 <placeChip@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <displayGrid@plt>
cmp    $0xffffffff,%ebp
jne    11e0 <main+0x70>
mov    %r15,%rdi
call   1050 <puts@plt>
movsbl 0xb(%rsp),%esi
jmp    1200 <main+0x90>
movsbl %cl,%esi
lea    0xdbf(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Connect four chips and win!\0A\00"
@.str.1 = [41 x i8] c"Y are yellow chips and R are red chips.\0A\00"
@.str.2 = [27 x i8] c"ONLY ENTER IN NUMBERS!!!\0A\0A\00"
@.str.3 = [18 x i8] c"The col is full!\0A\00"
@.str.4 = [9 x i8] c"%c wins\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [9 x [9 x i8]]
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i8 89, i8* %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%9 = getelementptr inbounds [9 x [9 x i8]], [9 x [9 x i8]]* %2, i64 0, i64 0
%10 = bitcast [9 x i8]* %9 to i8**
%11 = call i32 @clearGrid(i8** %10)
%12 = getelementptr inbounds [9 x [9 x i8]], [9 x [9 x i8]]* %2, i64 0, i64 0
%13 = bitcast [9 x i8]* %12 to i8**
%14 = call i32 @displayGrid(i8** %13)
br label %15
15: ; preds = %36, %0
br label %16
16: ; preds = %32, %15
%17 = load i8, i8* %3
%18 = call i32 @askUserX(i32* %4, i8 signext %17)
%19 = getelementptr inbounds [9 x [9 x i8]], [9 x [9 x i8]]* %2, i64 0, i64 0
%20 = bitcast [9 x i8]* %19 to i8**
%21 = load i32, i32* %4
%22 = load i8, i8* %3
%23 = call i32 @placeChip(i8** %20, i32 %21, i8 signext %22)
store i32 %23, i32* %5
%24 = getelementptr inbounds [9 x [9 x i8]], [9 x [9 x i8]]* %2, i64 0, i64 0
%25 = bitcast [9 x i8]* %24 to i8**
%26 = call i32 @displayGrid(i8** %25)
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %16
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %16
br label %32
32: ; preds = %31
%33 = load i32, i32* %5
%34 = icmp eq i32 %33, -1
br i1 %34, label %16, label %35
35: ; preds = %32
br label %36
36: ; preds = %35
%37 = getelementptr inbounds [9 x [9 x i8]], [9 x [9 x i8]]* %2, i64 0, i64 0
%38 = bitcast [9 x i8]* %37 to i8**
%39 = load i32, i32* %4
%40 = load i32, i32* %5
%41 = call i64 @checkWin(i8** %38, i32 %39, i32 %40, i8* %3)
%42 = icmp ne i64 %41, 0
br i1 %42, label %15, label %43
43: ; preds = %36
%44 = load i8, i8* %3
%45 = sext i8 %44 to i32
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %45)
ret i32 0
}

LLVM IR (-O2):
@.str.4 = [9 x i8] c"%c wins\0A\00"
@str = [28 x i8] c"Connect four chips and win!\00"
@str.5 = [40 x i8] c"Y are yellow chips and R are red chips.\00"
@str.6 = [26 x i8] c"ONLY ENTER IN NUMBERS!!!\0A\00"
@str.7 = [17 x i8] c"The col is full!\00"
define i32 @main() {
%1 = alloca [9 x [9 x i8]]
%2 = alloca i8
%3 = alloca i32
%4 = getelementptr inbounds [9 x [9 x i8]], [9 x [9 x i8]]* %1, i64 0, i64 0, i64 0
store i8 89, i8* %2
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.5, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.6, i64 0, i64 0))
%9 = bitcast [9 x [9 x i8]]* %1 to i8**
%10 = call i32 @clearGrid(i8** %9)
%11 = call i32 @displayGrid(i8** %9)
br label %12
12: ; preds = %29, %0
%13 = phi i8 [ 89, %0 ], [ %34, %29 ]
%14 = call i32 @askUserX(i32* %3, i8 signext %13)
%15 = load i32, i32* %3
%16 = load i8, i8* %2
%17 = call i32 @placeChip(i8** %9, i32 %15, i8 signext %16)
%18 = call i32 @displayGrid(i8** %9)
%19 = icmp eq i32 %17, -1
br i1 %19, label %20, label %29
20: ; preds = %12, %20
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
%22 = load i8, i8* %2
%23 = call i32 @askUserX(i32* %3, i8 signext %22)
%24 = load i32, i32* %3
%25 = load i8, i8* %2
%26 = call i32 @placeChip(i8** %9, i32 %24, i8 signext %25)
%27 = call i32 @displayGrid(i8** %9)
%28 = icmp eq i32 %26, -1
br i1 %28, label %20, label %29
29: ; preds = %20, %12
%30 = phi i32 [ %17, %12 ], [ %26, %20 ]
%31 = load i32, i32* %3
%32 = call i64 @checkWin(i8** %9, i32 %31, i32 %30, i8* %2)
%33 = icmp eq i64 %32, 0
%34 = load i8, i8* %2
br i1 %33, label %35, label %12
35: ; preds = %29
%36 = sext i8 %34 to i32
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %36)
ret i32 0
}