#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 RAND_MAX;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, ...);
scalar_t__ rand();
double sin(double);
double sqrt(double);
int /*<<< orphan*/ stderr;
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;
  confidence_level = 0.1;
  do {
    x = (double)rand() / RAND_MAX * (xmax - xmin) + xmin;
    y = sin(x);
    n++;
    sum = sum + y;
    mean = sum / n * (xmax - xmin);
    tmp = tmp + (y - mean) * (y - mean);
    error = sqrt(tmp) / n * (xmax - xmin);
    fprintf(stderr, "%f %f \n", mean, error);
  } 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    $0x60,%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
divsd  (%rax),%xmm0
movsd  -0x18(%rbp),%xmm2
subsd  -0x10(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  0xe3d(%rip),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%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  -0x28(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%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)
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
movsd  -0x38(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
lea    0xdad(%rip),%rsi
mov    $0x2,%al
call   1030 <fprintf@plt>
movsd  -0x30(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
ja     1189 <main+0x49>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
movsd  -0x38(%rbp),%xmm0
lea    0xd89(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
movsd  -0x30(%rbp),%xmm0
lea    0xd83(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    0x2e98(%rip),%r14
mov    0x2e81(%rip),%r15
lea    0xec2(%rip),%rbx
xorps  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x20(%rsp)
xorps  %xmm0,%xmm0
jmp    11d6 <main+0x96>
cs nopw 0x0(%rax,%rax,1)
nop
call   1050 <sqrt@plt>
movsd  0x18(%rsp),%xmm3
movsd  0x10(%rsp),%xmm5
movapd %xmm0,%xmm1
movsd  0xe63(%rip),%xmm4
divsd  %xmm5,%xmm1
mulsd  %xmm4,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    (%r15),%edi
mov    %rbx,%rsi
movapd %xmm3,%xmm0
mov    $0x2,%al
call   1030 <fprintf@plt>
movsd  0x8(%rsp),%xmm1
ucomisd 0xe46(%rip),%xmm1
movsd  0x28(%rsp),%xmm0
jbe    1279 <main+0x139>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
movsd  0xe08(%rip),%xmm1
mulsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
call   1040 <sin@plt>
movsd  0x10(%rsp),%xmm1
addsd  0xdf1(%rip),%xmm1
movsd  0x20(%rsp),%xmm2
addsd  %xmm0,%xmm2
movapd %xmm2,%xmm3
divsd  %xmm1,%xmm3
movsd  0xdcf(%rip),%xmm4
mulsd  %xmm4,%xmm3
subsd  %xmm3,%xmm0
mulsd  %xmm0,%xmm0
addsd  0x8(%rsp),%xmm0
ucomisd 0xdcd(%rip),%xmm0
movsd  %xmm1,0x10(%rsp)
movsd  %xmm2,0x20(%rsp)
movsd  %xmm3,0x18(%rsp)
movsd  %xmm0,0x28(%rsp)
jb     1180 <main+0x40>
movapd %xmm1,%xmm5
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    119d <main+0x5d>
mov    0x2d50(%rip),%rbx
mov    (%rbx),%edi
lea    0xd9f(%rip),%rsi
movsd  0x18(%rsp),%xmm0
mov    $0x1,%al
call   1030 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd9f(%rip),%rsi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
@stderr = global i32 0
@.str = [8 x i8] c"%f %f \0A\00"
@stdout = global i32 0
@.str.1 = [22 x i8] c"Expected integral %f\0A\00"
@.str.2 = [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 ], [ %11, %1 ]
%3 = phi double [ 0.000000e+00, %0 ], [ %12, %1 ]
%4 = phi double [ 0.000000e+00, %0 ], [ %16, %1 ]
%5 = tail call i64 (...) @rand()
%6 = sitofp i64 %5 to double
%7 = load double, double* @RAND_MAX
%8 = fdiv double %6, %7
%9 = tail call double @llvm.fmuladd.f64(double %8, double 0x400921FAFC8B007A, double 0.000000e+00)
%10 = tail call double @sin(double %9)
%11 = fadd double %2, 1.000000e+00
%12 = fadd double %3, %10
%13 = fdiv double %12, %11
%14 = fmul double %13, 0x400921FAFC8B007A
%15 = fsub double %10, %14
%16 = tail call double @llvm.fmuladd.f64(double %15, double %15, double %4)
%17 = tail call double @sqrt(double %16)
%18 = fdiv double %17, %11
%19 = fmul double %18, 0x400921FAFC8B007A
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, double, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %14, double %19)
%22 = fcmp ogt double %19, 1.000000e-01
br i1 %22, label %1, label %23
23: ; preds = %1
%24 = load i32, i32* @stdout
%25 = tail call i32 (i32, i8*, double, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), double %14)
%26 = load i32, i32* @stdout
%27 = tail call i32 (i32, i8*, double, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %19)
ret i32 0
}