#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 */
long RAND_MAX;
float logf(float);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ random();
int /*<<< orphan*/ srand(int);
int main(int argc, char *argv[]) {
  srand(5);
  float lam = 1. / (365. * 1440 / 13000);
  printf("lambda = %3.4f\n", lam);
  int i = 0;
  float ura;
  float nxtime;
  float twt = .0;
  while (1) {
    ura = 1. - (float)random() / (RAND_MAX + 1L);
    nxtime = -logf(ura) / lam;
    twt += nxtime;
    i++;
    if (twt >= 365. * 1440)
      break;
  }
  printf("total num earthquakes in this replicate year is %i\n", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x5,%edi
call   1050 <srand@plt>
movss  0xe98(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
cvttss2si -0x14(%rbp),%esi
lea    0xe9f(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    $0x0,%al
call   1060 <random@plt>
cvtsi2ss %rax,%xmm0
mov    0x2e48(%rip),%rax
mov    (%rax),%rax
add    $0x1,%rax
cvtsi2ss %rax,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe54(%rip),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
call   1030 <logf@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
divss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
addss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdf5(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1222 <main+0xe2>
jmp    1227 <main+0xe7>
jmp    118d <main+0x4d>
mov    -0x18(%rbp),%esi
lea    0xdf7(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x5,%edi
call   1050 <srand@plt>
lea    0xeb7(%rip),%rdi
xor    %esi,%esi
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
mov    0x2e82(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movss  %xmm0,0x4(%rsp)
xor    %eax,%eax
call   1060 <random@plt>
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
mov    (%r14),%rax
add    $0x1,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  %xmm0,%xmm1
movss  0xe60(%rip),%xmm0
subss  %xmm1,%xmm0
call   1030 <logf@plt>
divss  0xe53(%rip),%xmm0
movss  0x4(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
movss  0x4(%rsp),%xmm0
add    $0x1,%ebx
ucomiss 0xe37(%rip),%xmm0
jb     1170 <main+0x30>
lea    0xe42(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"lambda = %3.4f\0A\00"
@RAND_MAX = global i64 0
@.str.1 = [52 x i8] c"total num earthquakes in this replicate year is %i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca i32
%8 = alloca float
%9 = alloca float
%10 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @srand(i32 5)
store float 0x3F9953C660000000, float* %6
%12 = load float, float* %6
%13 = fptosi float %12 to i32
%14 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 0, i32* %7
store float 0.000000e+00, float* %10
br label %15
15: ; preds = %2, %39
%16 = call i64 (...) @random()
%17 = sitofp i64 %16 to float
%18 = load i64, i64* @RAND_MAX
%19 = add nsw i64 %18, 1
%20 = sitofp i64 %19 to float
%21 = fdiv float %17, %20
%22 = fpext float %21 to double
%23 = fsub double 1.000000e+00, %22
%24 = fptrunc double %23 to float
store float %24, float* %8
%25 = load float, float* %8
%26 = call float @logf(float %25)
%27 = fneg float %26
%28 = load float, float* %6
%29 = fdiv float %27, %28
store float %29, float* %9
%30 = load float, float* %9
%31 = load float, float* %10
%32 = fadd float %31, %30
store float %32, float* %10
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
%35 = load float, float* %10
%36 = fpext float %35 to double
%37 = fcmp oge double %36, 5.256000e+05
br i1 %37, label %38, label %39
38: ; preds = %15
br label %40
39: ; preds = %15
br label %15
40: ; preds = %38
%41 = load i32, i32* %7
%42 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"lambda = %3.4f\0A\00"
@RAND_MAX = global i64 0
@.str.1 = [52 x i8] c"total num earthquakes in this replicate year is %i\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @srand(i32 5)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 0)
br label %5
5: ; preds = %5, %2
%6 = phi i32 [ 0, %2 ], [ %18, %5 ]
%7 = phi float [ 0.000000e+00, %2 ], [ %17, %5 ]
%8 = tail call i64 (...) @random()
%9 = sitofp i64 %8 to float
%10 = load i64, i64* @RAND_MAX
%11 = add nsw i64 %10, 1
%12 = sitofp i64 %11 to float
%13 = fdiv float %9, %12
%14 = fsub float 1.000000e+00, %13
%15 = tail call float @logf(float %14)
%16 = fdiv float %15, 0x3F9953C660000000
%17 = fsub float %7, %16
%18 = add nuw nsw i32 %6, 1
%19 = fcmp ult float %17, 5.256000e+05
br i1 %19, label %5, label %20
20: ; preds = %5
%21 = tail call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %18)
ret i32 0
}