#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 rand();
int simulate() {
  int generation = 0;
  int count = 2;
  while (generation++ < 10 && count) {
    int new_count = 0;
    for (int i = 0; i < count; ++i) {
      if (rand() % 4) {
        new_count += 2;
      }
    }
    count = new_count;
  }
  return count == 0;
}


x86 assembly (clang, -O0):
<simulate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x4(%rbp),%ecx
mov    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x11(%rbp)
jge    1149 <simulate+0x39>
cmpl   $0x0,-0x8(%rbp)
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1159 <simulate+0x49>
jmp    11b2 <simulate+0xa2>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a7 <simulate+0x97>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1194 <simulate+0x84>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    1199 <simulate+0x89>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1167 <simulate+0x57>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1126 <simulate+0x16>
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simulate>:
push   %rbp
push   %r14
push   %rbx
mov    $0x2,%ecx
mov    $0x1,%r14d
nop
test   %ecx,%ecx
jle    1156 <simulate+0x46>
mov    %ecx,%ebp
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
mov    %ecx,%ebx
xor    %eax,%eax
call   1030 <rand@plt>
lea    0x2(%rbx),%ecx
test   $0x3,%al
cmove  %ebx,%ecx
add    $0xffffffff,%ebp
jne    1130 <simulate+0x20>
cmp    $0x9,%r14d
ja     1158 <simulate+0x48>
add    $0x1,%r14d
test   %ecx,%ecx
jne    1120 <simulate+0x10>
jmp    1158 <simulate+0x48>
xor    %ecx,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @simulate() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 2, i32* %2
br label %5
5: ; preds = %30, %0
%6 = load i32, i32* %1
%7 = add nsw i32 %6, 1
store i32 %7, i32* %1
%8 = icmp slt i32 %6, 10
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 0
br label %12
12: ; preds = %9, %5
%13 = phi i1 [ false, %5 ], [ %11, %9 ]
br i1 %13, label %14, label %32
14: ; preds = %12
store i32 0, i32* %3
store i32 0, i32* %4
br label %15
15: ; preds = %27, %14
%16 = load i32, i32* %4
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 4
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 2
store i32 %25, i32* %3
br label %26
26: ; preds = %23, %19
br label %27
27: ; preds = %26
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %15
30: ; preds = %15
%31 = load i32, i32* %3
store i32 %31, i32* %2
br label %5
32: ; preds = %12
%33 = load i32, i32* %2
%34 = icmp eq i32 %33, 0
%35 = zext i1 %34 to i32
ret i32 %35
}

LLVM IR (-O2):
define i32 @simulate() {
br label %6
1: ; preds = %10
%2 = add nuw nsw i32 %7, 1
%3 = icmp ult i32 %7, 10
%4 = icmp ne i32 %17, 0
%5 = select i1 %3, i1 %4, i1 false
br i1 %5, label %6, label %20
6: ; preds = %0, %1
%7 = phi i32 [ 1, %0 ], [ %2, %1 ]
%8 = phi i32 [ 2, %0 ], [ %17, %1 ]
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %6, %10
%11 = phi i32 [ %18, %10 ], [ 0, %6 ]
%12 = phi i32 [ %17, %10 ], [ 0, %6 ]
%13 = tail call i32 (...) @rand()
%14 = and i32 %13, 3
%15 = icmp eq i32 %14, 0
%16 = add nsw i32 %12, 2
%17 = select i1 %15, i32 %12, i32 %16
%18 = add nuw nsw i32 %11, 1
%19 = icmp eq i32 %18, %8
br i1 %19, label %1, label %10
20: ; preds = %6, %1
%21 = phi i32 [ %17, %1 ], [ 0, %6 ]
%22 = icmp eq i32 %21, 0
%23 = zext i1 %22 to i32
ret i32 %23
}