#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 partida(int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
void main() {
  int scoreJ1 = 0, scoreJ2 = 0;
  int resultat;
  char resposta;
  int maxNivellsArbre;
  printf("\n \t\tBenvingut al 4 en ratlla \n\n");
  printf(
      "\tIntrodueix el numero de nivells de profunditat \n\tque usa l'arbre de "
      "possibles moviments del BOT \n\t(es recomanable que sigui un numero "
      "entre 1 i 4\n\tper tal de tenir un temps d'execucio raonable)\n");
  scanf(" %d", &maxNivellsArbre);
  printf("\n \t\tPer a moure cal introduir \n \t\t el numero de la columna \n "
         "\t\t    on vulguis tirar \n");
  while (1) {
    resultat = partida(maxNivellsArbre, scoreJ2, scoreJ1);
    if (resultat == 1)
      scoreJ1++;
    else if (resultat == -1)
      scoreJ2++;
    printf("\n\t\tVols tornar a jugar? (s/n)\n");
    scanf(" %c", &resposta);
    if (resposta == 'n')
      break;
  }
  printf("\n \t\t  FINAL GAME SCORE:\n \t\t BOT = %d JUGADOR = %d \n", scoreJ2,
         scoreJ1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf7b(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xf6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1030 <partida@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    11ab <main+0x7b>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11c3 <main+0x93>
cmpl   $0xffffffff,-0xc(%rbp)
jne    11be <main+0x8e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c3 <main+0x93>
lea    0xf74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf85(%rip),%rdi
lea    -0xd(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movsbl -0xd(%rbp),%eax
cmp    $0x6e,%eax
jne    11f5 <main+0xc5>
jmp    11fa <main+0xca>
jmp    1182 <main+0x52>
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xf5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
lea    0xefc(%rip),%rdi
call   1030 <puts@plt>
lea    0xe95(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xfa0(%rip),%rdi
call   1030 <puts@plt>
lea    0xfe9(%rip),%r14
lea    0xe73(%rip),%r15
lea    0xb(%rsp),%r12
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    11bf <main+0x7f>
nopl   0x0(%rax)
add    $0x1,%ebx
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpb   $0x6e,0xb(%rsp)
je     11db <main+0x9b>
mov    0xc(%rsp),%edi
mov    %ebx,%esi
mov    %ebp,%edx
call   1040 <partida@plt>
cmp    $0xffffffff,%eax
je     11a0 <main+0x60>
cmp    $0x1,%eax
jne    11a3 <main+0x63>
add    $0x1,%ebp
jmp    11a3 <main+0x63>
lea    0xe26(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"\0A \09\09Benvingut al 4 en ratlla \0A\0A\00"
@.str.1 = [196 x i8] c"\09Introdueix el numero de nivells de profunditat \0A\09que usa l'arbre de possibles moviments del BOT \0A\09(es recomanable que sigui un numero entre 1 i 4\0A\09per tal de tenir un temps d'execucio raonable)\0A\00"
@.str.2 = [4 x i8] c" %d\00"
@.str.3 = [86 x i8] c"\0A \09\09Per a moure cal introduir \0A \09\09 el numero de la columna \0A \09\09 on vulguis tirar \0A\00"
@.str.4 = [31 x i8] c"\0A\09\09Vols tornar a jugar? (s/n)\0A\00"
@.str.5 = [4 x i8] c" %c\00"
@.str.6 = [52 x i8] c"\0A \09\09 FINAL GAME SCORE:\0A \09\09 BOT = %d JUGADOR = %d \0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([196 x i8], [196 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.3, i64 0, i64 0))
br label %10
10: ; preds = %0, %34
%11 = load i32, i32* %5
%12 = load i32, i32* %2
%13 = load i32, i32* %1
%14 = call i32 @partida(i32 %11, i32 %12, i32 %13)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load i32, i32* %1
%19 = add nsw i32 %18, 1
store i32 %19, i32* %1
br label %27
20: ; preds = %10
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 1
store i32 %25, i32* %2
br label %26
26: ; preds = %23, %20
br label %27
27: ; preds = %26, %17
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%30 = load i8, i8* %4
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 110
br i1 %32, label %33, label %34
33: ; preds = %27
br label %35
34: ; preds = %27
br label %10
35: ; preds = %33
%36 = load i32, i32* %2
%37 = load i32, i32* %1
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0), i32 %36, i32 %37)
ret void
}

LLVM IR (-O2):
@.str.2 = [4 x i8] c" %d\00"
@.str.5 = [4 x i8] c" %c\00"
@.str.6 = [52 x i8] c"\0A \09\09 FINAL GAME SCORE:\0A \09\09 BOT = %d JUGADOR = %d \0A\00"
@str = [31 x i8] c"\0A \09\09Benvingut al 4 en ratlla \0A\00"
@str.7 = [195 x i8] c"\09Introdueix el numero de nivells de profunditat \0A\09que usa l'arbre de possibles moviments del BOT \0A\09(es recomanable que sigui un numero entre 1 i 4\0A\09per tal de tenir un temps d'execucio raonable)\00"
@str.8 = [85 x i8] c"\0A \09\09Per a moure cal introduir \0A \09\09 el numero de la columna \0A \09\09 on vulguis tirar \00"
@str.9 = [30 x i8] c"\0A\09\09Vols tornar a jugar? (s/n)\00"
define void @main() {
%1 = alloca i8
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([195 x i8], [195 x i8]* @str.7, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @str.8, i64 0, i64 0))
br label %8
8: ; preds = %17, %0
%9 = phi i32 [ 0, %0 ], [ %18, %17 ]
%10 = phi i32 [ 0, %0 ], [ %19, %17 ]
%11 = load i32, i32* %2
%12 = call i32 @partida(i32 %11, i32 %9, i32 %10)
switch i32 %12, label %17 [
i32 1, label %13
i32 -1, label %15
]
13: ; preds = %8
%14 = add nsw i32 %10, 1
br label %17
15: ; preds = %8
%16 = add nsw i32 %9, 1
br label %17
17: ; preds = %8, %15, %13
%18 = phi i32 [ %9, %13 ], [ %16, %15 ], [ %9, %8 ]
%19 = phi i32 [ %14, %13 ], [ %10, %15 ], [ %10, %8 ]
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.9, i64 0, i64 0))
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %1)
%22 = load i8, i8* %1
%23 = icmp eq i8 %22, 110
br i1 %23, label %24, label %8
24: ; preds = %17
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0), i32 %18, i32 %19)
ret void
}