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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jg     12d6 <main+0x176>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x14(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    $0xa,%edi
call   1070 <pow@plt>
movsd  -0x50(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    1271 <main+0x111>
mov    $0x0,%al
call   1080 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e05(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe1c(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe18(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  0xde3(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <exp@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <cos@plt>
movsd  -0x60(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
movsd  0xdae(%rip),%xmm3
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a7 <main+0x47>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x18(%rbp),%esi
mov    $0xa,%edi
call   1070 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
divsd  %xmm1,%xmm0
movslq -0x18(%rbp),%rax
movsd  %xmm0,-0x40(%rbp,%rax,8)
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    $0xa,%edi
call   1070 <pow@plt>
cvttsd2si %xmm0,%esi
movslq -0x18(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm0
lea    0xd5d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118e <main+0x2e>
mov    $0xffffffff,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    0x2e85(%rip),%r12
lea    0xeb6(%rip),%r14
xor    %r15d,%r15d
jmp    11b7 <main+0x67>
nop
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    %ebp,%esi
call   1060 <pow@plt>
cvttsd2si %xmm0,%esi
mov    %r14,%rdi
movsd  0x8(%rsp),%xmm0
call   1030 <printf@plt>
mov    %ebp,%r15d
cmp    $0x5,%ebp
je     1293 <main+0x143>
lea    0x1(%r15),%ebp
mov    $0xa,%edi
mov    %ebp,%esi
call   1060 <pow@plt>
xorpd  %xmm2,%xmm2
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x8(%rsp)
ucomisd %xmm2,%xmm0
jbe    1170 <main+0x20>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq (%r12),%xmm0
divsd  %xmm0,%xmm1
mulsd  0xdec(%rip),%xmm1
addsd  0xdec(%rip),%xmm1
movsd  %xmm1,0x10(%rsp)
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  0xdde(%rip),%xmm0
call   1040 <exp@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
call   1050 <cos@plt>
addsd  0xdc8(%rip),%xmm0
mulsd  0x18(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    $0xa,%edi
mov    %ebp,%esi
call   1060 <pow@plt>
add    $0x1,%ebx
ucomisd 0x10(%rsp),%xmm0
ja     11f0 <main+0xa0>
jmp    1170 <main+0x20>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@RAND_MAX = global i64 0
@.str = [12 x i8] c"%d %.12e\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %25
%2 = phi i32 [ 0, %0 ], [ %3, %25 ]
%3 = add nuw nsw i32 %2, 1
%4 = tail call double @pow(i32 10, i32 %3)
%5 = fcmp ogt double %4, 0.000000e+00
br i1 %5, label %6, label %25
6: ; preds = %1, %6
%7 = phi double [ %20, %6 ], [ 0.000000e+00, %1 ]
%8 = phi i32 [ %21, %6 ], [ 0, %1 ]
%9 = tail call i64 (...) @rand()
%10 = sitofp i64 %9 to double
%11 = load i64, i64* @RAND_MAX
%12 = sitofp i64 %11 to double
%13 = fdiv double %10, %12
%14 = tail call double @llvm.fmuladd.f64(double %13, double 1.000000e+01, double -5.000000e+00)
%15 = fmul double %14, %14
%16 = fmul double %15, -5.000000e-01
%17 = tail call double @exp(double %16)
%18 = tail call double @cos(double %14)
%19 = fadd double %18, 5.000000e+00
%20 = tail call double @llvm.fmuladd.f64(double %17, double %19, double %7)
%21 = add nuw nsw i32 %8, 1
%22 = sitofp i32 %21 to double
%23 = tail call double @pow(i32 10, i32 %3)
%24 = fcmp ogt double %23, %22
br i1 %24, label %6, label %25
25: ; preds = %6, %1
%26 = phi double [ 0.000000e+00, %1 ], [ %20, %6 ]
%27 = tail call double @pow(i32 10, i32 %2)
%28 = fdiv double %26, %27
%29 = tail call double @pow(i32 10, i32 %3)
%30 = fptosi double %29 to i32
%31 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %30, double %28)
%32 = icmp eq i32 %3, 5
br i1 %32, label %33, label %1
33: ; preds = %25
ret i32 -1
}