#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 M_PI;
scalar_t__ RAND_MAX;
double cos(double);
int exp(double);
double pow(int, int);
int /*<<< orphan*/ printf(char *, int, double);
scalar_t__ rand();
double sqrt(double);
int main() {
  double y, u;
  int i, n;
  int check = 0;
  double result[5] = {0.0};
  double sum = 0.0;
  for (n = 0; n <= 4; n++) {
    sum = 0.0;
    check = 0;
    for (i = 0; i < pow(10, n + 1); i++) {
      while (check == 0) {
        u = ((double)rand() / (double)RAND_MAX);
        y = ((double)rand() / (double)RAND_MAX) * 10.0 - 5.0;
        if (u <= ((1 / sqrt(2.0 * M_PI)) * exp(y * y / -2.0))) {
          check = 1;
          break;
        }
      }
      sum = sum + ((cos(y) + 5.0));
    }
    result[n] = sum * sqrt(2.0 * M_PI) / (pow(10, n + 1));
    printf("%d   %.12e\n", (int)pow(10, n + 1), result[n]);
  }
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jg     13ae <main+0x23e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x20(%rbp),%esi
add    $0x1,%esi
mov    $0xa,%edi
call   1070 <pow@plt>
movsd  -0x60(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    1317 <main+0x1a7>
jmp    11f6 <main+0x86>
cmpl   $0x0,-0x24(%rbp)
jne    12d8 <main+0x168>
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2dcd(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2dac(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xdd3(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdcf(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  0xd94(%rip),%xmm0
mov    0x2d75(%rip),%rax
mulsd  (%rax),%xmm0
call   1080 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xd89(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  0xd66(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <exp@plt>
movsd  -0x70(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
cvtsi2sd %eax,%xmm2
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     12d3 <main+0x163>
movl   $0x1,-0x24(%rbp)
jmp    12d8 <main+0x168>
jmp    11f6 <main+0x86>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
movsd  0xd2c(%rip),%xmm2
addsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c8 <main+0x58>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  0xcd4(%rip),%xmm0
mov    0x2cb5(%rip),%rax
mulsd  (%rax),%xmm0
call   1080 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x88(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0x20(%rbp),%esi
add    $0x1,%esi
mov    $0xa,%edi
call   1070 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
divsd  %xmm1,%xmm0
movslq -0x20(%rbp),%rax
movsd  %xmm0,-0x50(%rbp,%rax,8)
mov    -0x20(%rbp),%esi
add    $0x1,%esi
mov    $0xa,%edi
call   1070 <pow@plt>
cvttsd2si %xmm0,%esi
movslq -0x20(%rbp),%rax
movsd  -0x50(%rbp,%rax,8),%xmm0
lea    0xc95(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a8 <main+0x38>
mov    $0xffffffff,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e6b(%rip),%rbp
mov    0x2e6c(%rip),%r12
lea    0xebd(%rip),%r14
xor    %r15d,%r15d
jmp    11eb <main+0x8b>
nopl   0x0(%rax,%rax,1)
call   1070 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    $0xa,%edi
mov    %r15d,%esi
call   1060 <pow@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    $0xa,%edi
mov    %r15d,%esi
call   1060 <pow@plt>
cvttsd2si %xmm0,%esi
mov    %r14,%rdi
movsd  0x8(%rsp),%xmm0
call   1030 <printf@plt>
cmp    $0x5,%r15d
je     138b <main+0x22b>
add    $0x1,%r15d
mov    $0xa,%edi
mov    %r15d,%esi
call   1060 <pow@plt>
ucomisd 0xe1c(%rip),%xmm0
jbe    1360 <main+0x200>
xor    %r13d,%r13d
mov    $0x1,%al
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    1270 <main+0x110>
nopl   0x0(%rax,%rax,1)
movsd  0x20(%rsp),%xmm0
call   1050 <cos@plt>
addsd  0xde5(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
add    $0x1,%r13d
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    $0xa,%edi
mov    %r15d,%esi
call   1060 <pow@plt>
xor    %eax,%eax
ucomisd 0x10(%rsp),%xmm0
jbe    136a <main+0x20a>
test   $0x1,%al
jne    12e8 <main+0x188>
jmp    1220 <main+0xc0>
cs nopw 0x0(%rax,%rax,1)
call   1070 <sqrt@plt>
movsd  0x20(%rsp),%xmm1
movapd 0x10(%rsp),%xmm2
unpcklpd %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
shufpd $0x2,0xd8a(%rip),%xmm0
divpd  %xmm2,%xmm0
movapd %xmm0,0x10(%rsp)
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  0xd50(%rip),%xmm0
call   1040 <exp@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movapd 0x10(%rsp),%xmm2
movapd %xmm2,%xmm1
unpckhpd %xmm2,%xmm1
mulsd  %xmm0,%xmm1
ucomisd %xmm2,%xmm1
jae    1220 <main+0xc0>
xor    %eax,%eax
call   1080 <rand@plt>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
cvtsi2sdq 0x0(%rbp),%xmm0
movapd %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1080 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq 0x0(%rbp),%xmm0
divsd  %xmm0,%xmm1
mulsd  0xcdb(%rip),%xmm1
addsd  0xcdb(%rip),%xmm1
movsd  (%r12),%xmm0
addsd  %xmm0,%xmm0
ucomisd 0xce1(%rip),%xmm0
movsd  %xmm1,0x20(%rsp)
jb     1280 <main+0x120>
sqrtsd %xmm0,%xmm0
jmp    128b <main+0x12b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%r12),%xmm0
addsd  %xmm0,%xmm0
ucomisd 0xca4(%rip),%xmm0
jb     1190 <main+0x30>
sqrtsd %xmm0,%xmm0
jmp    1195 <main+0x35>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
@M_PI = global double 0.000000e+00
@.str = [12 x i8] c"%d %.12e\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [5 x double]
%8 = alloca double
store i32 0, i32* %1
store i32 0, i32* %6
%9 = bitcast [5 x double]* %7 to i8*
store double 0.000000e+00, double* %8
store i32 0, i32* %5
br label %10
10: ; preds = %83, %0
%11 = load i32, i32* %5
%12 = icmp sle i32 %11, 4
br i1 %12, label %13, label %86
13: ; preds = %10
store double 0.000000e+00, double* %8
store i32 0, i32* %6
store i32 0, i32* %4
br label %14
14: ; preds = %58, %13
%15 = load i32, i32* %4
%16 = sitofp i32 %15 to double
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
%19 = call double @pow(i32 10, i32 %18)
%20 = fcmp olt double %16, %19
br i1 %20, label %21, label %61
21: ; preds = %14
br label %22
22: ; preds = %51, %21
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %52
25: ; preds = %22
%26 = call i64 (...) @rand()
%27 = sitofp i64 %26 to double
%28 = load i64, i64* @RAND_MAX
%29 = sitofp i64 %28 to double
%30 = fdiv double %27, %29
store double %30, double* %3
%31 = call i64 (...) @rand()
%32 = sitofp i64 %31 to double
%33 = load i64, i64* @RAND_MAX
%34 = sitofp i64 %33 to double
%35 = fdiv double %32, %34
%36 = call double @llvm.fmuladd.f64(double %35, double 1.000000e+01, double -5.000000e+00)
store double %36, double* %2
%37 = load double, double* %3
%38 = load double, double* @M_PI
%39 = fmul double 2.000000e+00, %38
%40 = call double @sqrt(double %39)
%41 = fdiv double 1.000000e+00, %40
%42 = load double, double* %2
%43 = load double, double* %2
%44 = fmul double %42, %43
%45 = fdiv double %44, -2.000000e+00
%46 = call i32 @exp(double %45)
%47 = sitofp i32 %46 to double
%48 = fmul double %41, %47
%49 = fcmp ole double %37, %48
br i1 %49, label %50, label %51
50: ; preds = %25
store i32 1, i32* %6
br label %52
51: ; preds = %25
br label %22
52: ; preds = %50, %22
%53 = load double, double* %8
%54 = load double, double* %2
%55 = call double @cos(double %54)
%56 = fadd double %55, 5.000000e+00
%57 = fadd double %53, %56
store double %57, double* %8
br label %58
58: ; preds = %52
%59 = load i32, i32* %4
%60 = add nsw i32 %59, 1
store i32 %60, i32* %4
br label %14
61: ; preds = %14
%62 = load double, double* %8
%63 = load double, double* @M_PI
%64 = fmul double 2.000000e+00, %63
%65 = call double @sqrt(double %64)
%66 = fmul double %62, %65
%67 = load i32, i32* %5
%68 = add nsw i32 %67, 1
%69 = call double @pow(i32 10, i32 %68)
%70 = fdiv double %66, %69
%71 = load i32, i32* %5
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [5 x double], [5 x double]* %7, i64 0, i64 %72
store double %70, double* %73
%74 = load i32, i32* %5
%75 = add nsw i32 %74, 1
%76 = call double @pow(i32 10, i32 %75)
%77 = fptosi double %76 to i32
%78 = load i32, i32* %5
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [5 x double], [5 x double]* %7, i64 0, i64 %79
%81 = load double, double* %80
%82 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %77, double %81)
br label %83
83: ; preds = %61
%84 = load i32, i32* %5
%85 = add nsw i32 %84, 1
store i32 %85, i32* %5
br label %10
86: ; preds = %10
ret i32 -1
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
@M_PI = global double 0.000000e+00
@.str = [12 x i8] c"%d %.12e\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %47
%2 = phi i32 [ 0, %0 ], [ %4, %47 ]
%3 = phi double [ undef, %0 ], [ %48, %47 ]
%4 = add nuw nsw i32 %2, 1
%5 = tail call double @pow(i32 10, i32 %4)
%6 = fcmp ogt double %5, 0.000000e+00
br i1 %6, label %7, label %47
7: ; preds = %1, %38
%8 = phi double [ %42, %38 ], [ 0.000000e+00, %1 ]
%9 = phi i1 [ false, %38 ], [ true, %1 ]
%10 = phi i32 [ %43, %38 ], [ 0, %1 ]
%11 = phi double [ %39, %38 ], [ %3, %1 ]
br i1 %9, label %12, label %38
12: ; preds = %7, %12
%13 = tail call i64 (...) @rand()
%14 = sitofp i64 %13 to double
%15 = load i64, i64* @RAND_MAX
%16 = sitofp i64 %15 to double
%17 = tail call i64 (...) @rand()
%18 = sitofp i64 %17 to double
%19 = load i64, i64* @RAND_MAX
%20 = sitofp i64 %19 to double
%21 = fdiv double %18, %20
%22 = tail call double @llvm.fmuladd.f64(double %21, double 1.000000e+01, double -5.000000e+00)
%23 = load double, double* @M_PI
%24 = fmul double %23, 2.000000e+00
%25 = tail call double @sqrt(double %24)
%26 = insertelement <2 x double> <double poison, double 1.000000e+00>, double %14, i64 0
%27 = insertelement <2 x double> poison, double %16, i64 0
%28 = insertelement <2 x double> %27, double %25, i64 1
%29 = fdiv <2 x double> %26, %28
%30 = fmul double %22, %22
%31 = fmul double %30, -5.000000e-01
%32 = tail call i32 @exp(double %31)
%33 = sitofp i32 %32 to double
%34 = extractelement <2 x double> %29, i64 1
%35 = fmul double %34, %33
%36 = extractelement <2 x double> %29, i64 0
%37 = fcmp ugt double %36, %35
br i1 %37, label %12, label %38
38: ; preds = %12, %7
%39 = phi double [ %11, %7 ], [ %22, %12 ]
%40 = tail call double @cos(double %39)
%41 = fadd double %40, 5.000000e+00
%42 = fadd double %8, %41
%43 = add nuw nsw i32 %10, 1
%44 = sitofp i32 %43 to double
%45 = tail call double @pow(i32 10, i32 %4)
%46 = fcmp ogt double %45, %44
br i1 %46, label %7, label %47
47: ; preds = %38, %1
%48 = phi double [ %3, %1 ], [ %39, %38 ]
%49 = phi double [ 0.000000e+00, %1 ], [ %42, %38 ]
%50 = load double, double* @M_PI
%51 = fmul double %50, 2.000000e+00
%52 = tail call double @sqrt(double %51)
%53 = fmul double %49, %52
%54 = tail call double @pow(i32 10, i32 %4)
%55 = fdiv double %53, %54
%56 = tail call double @pow(i32 10, i32 %4)
%57 = fptosi double %56 to i32
%58 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %57, double %55)
%59 = icmp eq i32 %4, 5
br i1 %59, label %60, label %1
60: ; preds = %47
ret i32 -1
}