#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*/ printf(char *, ...);
unsigned long random();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  long unsigned int i, j, max_j, genome_1, genome_2, genome_max, mutator, limit,
      actual_limit, minimal_complexity, print;
  minimal_complexity = 0xf;
  actual_limit = minimal_complexity;
  limit = 0xffff;
  print = 1;
  j = 0;
  max_j = 0;
  genome_1 = random() % (actual_limit + 1);
  genome_2 = random() % (actual_limit + 1);
  for (i = 0; genome_1 <= limit; i++) {
    if (print == 1) {
      printf("surviving genome:  %8x ", genome_1, genome_2);
    }
    if (genome_1 > genome_2) {
      print = 0;
      j++;
    } else if (genome_2 > genome_1) {
      printf("(%d)", j);
      if (j > max_j) {
        max_j = j;
        genome_max = genome_1;
        printf(" *");
      }
      printf("\n");
      j = 0;
      genome_1 = genome_2;
      print = 1;
      actual_limit++;
    } else {
    }
    genome_2 = random() % (actual_limit + 1);
  }
  printf("\nlast round: genome 1 (%x) vs. genome 2 (%x)", genome_1, genome_2);
  printf("\nthe longest surviving genome was %x with %d generations",
         genome_max, max_j);
  printf("\nthis game took %d generations to finish.\n", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movq   $0xf,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x50(%rbp)
movq   $0xffff,-0x48(%rbp)
movq   $0x1,-0x60(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1060 <random@plt>
mov    -0x50(%rbp),%rcx
add    $0x1,%rcx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x28(%rbp)
mov    $0x0,%al
call   1060 <random@plt>
mov    -0x50(%rbp),%rcx
add    $0x1,%rcx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x30(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x48(%rbp),%rax
ja     12d3 <main+0x193>
cmpq   $0x1,-0x60(%rbp)
jne    11f6 <main+0xb6>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jbe    121d <main+0xdd>
movq   $0x0,-0x60(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    12aa <main+0x16a>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    12a0 <main+0x160>
mov    -0x18(%rbp),%rsi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    1269 <main+0x129>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x1,-0x60(%rbp)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    12a5 <main+0x165>
jmp    12a5 <main+0x165>
jmp    12aa <main+0x16a>
mov    $0x0,%al
call   1060 <random@plt>
mov    -0x50(%rbp),%rcx
add    $0x1,%rcx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x30(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11c7 <main+0x87>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xd3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %eax,%eax
call   1070 <random@plt>
mov    %rax,%rbp
and    $0xf,%ebp
xor    %eax,%eax
call   1070 <random@plt>
mov    %rax,%r14
and    $0xf,%r14d
mov    $0xf,%r15d
mov    $0x1,%r13d
xor    %ebx,%ebx
xor    %r12d,%r12d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    11c9 <main+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edx,%edx
div    %rcx
mov    %rdx,%r14
add    $0x1,%rbx
cmp    $0x10000,%rbp
jae    1273 <main+0x123>
cmp    $0x1,%r13
jne    11e3 <main+0x93>
lea    0xe2a(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %r14,%rbp
jbe    1200 <main+0xb0>
add    $0x1,%r12
xor    %r13d,%r13d
jmp    124c <main+0xfc>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
jae    124c <main+0xfc>
lea    0xe0f(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    0x8(%rsp),%r12
jbe    1232 <main+0xe2>
lea    0xdfc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,0x10(%rsp)
mov    %r12,0x8(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r15
mov    $0x1,%r13d
mov    %r14,%rbp
xor    %r12d,%r12d
xor    %eax,%eax
call   1070 <random@plt>
lea    0x1(%r15),%rcx
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
jne    11b0 <main+0x60>
xor    %edx,%edx
div    %ecx
mov    %edx,%r14d
jmp    11b8 <main+0x68>
lea    0xda6(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdbf(%rip),%rdi
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xde0(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"surviving genome: %8x \00"
@.str.1 = [5 x i8] c"(%d)\00"
@.str.2 = [3 x i8] c" *\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [45 x i8] c"\0Alast round: genome 1 (%x) vs. genome 2 (%x)\00"
@.str.5 = [57 x i8] c"\0Athe longest surviving genome was %x with %d generations\00"
@.str.6 = [43 x i8] c"\0Athis game took %d generations to finish.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
store i32 0, i32* %1
%13 = call i32 @time(i32* null)
%14 = call i32 @srand(i32 %13)
store i64 15, i64* %11
%15 = load i64, i64* %11
store i64 %15, i64* %10
store i64 65535, i64* %9
store i64 1, i64* %12
store i64 0, i64* %3
store i64 0, i64* %4
%16 = call i64 (...) @random()
%17 = load i64, i64* %10
%18 = add i64 %17, 1
%19 = urem i64 %16, %18
store i64 %19, i64* %5
%20 = call i64 (...) @random()
%21 = load i64, i64* %10
%22 = add i64 %21, 1
%23 = urem i64 %20, %22
store i64 %23, i64* %6
store i64 0, i64* %2
br label %24
24: ; preds = %68, %0
%25 = load i64, i64* %5
%26 = load i64, i64* %9
%27 = icmp ule i64 %25, %26
br i1 %27, label %28, label %71
28: ; preds = %24
%29 = load i64, i64* %12
%30 = icmp eq i64 %29, 1
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i64, i64* %5
%33 = load i64, i64* %6
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %32, i64 %33)
br label %35
35: ; preds = %31, %28
%36 = load i64, i64* %5
%37 = load i64, i64* %6
%38 = icmp ugt i64 %36, %37
br i1 %38, label %39, label %42
39: ; preds = %35
store i64 0, i64* %12
%40 = load i64, i64* %3
%41 = add i64 %40, 1
store i64 %41, i64* %3
br label %63
42: ; preds = %35
%43 = load i64, i64* %6
%44 = load i64, i64* %5
%45 = icmp ugt i64 %43, %44
br i1 %45, label %46, label %61
46: ; preds = %42
%47 = load i64, i64* %3
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %47)
%49 = load i64, i64* %3
%50 = load i64, i64* %4
%51 = icmp ugt i64 %49, %50
br i1 %51, label %52, label %56
52: ; preds = %46
%53 = load i64, i64* %3
store i64 %53, i64* %4
%54 = load i64, i64* %5
store i64 %54, i64* %7
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %56
56: ; preds = %52, %46
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i64 0, i64* %3
%58 = load i64, i64* %6
store i64 %58, i64* %5
store i64 1, i64* %12
%59 = load i64, i64* %10
%60 = add i64 %59, 1
store i64 %60, i64* %10
br label %62
61: ; preds = %42
br label %62
62: ; preds = %61, %56
br label %63
63: ; preds = %62, %39
%64 = call i64 (...) @random()
%65 = load i64, i64* %10
%66 = add i64 %65, 1
%67 = urem i64 %64, %66
store i64 %67, i64* %6
br label %68
68: ; preds = %63
%69 = load i64, i64* %2
%70 = add i64 %69, 1
store i64 %70, i64* %2
br label %24
71: ; preds = %24
%72 = load i64, i64* %5
%73 = load i64, i64* %6
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i64 %72, i64 %73)
%75 = load i64, i64* %7
%76 = load i64, i64* %4
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0), i64 %75, i64 %76)
%78 = load i64, i64* %2
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i64 %78)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"surviving genome: %8x \00"
@.str.1 = [5 x i8] c"(%d)\00"
@.str.2 = [3 x i8] c" *\00"
@.str.4 = [45 x i8] c"\0Alast round: genome 1 (%x) vs. genome 2 (%x)\00"
@.str.5 = [57 x i8] c"\0Athe longest surviving genome was %x with %d generations\00"
@.str.6 = [43 x i8] c"\0Athis game took %d generations to finish.\0A\00"
define i32 @main() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
%3 = tail call i64 (...) @random()
%4 = and i64 %3, 15
%5 = tail call i64 (...) @random()
%6 = and i64 %5, 15
br label %7
7: ; preds = %0, %35
%8 = phi i64 [ 1, %0 ], [ %41, %35 ]
%9 = phi i64 [ 0, %0 ], [ %45, %35 ]
%10 = phi i64 [ 15, %0 ], [ %40, %35 ]
%11 = phi i64 [ 0, %0 ], [ %39, %35 ]
%12 = phi i64 [ 0, %0 ], [ %38, %35 ]
%13 = phi i64 [ undef, %0 ], [ %37, %35 ]
%14 = phi i64 [ %6, %0 ], [ %44, %35 ]
%15 = phi i64 [ %4, %0 ], [ %36, %35 ]
%16 = icmp eq i64 %8, 1
br i1 %16, label %17, label %19
17: ; preds = %7
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %15, i64 %14)
br label %19
19: ; preds = %17, %7
%20 = icmp ugt i64 %15, %14
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = add i64 %11, 1
br label %35
23: ; preds = %19
%24 = icmp ugt i64 %14, %15
br i1 %24, label %25, label %35
25: ; preds = %23
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %11)
%27 = icmp ugt i64 %11, %12
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
%31 = phi i64 [ %15, %28 ], [ %13, %25 ]
%32 = phi i64 [ %11, %28 ], [ %12, %25 ]
%33 = tail call i32 @putchar(i32 10)
%34 = add i64 %10, 1
br label %35
35: ; preds = %30, %23, %21
%36 = phi i64 [ %15, %21 ], [ %14, %30 ], [ %15, %23 ]
%37 = phi i64 [ %13, %21 ], [ %31, %30 ], [ %13, %23 ]
%38 = phi i64 [ %12, %21 ], [ %32, %30 ], [ %12, %23 ]
%39 = phi i64 [ %22, %21 ], [ 0, %30 ], [ %11, %23 ]
%40 = phi i64 [ %10, %21 ], [ %34, %30 ], [ %10, %23 ]
%41 = phi i64 [ 0, %21 ], [ 1, %30 ], [ %8, %23 ]
%42 = tail call i64 (...) @random()
%43 = add i64 %40, 1
%44 = urem i64 %42, %43
%45 = add i64 %9, 1
%46 = icmp ult i64 %36, 65536
br i1 %46, label %7, label %47
47: ; preds = %35
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i64 %36, i64 %44)
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0), i64 %37, i64 %38)
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i64 %45)
ret i32 0
}