#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_uni(double);
double sqrt(double);
double integral_1(int nsteps) {
  int i;
  double sum;
  double rand_nr;
  sum = 0.0;
  for (i = 0; i < nsteps; i++) {
    rand_nr = rand_uni(1.0);
    sum += sqrt(rand_nr + sqrt(rand_nr));
  }
  return sum / (double)nsteps;
}


x86 assembly (clang, -O0):
<integral_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1195 <integral_1+0x75>
movsd  0xeb2(%rip),%xmm0
call   1030 <rand_uni@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113a <integral_1+0x1a>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<integral_1>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
test   %edi,%edi
jle    11bc <integral_1+0x9c>
mov    %ebx,%ebp
xorpd  %xmm1,%xmm1
jmp    1158 <integral_1+0x38>
nopl   0x0(%rax,%rax,1)
movapd %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
add    $0xffffffff,%ebp
je     11c0 <integral_1+0xa0>
movsd  %xmm1,0x8(%rsp)
movsd  0xe9a(%rip),%xmm0
call   1030 <rand_uni@plt>
movapd %xmm0,%xmm1
ucomisd 0xe91(%rip),%xmm0
jb     1190 <integral_1+0x70>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    11a5 <integral_1+0x85>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movapd %xmm1,%xmm0
movsd  %xmm1,0x10(%rsp)
call   1040 <sqrt@plt>
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
ucomisd 0xe57(%rip),%xmm1
jb     1140 <integral_1+0x20>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    1149 <integral_1+0x29>
xorpd  %xmm1,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @integral_1(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
store i32 %0, i32* %2
store double 0.000000e+00, double* %4
store i32 0, i32* %3
br label %6
6: ; preds = %19, %1
%7 = load i32, i32* %3
%8 = load i32, i32* %2
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %22
10: ; preds = %6
%11 = call double @rand_uni(double 1.000000e+00)
store double %11, double* %5
%12 = load double, double* %5
%13 = load double, double* %5
%14 = call double @sqrt(double %13)
%15 = fadd double %12, %14
%16 = call double @sqrt(double %15)
%17 = load double, double* %4
%18 = fadd double %17, %16
store double %18, double* %4
br label %19
19: ; preds = %10
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %6
22: ; preds = %6
%23 = load double, double* %4
%24 = load i32, i32* %2
%25 = sitofp i32 %24 to double
%26 = fdiv double %23, %25
ret double %26
}

LLVM IR (-O2):
define double @integral_1(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %3, label %13
3: ; preds = %1, %3
%4 = phi i32 [ %11, %3 ], [ 0, %1 ]
%5 = phi double [ %10, %3 ], [ 0.000000e+00, %1 ]
%6 = tail call double @rand_uni(double 1.000000e+00)
%7 = tail call double @sqrt(double %6)
%8 = fadd double %6, %7
%9 = tail call double @sqrt(double %8)
%10 = fadd double %5, %9
%11 = add nuw nsw i32 %4, 1
%12 = icmp eq i32 %11, %0
br i1 %12, label %13, label %3
13: ; preds = %3, %1
%14 = phi double [ 0.000000e+00, %1 ], [ %10, %3 ]
%15 = sitofp i32 %0 to double
%16 = fdiv double %14, %15
ret double %16
}