#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 MD5_DIGEST_LENGTH;
int /*<<< orphan*/ addHashInHistory(unsigned int *, unsigned int **, int);
int findHashInHistory(unsigned int *, unsigned int **, int);
int /*<<< orphan*/ hash(unsigned int *, int **, int);
int /*<<< orphan*/ initGamePlane(int **, int);
int /*<<< orphan*/ nextStep(int ***, int, int);
int /*<<< orphan*/ printGamePlan(int **, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int stop = 0, begin = 0, currentPlane = 0, nb = 0;
  int gamePlane[2][50][50];
  unsigned int hash_history[100000][MD5_DIGEST_LENGTH];
  unsigned int hashcode[MD5_DIGEST_LENGTH];
  srand(time(NULL));
  initGamePlane(gamePlane[0], 50);
  while (!stop) {
    nb++;
    system("clear");
    printf("\n\nNouvelle génération :");
    printGamePlan(gamePlane[currentPlane], 50);
    system("sleep 0.02");
    hash(hashcode, gamePlane[currentPlane], 50);
    if ((begin = findHashInHistory(hashcode, hash_history, nb)) != -1) {
      printf("\nCycle repéré qui commence à la %dème itération.\n", begin);
      stop = 1;
    } else {
      addHashInHistory(hashcode, hash_history, nb);
      nextStep(gamePlane, 50, currentPlane);
      currentPlane = (currentPlane + 1) % 2;
    }
    if (nb == 100000) {
      printf("\nPas de cycle repéré... arrêt à la %de dimension.\n", 100000);
      stop = 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x4e48(%rbp)
imul   $0x61a80,%rcx,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x4e68(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x4e50(%rbp)
mov    (%rax),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x4e60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x4e58(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    -0x4e40(%rbp),%rdi
mov    $0x32,%esi
call   1070 <initGamePlane@plt>
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1262 <main+0xc2>
jmp    137c <main+0x1dc>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
lea    0xd8e(%rip),%rdi
call   1030 <system@plt>
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x1c(%rbp),%rax
lea    -0x4e40(%rbp),%rdi
imul   $0x2710,%rax,%rax
add    %rax,%rdi
mov    $0x32,%esi
call   10b0 <printGamePlan@plt>
lea    0xd75(%rip),%rdi
call   1030 <system@plt>
mov    -0x4e60(%rbp),%rdi
movslq -0x1c(%rbp),%rax
lea    -0x4e40(%rbp),%rsi
imul   $0x2710,%rax,%rax
add    %rax,%rsi
mov    $0x32,%edx
call   1040 <hash@plt>
mov    -0x4e68(%rbp),%rsi
mov    -0x4e60(%rbp),%rdi
mov    -0x20(%rbp),%edx
call   10a0 <findHashInHistory@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     1315 <main+0x175>
mov    -0x18(%rbp),%esi
lea    0xd29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    1350 <main+0x1b0>
mov    -0x4e60(%rbp),%rdi
mov    -0x4e68(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   10c0 <addHashInHistory@plt>
lea    -0x4e40(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    $0x32,%esi
call   1080 <nextStep@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
cmpl   $0x186a0,-0x20(%rbp)
jne    1377 <main+0x1d7>
lea    0xcfe(%rip),%rdi
mov    $0x186a0,%esi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    124c <main+0xac>
movl   $0x0,-0x4(%rbp)
mov    -0x4e48(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4e28,%rsp
mov    %rsp,-0x30(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
imul   $0x61a80,%rcx,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    (%rax),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    -0x4e50(%rbp),%rdi
mov    $0x32,%esi
call   1070 <initGamePlane@plt>
mov    $0x1,%r14d
xor    %r15d,%r15d
lea    0xde9(%rip),%rdi
call   1030 <system@plt>
lea    0xde3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%eax
imul   $0x2710,%rax,%rax
mov    %rbx,%r13
lea    (%rax,%rbp,1),%rbx
add    $0xffffffffffffb1b0,%rbx
mov    %rbx,%rdi
mov    $0x32,%esi
call   10b0 <printGamePlan@plt>
lea    0xdca(%rip),%rdi
call   1030 <system@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r13,%rbx
mov    $0x32,%edx
call   1040 <hash@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
call   10a0 <findHashInHistory@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
je     12a0 <main+0x100>
lea    0xda0(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x186a0,%r14d
jne    12e6 <main+0x146>
jmp    12f6 <main+0x156>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   10c0 <addHashInHistory@plt>
lea    -0x4e50(%rbp),%rdi
mov    $0x32,%esi
mov    %r15d,%edx
call   1080 <nextStep@plt>
mov    %r15d,%eax
add    $0x1,%eax
shr    $0x1f,%eax
add    %r15d,%eax
add    $0x1,%eax
and    $0xfffffffe,%eax
neg    %eax
add    %eax,%r15d
add    $0x1,%r15d
cmp    $0x186a0,%r14d
je     12f6 <main+0x156>
add    $0x1,%r14d
cmp    $0xffffffff,%r13d
je     1210 <main+0x70>
jmp    1309 <main+0x169>
lea    0xd65(%rip),%rdi
mov    $0x186a0,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x30(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MD5_DIGEST_LENGTH = global i32 0
@.str = [6 x i8] c"clear\00"
@.str.1 = [26 x i8] c"\0A\0ANouvelle g\C3\A9n\C3\A9ration :\00"
@.str.2 = [11 x i8] c"sleep 0.02\00"
@.str.3 = [55 x i8] c"\0ACycle rep\C3\A9r\C3\A9 qui commence \C3\A0 la %d\C3\A8me it\C3\A9ration.\0A\00"
@.str.4 = [55 x i8] c"\0APas de cycle rep\C3\A9r\C3\A9... arr\C3\AAt \C3\A0 la %de dimension.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [2 x [50 x [50 x i32]]]
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%14 = load i32, i32* @MD5_DIGEST_LENGTH
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %11
%17 = mul nuw i64 100000, %15
%18 = alloca i32, i64 %17
store i64 %15, i64* %12
%19 = load i32, i32* @MD5_DIGEST_LENGTH
%20 = zext i32 %19 to i64
%21 = alloca i32, i64 %20
store i64 %20, i64* %13
%22 = call i32 @time(i32* null)
%23 = call i32 @srand(i32 %22)
%24 = getelementptr inbounds [2 x [50 x [50 x i32]]], [2 x [50 x [50 x i32]]]* %10, i64 0, i64 0
%25 = getelementptr inbounds [50 x [50 x i32]], [50 x [50 x i32]]* %24, i64 0, i64 0
%26 = bitcast [50 x i32]* %25 to i32**
%27 = call i32 @initGamePlane(i32** %26, i32 50)
br label %28
28: ; preds = %73, %2
%29 = load i32, i32* %6
%30 = icmp ne i32 %29, 0
%31 = xor i1 %30, true
br i1 %31, label %32, label %74
32: ; preds = %28
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
%35 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [2 x [50 x [50 x i32]]], [2 x [50 x [50 x i32]]]* %10, i64 0, i64 %38
%40 = getelementptr inbounds [50 x [50 x i32]], [50 x [50 x i32]]* %39, i64 0, i64 0
%41 = bitcast [50 x i32]* %40 to i32**
%42 = call i32 @printGamePlan(i32** %41, i32 50)
%43 = call i32 @system(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [2 x [50 x [50 x i32]]], [2 x [50 x [50 x i32]]]* %10, i64 0, i64 %45
%47 = getelementptr inbounds [50 x [50 x i32]], [50 x [50 x i32]]* %46, i64 0, i64 0
%48 = bitcast [50 x i32]* %47 to i32**
%49 = call i32 @hash(i32* %21, i32** %48, i32 50)
%50 = bitcast i32* %18 to i32**
%51 = load i32, i32* %9
%52 = call i32 @findHashInHistory(i32* %21, i32** %50, i32 %51)
store i32 %52, i32* %7
%53 = icmp ne i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %32
%55 = load i32, i32* %7
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %55)
store i32 1, i32* %6
br label %68
57: ; preds = %32
%58 = bitcast i32* %18 to i32**
%59 = load i32, i32* %9
%60 = call i32 @addHashInHistory(i32* %21, i32** %58, i32 %59)
%61 = getelementptr inbounds [2 x [50 x [50 x i32]]], [2 x [50 x [50 x i32]]]* %10, i64 0, i64 0
%62 = bitcast [50 x [50 x i32]]* %61 to i32***
%63 = load i32, i32* %8
%64 = call i32 @nextStep(i32*** %62, i32 50, i32 %63)
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
%67 = srem i32 %66, 2
store i32 %67, i32* %8
br label %68
68: ; preds = %57, %54
%69 = load i32, i32* %9
%70 = icmp eq i32 %69, 100000
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i32 100000)
store i32 1, i32* %6
br label %73
73: ; preds = %71, %68
br label %28
74: ; preds = %28
store i32 0, i32* %3
%75 = load i8*, i8** %11
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@MD5_DIGEST_LENGTH = global i32 0
@.str = [6 x i8] c"clear\00"
@.str.1 = [26 x i8] c"\0A\0ANouvelle g\C3\A9n\C3\A9ration :\00"
@.str.2 = [11 x i8] c"sleep 0.02\00"
@.str.3 = [55 x i8] c"\0ACycle rep\C3\A9r\C3\A9 qui commence \C3\A0 la %d\C3\A8me it\C3\A9ration.\0A\00"
@.str.4 = [55 x i8] c"\0APas de cycle rep\C3\A9r\C3\A9... arr\C3\AAt \C3\A0 la %de dimension.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x [50 x [50 x i32]]]
%4 = bitcast [2 x [50 x [50 x i32]]]* %3 to i8*
%5 = load i32, i32* @MD5_DIGEST_LENGTH
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = mul nuw nsw i64 %6, 50000
%9 = alloca i32*, i64 %8
%10 = load i32, i32* @MD5_DIGEST_LENGTH
%11 = zext i32 %10 to i64
%12 = alloca i32, i64 %11
%13 = tail call i32 @time(i32* null)
%14 = tail call i32 @srand(i32 %13)
%15 = bitcast [2 x [50 x [50 x i32]]]* %3 to i32**
%16 = call i32 @initGamePlane(i32** %15, i32 50)
%17 = bitcast [2 x [50 x [50 x i32]]]* %3 to i32***
br label %18
18: ; preds = %2, %44
%19 = phi i32 [ 0, %2 ], [ %21, %44 ]
%20 = phi i32 [ 0, %2 ], [ %40, %44 ]
%21 = add nuw nsw i32 %19, 1
%22 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%24 = zext i32 %20 to i64
%25 = getelementptr inbounds [2 x [50 x [50 x i32]]], [2 x [50 x [50 x i32]]]* %3, i64 0, i64 %24, i64 0
%26 = bitcast [50 x i32]* %25 to i32**
%27 = call i32 @printGamePlan(i32** %26, i32 50)
%28 = call i32 @system(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @hash(i32* %12, i32** %26, i32 50)
%30 = call i32 @findHashInHistory(i32* %12, i32** %9, i32 %21)
%31 = icmp eq i32 %30, -1
br i1 %31, label %34, label %32
32: ; preds = %18
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %30)
br label %39
34: ; preds = %18
%35 = call i32 @addHashInHistory(i32* %12, i32** %9, i32 %21)
%36 = call i32 @nextStep(i32*** %17, i32 50, i32 %20)
%37 = add nsw i32 %20, 1
%38 = srem i32 %37, 2
br label %39
39: ; preds = %34, %32
%40 = phi i32 [ %20, %32 ], [ %38, %34 ]
%41 = icmp eq i32 %21, 100000
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i32 100000)
br label %45
44: ; preds = %39
br i1 %31, label %18, label %45
45: ; preds = %44, %42
ret i32 0
}