#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__ RAND_MAX;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double);
scalar_t__ rand();
double sin(double);
double sqrt(double);
int /*<<< orphan*/ stdout;
int main() {
  double xmin = 0;
  double xmax = 3.141592;
  double x, y;
  double error;
  double mean;
  double confidence_level;
  double n = 0, sum = 0, tmp = 0;
  int k;
  confidence_level = 0.01;
  do {
    x = (double)rand() / (double)RAND_MAX * (xmax - xmin) + xmin;
    y = (double)rand() / (double)RAND_MAX;
    if (y < sin(x)) {
      k++;
    }
    n++;
    mean = (double)k / n * (xmax - xmin);
    tmp = tmp + (1 - mean) * (1 - mean);
    error = sqrt(tmp) / n * (xmax - xmin);
  } while (error > confidence_level);
  fprintf(stdout, "Expected integral %f\n", mean);
  fprintf(stdout, "Error %f\n", error);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xea9(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xe7c(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e4c(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm2
subsd  -0x10(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e14(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <sin@plt>
movsd  -0x68(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    120e <main+0xce>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
movsd  0xdfa(%rip),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
cvtsi2sdl -0x5c(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x58(%rbp),%xmm1
movsd  0xdc6(%rip),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  0xdb9(%rip),%xmm2
subsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
call   1050 <sqrt@plt>
divsd  -0x48(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
ja     1189 <main+0x49>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
movsd  -0x38(%rbp),%xmm0
lea    0xd68(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
movsd  -0x30(%rbp),%xmm0
lea    0xd64(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e99(%rip),%r14
xorpd  %xmm2,%xmm2
xorpd  %xmm1,%xmm1
jmp    11ad <main+0x6d>
nopl   0x0(%rax)
movapd %xmm1,%xmm0
movsd  %xmm2,(%rsp)
movsd  %xmm3,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm3
movsd  (%rsp),%xmm2
movapd %xmm0,%xmm4
movsd  0xe69(%rip),%xmm0
divsd  %xmm2,%xmm4
mulsd  %xmm0,%xmm4
ucomisd 0xe69(%rip),%xmm4
jbe    1275 <main+0x135>
movsd  %xmm2,(%rsp)
mov    %ebp,%ebx
movsd  %xmm1,0x10(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq (%r14),%xmm0
divsd  %xmm0,%xmm1
mulsd  0xe23(%rip),%xmm1
xorpd  %xmm0,%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq (%r14),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movsd  (%rsp),%xmm2
xor    %ebp,%ebp
ucomisd 0x18(%rsp),%xmm0
movsd  0xdd4(%rip),%xmm0
seta   %bpl
add    %ebx,%ebp
xorps  %xmm3,%xmm3
cvtsi2sd %ebp,%xmm3
movsd  0xdc7(%rip),%xmm1
addsd  %xmm1,%xmm2
divsd  %xmm2,%xmm3
mulsd  %xmm0,%xmm3
subsd  %xmm3,%xmm1
mulsd  %xmm1,%xmm1
addsd  0x10(%rsp),%xmm1
ucomisd 0xdb5(%rip),%xmm1
jb     1160 <main+0x20>
xorps  %xmm4,%xmm4
sqrtsd %xmm1,%xmm4
jmp    1197 <main+0x57>
mov    0x2d5c(%rip),%rbx
mov    (%rbx),%edi
lea    0xd9b(%rip),%rsi
movapd %xmm3,%xmm0
movsd  %xmm4,(%rsp)
call   1030 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd9a(%rip),%rsi
movsd  (%rsp),%xmm0
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
@stdout = global i32 0
@.str = [22 x i8] c"Expected integral %f\0A\00"
@.str.1 = [10 x i8] c"Error %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store double 0x400921FAFC8B007A, double* %3
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %10
store double 0.000000e+00, double* %11
store double 1.000000e-02, double* %8
br label %13
13: ; preds = %61, %0
%14 = call i64 (...) @rand()
%15 = sitofp i64 %14 to double
%16 = load i64, i64* @RAND_MAX
%17 = sitofp i64 %16 to double
%18 = fdiv double %15, %17
%19 = load double, double* %3
%20 = load double, double* %2
%21 = fsub double %19, %20
%22 = load double, double* %2
%23 = call double @llvm.fmuladd.f64(double %18, double %21, double %22)
store double %23, double* %4
%24 = call i64 (...) @rand()
%25 = sitofp i64 %24 to double
%26 = load i64, i64* @RAND_MAX
%27 = sitofp i64 %26 to double
%28 = fdiv double %25, %27
store double %28, double* %5
%29 = load double, double* %5
%30 = load double, double* %4
%31 = call double @sin(double %30)
%32 = fcmp olt double %29, %31
br i1 %32, label %33, label %36
33: ; preds = %13
%34 = load i32, i32* %12
%35 = add nsw i32 %34, 1
store i32 %35, i32* %12
br label %36
36: ; preds = %33, %13
%37 = load double, double* %9
%38 = fadd double %37, 1.000000e+00
store double %38, double* %9
%39 = load i32, i32* %12
%40 = sitofp i32 %39 to double
%41 = load double, double* %9
%42 = fdiv double %40, %41
%43 = load double, double* %3
%44 = load double, double* %2
%45 = fsub double %43, %44
%46 = fmul double %42, %45
store double %46, double* %7
%47 = load double, double* %11
%48 = load double, double* %7
%49 = fsub double 1.000000e+00, %48
%50 = load double, double* %7
%51 = fsub double 1.000000e+00, %50
%52 = call double @llvm.fmuladd.f64(double %49, double %51, double %47)
store double %52, double* %11
%53 = load double, double* %11
%54 = call double @sqrt(double %53)
%55 = load double, double* %9
%56 = fdiv double %54, %55
%57 = load double, double* %3
%58 = load double, double* %2
%59 = fsub double %57, %58
%60 = fmul double %56, %59
store double %60, double* %6
br label %61
61: ; preds = %36
%62 = load double, double* %6
%63 = load double, double* %8
%64 = fcmp ogt double %62, %63
br i1 %64, label %13, label %65
65: ; preds = %61
%66 = load i32, i32* @stdout
%67 = load double, double* %7
%68 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %67)
%69 = load i32, i32* @stdout
%70 = load double, double* %6
%71 = call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %70)
ret i32 0
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
@stdout = global i32 0
@.str = [22 x i8] c"Expected integral %f\0A\00"
@.str.1 = [10 x i8] c"Error %f\0A\00"
define i32 @main() {
br label %1
1: ; preds = %1, %0
%2 = phi double [ 0.000000e+00, %0 ], [ %20, %1 ]
%3 = phi double [ 0.000000e+00, %0 ], [ %25, %1 ]
%4 = phi i32 [ undef, %0 ], [ %19, %1 ]
%5 = tail call i64 (...) @rand()
%6 = sitofp i64 %5 to double
%7 = load i64, i64* @RAND_MAX
%8 = sitofp i64 %7 to double
%9 = fdiv double %6, %8
%10 = tail call double @llvm.fmuladd.f64(double %9, double 0x400921FAFC8B007A, double 0.000000e+00)
%11 = tail call i64 (...) @rand()
%12 = sitofp i64 %11 to double
%13 = load i64, i64* @RAND_MAX
%14 = sitofp i64 %13 to double
%15 = fdiv double %12, %14
%16 = tail call double @sin(double %10)
%17 = fcmp olt double %15, %16
%18 = zext i1 %17 to i32
%19 = add nsw i32 %4, %18
%20 = fadd double %2, 1.000000e+00
%21 = sitofp i32 %19 to double
%22 = fdiv double %21, %20
%23 = fmul double %22, 0x400921FAFC8B007A
%24 = fsub double 1.000000e+00, %23
%25 = tail call double @llvm.fmuladd.f64(double %24, double %24, double %3)
%26 = tail call double @sqrt(double %25)
%27 = fdiv double %26, %20
%28 = fmul double %27, 0x400921FAFC8B007A
%29 = fcmp ogt double %28, 1.000000e-02
br i1 %29, label %1, label %30
30: ; preds = %1
%31 = load i32, i32* @stdout
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %23)
%33 = load i32, i32* @stdout
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %28)
ret i32 0
}