#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int M_PI;
float exp(float);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
float pow(float, double);
int /*<<< orphan*/ printf(char *, float);
float sqrt(int);
int main(int argc, char *argv[]) {
  FILE *output_file;
  output_file = fopen("escape.dat", "w");
  fprintf(output_file, "##velocity\t\tprobability\t\tcumulative probability\n");
  float probability;
  float probability_slice;
  float escape_probability = 0;
  float v_esc;
  float width = .5;
  float mass;
  float velocity;
  float temp = 1000;
  v_esc = sqrt(2 * 6.67626e-11 * 7.342e22 / (1738.1e3 + 1000e3));
  mass = 4.002 * 1.66053892e-27;
  fprintf(output_file, "## escape velocity is %f\n m/s", v_esc);
  probability = 0;
  velocity = 0;
  while (probability < 0.9999) {
    probability_slice = pow(mass / (2 * M_PI * 1.380648813e-23 * temp), 1.5);
    probability_slice *= (4 * M_PI * velocity * velocity);
    probability_slice *=
        exp(-mass * velocity * velocity / (2 * 1.380648813e-23 * temp));
    probability += probability_slice * width;
    velocity += width;
    fprintf(output_file, "%f\t\t%f\t\t%f\n", velocity, probability_slice,
            probability);
    if (velocity > v_esc)
      escape_probability += (probability_slice * width);
  }
  fclose(output_file);
  printf("escape velocity is %f m/s\n", v_esc);
  printf("99.99 per cent of all h2 are traveling below %f m/s\n", velocity);
  printf("The probability of escape is %f\n", escape_probability);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe95(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  0xe49(%rip),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  0xe38(%rip),%xmm0
movss  %xmm0,-0x38(%rbp)
mov    $0x36a1d5,%edi
call   1090 <sqrt@plt>
movss  %xmm0,-0x28(%rbp)
movss  0xe18(%rip),%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
movss  -0x28(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe6d(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xde7(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1377 <main+0x207>
movss  -0x30(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xdd4(%rip),%xmm2
mulsd  %xmm2,%xmm1
movss  -0x38(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movsd  0xdab(%rip),%xmm1
call   1080 <pow@plt>
movss  %xmm0,-0x20(%rbp)
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
shl    $0x2,%eax
cvtsi2ss %eax,%xmm0
mulss  -0x34(%rbp),%xmm0
mulss  -0x34(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x30(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  -0x34(%rbp),%xmm0
mulss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x38(%rbp),%xmm1
cvtss2sd %xmm1,%xmm2
movsd  0xd44(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1060 <exp@plt>
mulss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
movss  -0x2c(%rbp),%xmm2
movss  -0x1c(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x2c(%rbp),%xmm0
addss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x20(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movss  -0x1c(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xd4c(%rip),%rsi
mov    $0x3,%al
call   1050 <fprintf@plt>
movss  -0x34(%rbp),%xmm0
ucomiss -0x28(%rbp),%xmm0
jbe    1372 <main+0x202>
movss  -0x20(%rbp),%xmm0
movss  -0x2c(%rbp),%xmm2
movss  -0x24(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
jmp    1218 <main+0xa8>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movss  -0x28(%rbp),%xmm0
lea    0xd0c(%rip),%rdi
call   1040 <printf@plt>
movss  -0x34(%rbp),%xmm0
lea    0xd16(%rip),%rdi
call   1040 <printf@plt>
movss  -0x24(%rbp),%xmm0
lea    0xd3a(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xea8(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
lea    0xe9f(%rip),%rdi
mov    $0x30,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    $0x36a1d5,%edi
call   1090 <sqrt@plt>
movss  %xmm0,0x10(%rsp)
cvtss2sd %xmm0,%xmm0
lea    0xea3(%rip),%rsi
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <fprintf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,0x14(%rsp)
mov    0x2dfb(%rip),%rbx
lea    0xea0(%rip),%r14
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx),%eax
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xddd(%rip),%xmm0
mulsd  0xddd(%rip),%xmm0
movsd  0xddd(%rip),%xmm1
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movsd  0xdd2(%rip),%xmm1
call   1080 <pow@plt>
mov    (%rbx),%eax
shl    $0x2,%eax
xorps  %xmm2,%xmm2
cvtsi2ss %eax,%xmm2
movss  0xc(%rsp),%xmm1
mulss  %xmm1,%xmm2
mulss  %xmm1,%xmm2
mulss  %xmm0,%xmm2
movss  %xmm2,0x18(%rsp)
movaps %xmm1,%xmm0
mulss  0xdb6(%rip),%xmm0
mulss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
divsd  0xd96(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1060 <exp@plt>
movaps %xmm0,%xmm3
mulss  0x18(%rsp),%xmm3
xorps  %xmm1,%xmm1
cvtss2sd %xmm3,%xmm1
movss  0xd89(%rip),%xmm0
mulss  %xmm0,%xmm3
movaps %xmm3,0x30(%rsp)
movss  0x14(%rsp),%xmm2
addss  %xmm3,%xmm2
movss  0xc(%rsp),%xmm3
addss  %xmm0,%xmm3
movss  %xmm3,0xc(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm3,%xmm0
movss  %xmm2,0x14(%rsp)
cvtss2sd %xmm2,%xmm2
movsd  %xmm2,0x18(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x3,%al
call   1050 <fprintf@plt>
movaps 0x20(%rsp),%xmm1
movaps 0x30(%rsp),%xmm2
addss  %xmm1,%xmm2
movss  0x10(%rsp),%xmm0
cmpltss 0xc(%rsp),%xmm0
andps  %xmm0,%xmm2
andnps %xmm1,%xmm0
orps   %xmm2,%xmm0
movaps %xmm0,0x20(%rsp)
movsd  0xd05(%rip),%xmm0
ucomisd 0x18(%rsp),%xmm0
ja     1210 <main+0x90>
mov    %r15,%rdi
call   1030 <fclose@plt>
lea    0xd62(%rip),%rdi
movss  0x10(%rsp),%xmm0
call   1040 <printf@plt>
lea    0xd6b(%rip),%rdi
movss  0xc(%rsp),%xmm0
call   1040 <printf@plt>
lea    0xd8e(%rip),%rdi
movaps 0x20(%rsp),%xmm0
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"escape.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [49 x i8] c"##velocity\09\09probability\09\09cumulative probability\0A\00"
@.str.3 = [30 x i8] c"## escape velocity is %f\0A m/s\00"
@M_PI = global i32 0
@.str.4 = [12 x i8] c"%f\09\09%f\09\09%f\0A\00"
@.str.5 = [27 x i8] c"escape velocity is %f m/s\0A\00"
@.str.6 = [53 x i8] c"99.99 per cent of all h2 are traveling below %f m/s\0A\00"
@.str.7 = [33 x i8] c"The probability of escape is %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
%14 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
store float 0.000000e+00, float* %9
store float 5.000000e-01, float* %11
store float 1.000000e+03, float* %14
%18 = call float @sqrt(i32 3580373)
store float %18, float* %10
store float 0x3A80741240000000, float* %12
%19 = load i32*, i32** %6
%20 = load float, float* %10
%21 = fpext float %20 to double
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), double %21)
store float 0.000000e+00, float* %7
store float 0.000000e+00, float* %13
br label %23
23: ; preds = %87, %2
%24 = load float, float* %7
%25 = fpext float %24 to double
%26 = fcmp olt double %25, 9.999000e-01
br i1 %26, label %27, label %88
27: ; preds = %23
%28 = load float, float* %12
%29 = fpext float %28 to double
%30 = load i32, i32* @M_PI
%31 = mul nsw i32 2, %30
%32 = sitofp i32 %31 to double
%33 = fmul double %32, 0x3B30B0E6AF70CC22
%34 = load float, float* %14
%35 = fpext float %34 to double
%36 = fmul double %33, %35
%37 = fdiv double %29, %36
%38 = fptrunc double %37 to float
%39 = call float @pow(float %38, double 1.500000e+00)
store float %39, float* %8
%40 = load i32, i32* @M_PI
%41 = mul nsw i32 4, %40
%42 = sitofp i32 %41 to float
%43 = load float, float* %13
%44 = fmul float %42, %43
%45 = load float, float* %13
%46 = fmul float %44, %45
%47 = load float, float* %8
%48 = fmul float %47, %46
store float %48, float* %8
%49 = load float, float* %12
%50 = fneg float %49
%51 = load float, float* %13
%52 = fmul float %50, %51
%53 = load float, float* %13
%54 = fmul float %52, %53
%55 = fpext float %54 to double
%56 = load float, float* %14
%57 = fpext float %56 to double
%58 = fmul double 0x3B40B0E6AF70CC22, %57
%59 = fdiv double %55, %58
%60 = fptrunc double %59 to float
%61 = call float @exp(float %60)
%62 = load float, float* %8
%63 = fmul float %62, %61
store float %63, float* %8
%64 = load float, float* %8
%65 = load float, float* %11
%66 = load float, float* %7
%67 = call float @llvm.fmuladd.f32(float %64, float %65, float %66)
store float %67, float* %7
%68 = load float, float* %11
%69 = load float, float* %13
%70 = fadd float %69, %68
store float %70, float* %13
%71 = load i32*, i32** %6
%72 = load float, float* %13
%73 = fpext float %72 to double
%74 = load float, float* %8
%75 = fpext float %74 to double
%76 = load float, float* %7
%77 = fpext float %76 to double
%78 = call i32 (i32*, i8*, ...) @fprintf(i32* %71, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), double %73, double %75, double %77)
%79 = load float, float* %13
%80 = load float, float* %10
%81 = fcmp ogt float %79, %80
br i1 %81, label %82, label %87
82: ; preds = %27
%83 = load float, float* %8
%84 = load float, float* %11
%85 = load float, float* %9
%86 = call float @llvm.fmuladd.f32(float %83, float %84, float %85)
store float %86, float* %9
br label %87
87: ; preds = %82, %27
br label %23
88: ; preds = %23
%89 = load i32*, i32** %6
%90 = call i32 @fclose(i32* %89)
%91 = load float, float* %10
%92 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), float %91)
%93 = load float, float* %13
%94 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0), float %93)
%95 = load float, float* %9
%96 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), float %95)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"escape.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [49 x i8] c"##velocity\09\09probability\09\09cumulative probability\0A\00"
@.str.3 = [30 x i8] c"## escape velocity is %f\0A m/s\00"
@M_PI = global i32 0
@.str.4 = [12 x i8] c"%f\09\09%f\09\09%f\0A\00"
@.str.5 = [27 x i8] c"escape velocity is %f m/s\0A\00"
@.str.6 = [53 x i8] c"99.99 per cent of all h2 are traveling below %f m/s\0A\00"
@.str.7 = [33 x i8] c"The probability of escape is %f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i64 @fwrite(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i64 48, i64 1, i32* %3)
%5 = tail call float @sqrt(i32 3580373)
%6 = fpext float %5 to double
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), double %6)
br label %8
8: ; preds = %2, %8
%9 = phi float [ 0.000000e+00, %2 ], [ %33, %8 ]
%10 = phi float [ 0.000000e+00, %2 ], [ %34, %8 ]
%11 = phi float [ 0.000000e+00, %2 ], [ %41, %8 ]
%12 = load i32, i32* @M_PI
%13 = shl nsw i32 %12, 1
%14 = sitofp i32 %13 to double
%15 = fmul double %14, 0x3B30B0E6AF70CC22
%16 = fmul double %15, 1.000000e+03
%17 = fdiv double 0x3A80741240000000, %16
%18 = fptrunc double %17 to float
%19 = tail call float @pow(float %18, double 1.500000e+00)
%20 = load i32, i32* @M_PI
%21 = shl nsw i32 %20, 2
%22 = sitofp i32 %21 to float
%23 = fmul float %10, %22
%24 = fmul float %10, %23
%25 = fmul float %19, %24
%26 = fmul float %10, 0xBA80741240000000
%27 = fmul float %10, %26
%28 = fpext float %27 to double
%29 = fdiv double %28, 0x3BE04CC147542759
%30 = fptrunc double %29 to float
%31 = tail call float @exp(float %30)
%32 = fmul float %31, %25
%33 = tail call float @llvm.fmuladd.f32(float %32, float 5.000000e-01, float %9)
%34 = fadd float %10, 5.000000e-01
%35 = fpext float %34 to double
%36 = fpext float %32 to double
%37 = fpext float %33 to double
%38 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), double %35, double %36, double %37)
%39 = fcmp ogt float %34, %5
%40 = tail call float @llvm.fmuladd.f32(float %32, float 5.000000e-01, float %11)
%41 = select i1 %39, float %40, float %11
%42 = fcmp olt double %37, 9.999000e-01
br i1 %42, label %8, label %43
43: ; preds = %8
%44 = tail call i32 @fclose(i32* %3)
%45 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), float %5)
%46 = tail call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0), float %34)
%47 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), float %41)
ret i32 0
}