#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 */
typedef int uint8_t;
typedef int uint32_t;

/* Variables and functions */
int bestMove(int *, char, char, int *, int);
int /*<<< orphan*/ displayBoard(int *);
int /*<<< orphan*/ dropCounter(int *, char, int);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int score(int *, char, char);
int /*<<< orphan*/ system(char *);
int main(void) {
  uint8_t lookAhead, playerInput, gameIsPlaying, board[42], best, i;
  uint32_t currentScore;
  while (1) {
    gameIsPlaying = 1;
    system("clear");
    printf("\n~~~~~~Connect 4~~~~~~\n");
    for (i = 0; i < 42; i++) {
      board[i] = '.';
    }
    printf("Please select look ahead level 1-4 recomended.");
    scanf("%c", &lookAhead);
    getchar();
    displayBoard(board);
    while (gameIsPlaying) {
      printf("Your go: ");
      scanf("%c", &playerInput);
      playerInput -= '0';
      getchar();
      dropCounter(board, 'O', playerInput);
      displayBoard(board);
      if (score(board, 'X', 'O') == -1000) {
        printf("\n****CONGRATULATIONS YOU WIN****\n");
        printf("Press return for new game");
        getchar();
        gameIsPlaying = 0;
        continue;
      } else {
        printf("My go: ");
        currentScore = bestMove(board, 'X', 'O', &best, lookAhead);
        printf("%d\n", best);
        dropCounter(board, 'X', best);
        displayBoard(board);
        printf("\n%d\n", currentScore);
        if (score(board, 'X', 'O') == 1000) {
          printf("\n****COMISERATIONS YOU LOST****\n");
          printf("Press return for new game");
          getchar();
          gameIsPlaying = 0;
          continue;
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
lea    0xe60(%rip),%rdi
call   1050 <system@plt>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0xc8(%rbp)
cmpl   $0x2a,-0xc8(%rbp)
jge    11f0 <main+0x70>
movslq -0xc8(%rbp),%rax
movl   $0x2e,-0xc0(%rbp,%rax,4)
mov    -0xc8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc8(%rbp)
jmp    11bd <main+0x3d>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe48(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   10a0 <scanf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
lea    -0xc0(%rbp),%rdi
call   1090 <displayBoard@plt>
cmpl   $0x0,-0x10(%rbp)
je     13a3 <main+0x223>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe0d(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   10a0 <scanf@plt>
mov    -0xc(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
lea    -0xc0(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0x4f,%esi
call   1040 <dropCounter@plt>
lea    -0xc0(%rbp),%rdi
call   1090 <displayBoard@plt>
lea    -0xc0(%rbp),%rdi
mov    $0x58,%esi
mov    $0x4f,%edx
call   1080 <score@plt>
cmp    $0xfffffc18,%eax
jne    12c9 <main+0x149>
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
movl   $0x0,-0x10(%rbp)
jmp    1221 <main+0xa1>
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x8(%rbp),%r8d
mov    $0x58,%esi
mov    $0x4f,%edx
lea    -0xc4(%rbp),%rcx
call   1030 <bestMove@plt>
mov    %eax,-0xcc(%rbp)
mov    -0xc4(%rbp),%esi
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xc0(%rbp),%rdi
mov    -0xc4(%rbp),%edx
mov    $0x58,%esi
call   1040 <dropCounter@plt>
lea    -0xc0(%rbp),%rdi
call   1090 <displayBoard@plt>
mov    -0xcc(%rbp),%esi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xc0(%rbp),%rdi
mov    $0x58,%esi
mov    $0x4f,%edx
call   1080 <score@plt>
cmp    $0x3e8,%eax
jne    1399 <main+0x219>
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xcfd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
movl   $0x0,-0x10(%rbp)
jmp    1221 <main+0xa1>
jmp    139e <main+0x21e>
jmp    1221 <main+0xa1>
jmp    1192 <main+0x12>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
lea    0xe9d(%rip),%rbx
lea    0x10(%rsp),%rbp
lea    0x4(%rsp),%r12
lea    0xebc(%rip),%r14
lea    0xeb4(%rip),%r13
jmp    11f1 <main+0x61>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xed9(%rip),%rdi
call   1050 <puts@plt>
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
lea    0xe18(%rip),%rdi
call   1060 <system@plt>
lea    0xe75(%rip),%rdi
call   1050 <puts@plt>
movaps 0xdf0(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0xa0(%rsp)
movabs $0x2e0000002e,%rax
mov    %rax,0xb0(%rsp)
lea    0xdb2(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
call   10b0 <scanf@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %rbp,%rdi
call   10a0 <displayBoard@plt>
nopw   0x0(%rax,%rax,1)
lea    0xdb1(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
call   10b0 <scanf@plt>
addl   $0xffffffd0,0x8(%rsp)
xor    %eax,%eax
call   1080 <getchar@plt>
mov    0x8(%rsp),%edx
mov    %rbp,%rdi
mov    $0x4f,%esi
call   1040 <dropCounter@plt>
mov    %rbp,%rdi
call   10a0 <displayBoard@plt>
mov    %rbp,%rdi
mov    $0x58,%esi
mov    $0x4f,%edx
call   1090 <score@plt>
cmp    $0xfffffc18,%eax
je     11d0 <main+0x40>
lea    0xd78(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0xc(%rsp),%r8d
mov    %rbp,%rdi
mov    $0x58,%esi
mov    $0x4f,%edx
mov    %r12,%rcx
call   1030 <bestMove@plt>
mov    %eax,%r15d
mov    0x4(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x4(%rsp),%edx
mov    %rbp,%rdi
mov    $0x58,%esi
call   1040 <dropCounter@plt>
mov    %rbp,%rdi
call   10a0 <displayBoard@plt>
mov    %r13,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
mov    $0x58,%esi
mov    $0x4f,%edx
call   1090 <score@plt>
cmp    $0x3e8,%eax
jne    1290 <main+0x100>
lea    0xd20(%rip),%rdi
jmp    11d7 <main+0x47>

LLVM IR (-O0):
@.str = [6 x i8] c"clear\00"
@.str.1 = [24 x i8] c"\0A~~~~~~Connect 4~~~~~~\0A\00"
@.str.2 = [47 x i8] c"Please select look ahead level 1-4 recomended.\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [10 x i8] c"Your go: \00"
@.str.5 = [34 x i8] c"\0A****CONGRATULATIONS YOU WIN****\0A\00"
@.str.6 = [26 x i8] c"Press return for new game\00"
@.str.7 = [8 x i8] c"My go: \00"
@.str.8 = [4 x i8] c"%d\0A\00"
@.str.9 = [5 x i8] c"\0A%d\0A\00"
@.str.10 = [33 x i8] c"\0A****COMISERATIONS YOU LOST****\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [42 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
br label %9
9: ; preds = %0, %72
store i32 1, i32* %4
%10 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %7
br label %12
12: ; preds = %19, %9
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 42
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [42 x i32], [42 x i32]* %5, i64 0, i64 %17
store i32 46, i32* %18
br label %19
19: ; preds = %15
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
store i32 %21, i32* %7
br label %12
22: ; preds = %12
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%25 = call i32 (...) @getchar()
%26 = getelementptr inbounds [42 x i32], [42 x i32]* %5, i64 0, i64 0
%27 = call i32 @displayBoard(i32* %26)
br label %28
28: ; preds = %71, %66, %45, %22
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %72
31: ; preds = %28
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%34 = load i32, i32* %3
%35 = sub nsw i32 %34, 48
store i32 %35, i32* %3
%36 = call i32 (...) @getchar()
%37 = getelementptr inbounds [42 x i32], [42 x i32]* %5, i64 0, i64 0
%38 = load i32, i32* %3
%39 = call i32 @dropCounter(i32* %37, i8 signext 79, i32 %38)
%40 = getelementptr inbounds [42 x i32], [42 x i32]* %5, i64 0, i64 0
%41 = call i32 @displayBoard(i32* %40)
%42 = getelementptr inbounds [42 x i32], [42 x i32]* %5, i64 0, i64 0
%43 = call i32 @score(i32* %42, i8 signext 88, i8 signext 79)
%44 = icmp eq i32 %43, -1000
br i1 %44, label %45, label %49
45: ; preds = %31
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%48 = call i32 (...) @getchar()
store i32 0, i32* %4
br label %28
49: ; preds = %31
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%51 = getelementptr inbounds [42 x i32], [42 x i32]* %5, i64 0, i64 0
%52 = load i32, i32* %2
%53 = call i32 @bestMove(i32* %51, i8 signext 88, i8 signext 79, i32* %6, i32 %52)
store i32 %53, i32* %8
%54 = load i32, i32* %6
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %54)
%56 = getelementptr inbounds [42 x i32], [42 x i32]* %5, i64 0, i64 0
%57 = load i32, i32* %6
%58 = call i32 @dropCounter(i32* %56, i8 signext 88, i32 %57)
%59 = getelementptr inbounds [42 x i32], [42 x i32]* %5, i64 0, i64 0
%60 = call i32 @displayBoard(i32* %59)
%61 = load i32, i32* %8
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %61)
%63 = getelementptr inbounds [42 x i32], [42 x i32]* %5, i64 0, i64 0
%64 = call i32 @score(i32* %63, i8 signext 88, i8 signext 79)
%65 = icmp eq i32 %64, 1000
br i1 %65, label %66, label %70
66: ; preds = %49
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%69 = call i32 (...) @getchar()
store i32 0, i32* %4
br label %28
70: ; preds = %49
br label %71
71: ; preds = %70
br label %28
72: ; preds = %28
br label %9
}

LLVM IR (-O2):
@.str = [6 x i8] c"clear\00"
@.str.2 = [47 x i8] c"Please select look ahead level 1-4 recomended.\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [10 x i8] c"Your go: \00"
@.str.6 = [26 x i8] c"Press return for new game\00"
@.str.7 = [8 x i8] c"My go: \00"
@.str.8 = [4 x i8] c"%d\0A\00"
@.str.9 = [5 x i8] c"\0A%d\0A\00"
@str = [23 x i8] c"\0A~~~~~~Connect 4~~~~~~\00"
@str.11 = [32 x i8] c"\0A****COMISERATIONS YOU LOST****\00"
@str.12 = [33 x i8] c"\0A****CONGRATULATIONS YOU WIN****\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [42 x i32]
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast [42 x i32]* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = getelementptr inbounds [42 x i32], [42 x i32]* %3, i64 0, i64 0
%10 = getelementptr inbounds [42 x i32], [42 x i32]* %3, i64 0, i64 4
%11 = getelementptr inbounds [42 x i32], [42 x i32]* %3, i64 0, i64 8
%12 = getelementptr inbounds [42 x i32], [42 x i32]* %3, i64 0, i64 12
%13 = getelementptr inbounds [42 x i32], [42 x i32]* %3, i64 0, i64 16
%14 = getelementptr inbounds [42 x i32], [42 x i32]* %3, i64 0, i64 20
%15 = getelementptr inbounds [42 x i32], [42 x i32]* %3, i64 0, i64 24
%16 = getelementptr inbounds [42 x i32], [42 x i32]* %3, i64 0, i64 28
%17 = getelementptr inbounds [42 x i32], [42 x i32]* %3, i64 0, i64 32
%18 = getelementptr inbounds [42 x i32], [42 x i32]* %3, i64 0, i64 36
%19 = getelementptr inbounds [42 x i32], [42 x i32]* %3, i64 0, i64 40
%20 = getelementptr inbounds [42 x i32], [42 x i32]* %3, i64 0, i64 41
%21 = bitcast [42 x i32]* %3 to <4 x i32>*
%22 = bitcast i32* %10 to <4 x i32>*
%23 = bitcast i32* %11 to <4 x i32>*
%24 = bitcast i32* %12 to <4 x i32>*
%25 = bitcast i32* %13 to <4 x i32>*
%26 = bitcast i32* %14 to <4 x i32>*
%27 = bitcast i32* %15 to <4 x i32>*
%28 = bitcast i32* %16 to <4 x i32>*
%29 = bitcast i32* %17 to <4 x i32>*
%30 = bitcast i32* %18 to <4 x i32>*
br label %31
31: ; preds = %61, %0
%32 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
store <4 x i32> <i32 46, i32 46, i32 46, i32 46>, <4 x i32>* %21
store <4 x i32> <i32 46, i32 46, i32 46, i32 46>, <4 x i32>* %22
store <4 x i32> <i32 46, i32 46, i32 46, i32 46>, <4 x i32>* %23
store <4 x i32> <i32 46, i32 46, i32 46, i32 46>, <4 x i32>* %24
store <4 x i32> <i32 46, i32 46, i32 46, i32 46>, <4 x i32>* %25
store <4 x i32> <i32 46, i32 46, i32 46, i32 46>, <4 x i32>* %26
store <4 x i32> <i32 46, i32 46, i32 46, i32 46>, <4 x i32>* %27
store <4 x i32> <i32 46, i32 46, i32 46, i32 46>, <4 x i32>* %28
store <4 x i32> <i32 46, i32 46, i32 46, i32 46>, <4 x i32>* %29
store <4 x i32> <i32 46, i32 46, i32 46, i32 46>, <4 x i32>* %30
store i32 46, i32* %19
store i32 46, i32* %20
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%36 = call i32 (...) @getchar()
%37 = call i32 @displayBoard(i32* %9)
br label %38
38: ; preds = %49, %31
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%41 = load i32, i32* %2
%42 = add nsw i32 %41, -48
store i32 %42, i32* %2
%43 = call i32 (...) @getchar()
%44 = load i32, i32* %2
%45 = call i32 @dropCounter(i32* %9, i8 signext 79, i32 %44)
%46 = call i32 @displayBoard(i32* %9)
%47 = call i32 @score(i32* %9, i8 signext 88, i8 signext 79)
%48 = icmp eq i32 %47, -1000
br i1 %48, label %61, label %49
49: ; preds = %38
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%51 = load i32, i32* %1
%52 = call i32 @bestMove(i32* %9, i8 signext 88, i8 signext 79, i32* %4, i32 %51)
%53 = load i32, i32* %4
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %53)
%55 = load i32, i32* %4
%56 = call i32 @dropCounter(i32* %9, i8 signext 88, i32 %55)
%57 = call i32 @displayBoard(i32* %9)
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %52)
%59 = call i32 @score(i32* %9, i8 signext 88, i8 signext 79)
%60 = icmp eq i32 %59, 1000
br i1 %60, label %61, label %38
61: ; preds = %49, %38
%62 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @str.12, i64 0, i64 0), %38 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @str.11, i64 0, i64 0), %49 ]
%63 = call i32 @puts(i8* dereferenceable(1) %62)
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%65 = call i32 (...) @getchar()
br label %31
}