#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 */
scalar_t__ randomChance(double);
int /*<<< orphan*/ randomize();
int halfLife(int year, int atoms) {
  int remains = atoms;
  randomize();
  for (int j = 0; j < year + 1; j++) {
    remains = atoms;
    for (int i = 0; i < remains; i++) {
      if (randomChance(0.5))
        atoms--;
    }
  }
  return remains;
}


x86 assembly (clang, -O0):
<halfLife>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <randomize@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11b2 <halfLife+0x92>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119f <halfLife+0x7f>
movsd  0xe8c(%rip),%xmm0
call   1040 <randomChance@plt>
cmp    $0x0,%rax
je     118c <halfLife+0x6c>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1191 <halfLife+0x71>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1160 <halfLife+0x40>
jmp    11a4 <halfLife+0x84>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1142 <halfLife+0x22>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<halfLife>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebx
mov    %edi,%r14d
xor    %r12d,%r12d
xor    %eax,%eax
call   1030 <randomize@plt>
test   %r14d,%r14d
jns    115d <halfLife+0x3d>
mov    %ebx,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
nopl   0x0(%rax,%rax,1)
lea    0x1(%r12),%eax
cmp    %r14d,%r12d
mov    %eax,%r12d
je     113f <halfLife+0x1f>
mov    %ebx,%r15d
mov    %ebx,%ebp
test   %ebx,%ebx
jle    1150 <halfLife+0x30>
cs nopw 0x0(%rax,%rax,1)
movsd  0xe88(%rip),%xmm0
call   1040 <randomChance@plt>
cmp    $0x1,%rax
adc    $0xffffffff,%ebx
add    $0xffffffff,%ebp
jne    1170 <halfLife+0x50>
jmp    1150 <halfLife+0x30>

LLVM IR (-O0):
define i32 @halfLife(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
store i32 %8, i32* %5
%9 = call i32 (...) @randomize()
store i32 0, i32* %6
br label %10
10: ; preds = %32, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %35
15: ; preds = %10
%16 = load i32, i32* %4
store i32 %16, i32* %5
store i32 0, i32* %7
br label %17
17: ; preds = %28, %15
%18 = load i32, i32* %7
%19 = load i32, i32* %5
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = call i64 @randomChance(double 5.000000e-01)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %4
%26 = add nsw i32 %25, -1
store i32 %26, i32* %4
br label %27
27: ; preds = %24, %21
br label %28
28: ; preds = %27
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %17
31: ; preds = %17
br label %32
32: ; preds = %31
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %10
35: ; preds = %10
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
define i32 @halfLife(i32 %0, i32 %1) {
%3 = tail call i32 (...) @randomize()
%4 = icmp slt i32 %0, 0
br i1 %4, label %9, label %5
5: ; preds = %2, %11
%6 = phi i32 [ %13, %11 ], [ 0, %2 ]
%7 = phi i32 [ %12, %11 ], [ %1, %2 ]
%8 = icmp sgt i32 %7, 0
br i1 %8, label %15, label %11
9: ; preds = %11, %2
%10 = phi i32 [ %1, %2 ], [ %7, %11 ]
ret i32 %10
11: ; preds = %15, %5
%12 = phi i32 [ %7, %5 ], [ %21, %15 ]
%13 = add nuw i32 %6, 1
%14 = icmp eq i32 %6, %0
br i1 %14, label %9, label %5
15: ; preds = %5, %15
%16 = phi i32 [ %22, %15 ], [ 0, %5 ]
%17 = phi i32 [ %21, %15 ], [ %7, %5 ]
%18 = tail call i64 @randomChance(double 5.000000e-01)
%19 = icmp ne i64 %18, 0
%20 = sext i1 %19 to i32
%21 = add nsw i32 %17, %20
%22 = add nuw nsw i32 %16, 1
%23 = icmp eq i32 %22, %7
br i1 %23, label %11, label %15
}