#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 */
double log(int);
int my_rand();
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  double l0 = 0.3, H = 1, q = 0.6, position = 0;
  int neutron_max = 30000000, passed = 0, neutron;
  for (neutron = 0; neutron < neutron_max; neutron++) {
    position = 0;
    while (position < H) {
      position += -l0 * log(1 - my_rand());
      if (position < H && my_rand() < 1 - q)
        break;
      if (position > H)
        passed++;
    }
  }
  double ans = 1.0 * passed / neutron_max;
  printf("I = %lf", ans);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movsd  0xe99(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe84(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe6f(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1c9c380,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1295 <main+0x145>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1282 <main+0x132>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    $0x0,%al
call   1030 <my_rand@plt>
mov    $0x1,%edi
sub    %eax,%edi
call   1070 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1264 <main+0x114>
mov    $0x0,%al
call   1030 <my_rand@plt>
cvtsi2sd %eax,%xmm1
movsd  0xdb8(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1264 <main+0x114>
jmp    1282 <main+0x132>
movsd  -0x28(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    127d <main+0x12d>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11c7 <main+0x77>
jmp    1287 <main+0x137>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11b3 <main+0x63>
cvtsi2sdl -0x30(%rbp),%xmm1
movsd  0xd66(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
lea    0xd58(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1193 <main+0x43>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
movsd  (%rsp),%xmm0
ucomisd 0xe89(%rip),%xmm0
seta   %al
add    %eax,%ebx
add    $0x1,%ebp
cmp    $0x1c9c380,%ebp
je     122f <main+0xdf>
xor    %eax,%eax
call   1030 <my_rand@plt>
mov    $0x1,%edi
sub    %eax,%edi
call   1070 <log@plt>
movapd %xmm0,%xmm1
mulsd  0xe4e(%rip),%xmm1
addsd  0xe5e(%rip),%xmm1
movsd  0xe46(%rip),%xmm0
movsd  %xmm1,(%rsp)
ucomisd %xmm1,%xmm0
jbe    1170 <main+0x20>
nopl   (%rax)
xor    %eax,%eax
call   1030 <my_rand@plt>
test   %eax,%eax
jle    1184 <main+0x34>
xor    %eax,%eax
movsd  0xe23(%rip),%xmm0
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
seta   %al
add    %eax,%ebx
xor    %eax,%eax
call   1030 <my_rand@plt>
mov    $0x1,%edi
sub    %eax,%edi
call   1070 <log@plt>
mulsd  0xdf2(%rip),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0xde4(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     11d0 <main+0x80>
jmp    1170 <main+0x20>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
divsd  0xdd2(%rip),%xmm0
lea    0xddb(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"I = %lf\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store i32 0, i32* %1
%10 = call i32 @time(i32* null)
%11 = call i32 @srand(i32 %10)
store double 3.000000e-01, double* %2
store double 1.000000e+00, double* %3
store double 6.000000e-01, double* %4
store double 0.000000e+00, double* %5
store i32 30000000, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %12
12: ; preds = %48, %0
%13 = load i32, i32* %8
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %51
16: ; preds = %12
store double 0.000000e+00, double* %5
br label %17
17: ; preds = %46, %16
%18 = load double, double* %5
%19 = load double, double* %3
%20 = fcmp olt double %18, %19
br i1 %20, label %21, label %47
21: ; preds = %17
%22 = load double, double* %2
%23 = fneg double %22
%24 = call i32 (...) @my_rand()
%25 = sub nsw i32 1, %24
%26 = call double @log(i32 %25)
%27 = load double, double* %5
%28 = call double @llvm.fmuladd.f64(double %23, double %26, double %27)
store double %28, double* %5
%29 = load double, double* %5
%30 = load double, double* %3
%31 = fcmp olt double %29, %30
br i1 %31, label %32, label %39
32: ; preds = %21
%33 = call i32 (...) @my_rand()
%34 = sitofp i32 %33 to double
%35 = load double, double* %4
%36 = fsub double 1.000000e+00, %35
%37 = fcmp olt double %34, %36
br i1 %37, label %38, label %39
38: ; preds = %32
br label %47
39: ; preds = %32, %21
%40 = load double, double* %5
%41 = load double, double* %3
%42 = fcmp ogt double %40, %41
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %46
46: ; preds = %43, %39
br label %17
47: ; preds = %38, %17
br label %48
48: ; preds = %47
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %12
51: ; preds = %12
%52 = load i32, i32* %7
%53 = sitofp i32 %52 to double
%54 = fmul double 1.000000e+00, %53
%55 = load i32, i32* %6
%56 = sitofp i32 %55 to double
%57 = fdiv double %54, %56
store double %57, double* %9
%58 = load double, double* %9
%59 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %58)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"I = %lf\00"
define i32 @main() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
br label %3
3: ; preds = %0, %31
%4 = phi i32 [ 0, %0 ], [ %33, %31 ]
%5 = phi i32 [ 0, %0 ], [ %32, %31 ]
%6 = tail call i32 (...) @my_rand()
%7 = sub nsw i32 1, %6
%8 = tail call double @log(i32 %7)
%9 = tail call double @llvm.fmuladd.f64(double %8, double -3.000000e-01, double 0.000000e+00)
%10 = fcmp olt double %9, 1.000000e+00
br i1 %10, label %17, label %11
11: ; preds = %22, %3
%12 = phi i32 [ %5, %3 ], [ %25, %22 ]
%13 = phi double [ %9, %3 ], [ %29, %22 ]
%14 = fcmp ogt double %13, 1.000000e+00
%15 = zext i1 %14 to i32
%16 = add nsw i32 %12, %15
br label %31
17: ; preds = %3, %22
%18 = phi double [ %29, %22 ], [ %9, %3 ]
%19 = phi i32 [ %25, %22 ], [ %5, %3 ]
%20 = tail call i32 (...) @my_rand()
%21 = icmp slt i32 %20, 1
br i1 %21, label %31, label %22
22: ; preds = %17
%23 = fcmp ogt double %18, 1.000000e+00
%24 = zext i1 %23 to i32
%25 = add nsw i32 %19, %24
%26 = tail call i32 (...) @my_rand()
%27 = sub nsw i32 1, %26
%28 = tail call double @log(i32 %27)
%29 = tail call double @llvm.fmuladd.f64(double %28, double -3.000000e-01, double %18)
%30 = fcmp olt double %29, 1.000000e+00
br i1 %30, label %17, label %11
31: ; preds = %17, %11
%32 = phi i32 [ %16, %11 ], [ %19, %17 ]
%33 = add nuw nsw i32 %4, 1
%34 = icmp eq i32 %33, 30000000
br i1 %34, label %35, label %3
35: ; preds = %31
%36 = sitofp i32 %32 to double
%37 = fdiv double %36, 3.000000e+07
%38 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %37)
ret i32 0
}