#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;
double fabs(double);
int /*<<< orphan*/ printf(char *, double, ...);
double sqrt(double);
int main(int argc, const char *argv[]) {
  double R = 0;
  int count = 100000;
  for (double n = 1; n < count; n++)
    R += (1.0 / (n * n));
  double S = sqrt(R * 6);
  printf("The square root of %.6lf is %.6lf.\n", S * S, S);
  double invS = M_PI;
  double invR = 0;
  double invn = 1;
  while (1) {
    invR += (1.0 / (invn * invn));
    double iterS = sqrt(invR * 6);
    if (fabs(iterS - invS) < 0.00001) {
      printf("The value of iterations that makes S = PI is %.1lf\n", invn);
      break;
    } else {
      invn++;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x186a0,-0x1c(%rbp)
movsd  0xeb3(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
cvtsi2sdl -0x1c(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    119d <main+0x7d>
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
movsd  0xe88(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe72(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1152 <main+0x32>
movsd  0xe63(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
lea    0xe66(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    0x2e10(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe0f(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
movsd  0xdf8(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xdea(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm1
subsd  -0x38(%rbp),%xmm1
movaps 0xde2(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xdc6(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    126c <main+0x14c>
movsd  -0x48(%rbp),%xmm0
lea    0xdf4(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1283 <main+0x163>
movsd  0xd8c(%rip),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    11f6 <main+0xd6>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movsd  0xed4(%rip),%xmm1
xorpd  %xmm0,%xmm0
mov    $0x3,%eax
movsd  0xecb(%rip),%xmm2
movapd %xmm1,%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movapd %xmm3,%xmm4
mulsd  %xmm3,%xmm4
movapd %xmm1,%xmm5
divsd  %xmm4,%xmm5
lea    -0x1(%rax),%ecx
xorps  %xmm4,%xmm4
cvtsi2sd %ecx,%xmm4
addsd  %xmm0,%xmm5
mulsd  %xmm4,%xmm4
movapd %xmm1,%xmm6
divsd  %xmm4,%xmm6
addsd  %xmm5,%xmm6
xorps  %xmm4,%xmm4
cvtsi2sd %eax,%xmm4
mulsd  %xmm4,%xmm4
movapd %xmm1,%xmm0
divsd  %xmm4,%xmm0
addsd  %xmm6,%xmm0
addsd  %xmm2,%xmm3
add    $0x3,%eax
cmp    $0x186a2,%eax
jne    1150 <main+0x30>
mulsd  0xe65(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11be <main+0x9e>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    11c7 <main+0xa7>
call   1040 <sqrt@plt>
movapd %xmm0,%xmm1
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
lea    0xe6a(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    0x2e04(%rip),%rax
movsd  (%rax),%xmm9
movsd  0xe27(%rip),%xmm0
subsd  %xmm9,%xmm0
andpd  0xe32(%rip),%xmm0
movsd  0xe1a(%rip),%xmm3
ucomisd %xmm0,%xmm3
jbe    122d <main+0x10d>
movsd  0xdec(%rip),%xmm4
lea    0xe49(%rip),%rdi
movapd %xmm4,%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
movsd  0xdcb(%rip),%xmm5
movsd  0xdd3(%rip),%xmm6
xorpd  %xmm8,%xmm8
movapd 0xde6(%rip),%xmm7
movapd %xmm5,%xmm2
movapd %xmm5,%xmm4
movsd  %xmm9,(%rsp)
jmp    12bb <main+0x19b>
nopw   0x0(%rax,%rax,1)
movsd  %xmm4,0x10(%rsp)
movsd  %xmm2,0x8(%rsp)
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
movapd 0xdb1(%rip),%xmm7
xorpd  %xmm8,%xmm8
movsd  0xd84(%rip),%xmm6
movsd  0xd6c(%rip),%xmm5
movsd  0x10(%rsp),%xmm4
movsd  0xd7e(%rip),%xmm3
movsd  (%rsp),%xmm9
subsd  %xmm9,%xmm0
andpd  %xmm7,%xmm0
ucomisd %xmm0,%xmm3
ja     1214 <main+0xf4>
movapd %xmm2,%xmm0
addsd  %xmm5,%xmm4
movapd %xmm4,%xmm1
mulsd  %xmm4,%xmm1
movapd %xmm5,%xmm2
divsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
mulsd  %xmm6,%xmm0
ucomisd %xmm8,%xmm0
jb     1260 <main+0x140>
sqrtsd %xmm0,%xmm0
jmp    12a8 <main+0x188>

LLVM IR (-O0):
@.str = [36 x i8] c"The square root of %.6lf is %.6lf.\0A\00"
@M_PI = global double 0.000000e+00
@.str.1 = [52 x i8] c"The value of iterations that makes S = PI is %.1lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %6
store i32 100000, i32* %7
store double 1.000000e+00, double* %8
br label %14
14: ; preds = %26, %2
%15 = load double, double* %8
%16 = load i32, i32* %7
%17 = sitofp i32 %16 to double
%18 = fcmp olt double %15, %17
br i1 %18, label %19, label %29
19: ; preds = %14
%20 = load double, double* %8
%21 = load double, double* %8
%22 = fmul double %20, %21
%23 = fdiv double 1.000000e+00, %22
%24 = load double, double* %6
%25 = fadd double %24, %23
store double %25, double* %6
br label %26
26: ; preds = %19
%27 = load double, double* %8
%28 = fadd double %27, 1.000000e+00
store double %28, double* %8
br label %14
29: ; preds = %14
%30 = load double, double* %6
%31 = fmul double %30, 6.000000e+00
%32 = call double @sqrt(double %31)
store double %32, double* %9
%33 = load double, double* %9
%34 = load double, double* %9
%35 = fmul double %33, %34
%36 = load double, double* %9
%37 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %35, double %36)
%38 = load double, double* @M_PI
store double %38, double* %10
store double 0.000000e+00, double* %11
store double 1.000000e+00, double* %12
br label %39
39: ; preds = %29, %60
%40 = load double, double* %12
%41 = load double, double* %12
%42 = fmul double %40, %41
%43 = fdiv double 1.000000e+00, %42
%44 = load double, double* %11
%45 = fadd double %44, %43
store double %45, double* %11
%46 = load double, double* %11
%47 = fmul double %46, 6.000000e+00
%48 = call double @sqrt(double %47)
store double %48, double* %13
%49 = load double, double* %13
%50 = load double, double* %10
%51 = fsub double %49, %50
%52 = call double @llvm.fabs.f64(double %51)
%53 = fcmp olt double %52, 1.000000e-05
br i1 %53, label %54, label %57
54: ; preds = %39
%55 = load double, double* %12
%56 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), double %55)
br label %61
57: ; preds = %39
%58 = load double, double* %12
%59 = fadd double %58, 1.000000e+00
store double %59, double* %12
br label %60
60: ; preds = %57
br label %39
61: ; preds = %54
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"The square root of %.6lf is %.6lf.\0A\00"
@M_PI = global double 0.000000e+00
@.str.1 = [52 x i8] c"The value of iterations that makes S = PI is %.1lf\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %12
3: ; preds = %12
%4 = fmul double %28, 6.000000e+00
%5 = tail call double @sqrt(double %4)
%6 = fmul double %5, %5
%7 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %6, double %5)
%8 = load double, double* @M_PI
%9 = fsub double 0x4003988E1409212E, %8
%10 = tail call double @llvm.fabs.f64(double %9)
%11 = fcmp olt double %10, 1.000000e-05
br i1 %11, label %43, label %31
12: ; preds = %12, %2
%13 = phi double [ 0.000000e+00, %2 ], [ %28, %12 ]
%14 = phi i32 [ 1, %2 ], [ %29, %12 ]
%15 = sitofp i32 %14 to double
%16 = fmul double %15, %15
%17 = fdiv double 1.000000e+00, %16
%18 = fadd double %13, %17
%19 = add nuw nsw i32 %14, 1
%20 = sitofp i32 %19 to double
%21 = fmul double %20, %20
%22 = fdiv double 1.000000e+00, %21
%23 = fadd double %18, %22
%24 = add nuw nsw i32 %14, 2
%25 = sitofp i32 %24 to double
%26 = fmul double %25, %25
%27 = fdiv double 1.000000e+00, %26
%28 = fadd double %23, %27
%29 = add nuw nsw i32 %14, 3
%30 = icmp eq i32 %29, 100000
br i1 %30, label %3, label %12
31: ; preds = %3, %31
%32 = phi double [ %37, %31 ], [ 1.000000e+00, %3 ]
%33 = phi double [ %34, %31 ], [ 1.000000e+00, %3 ]
%34 = fadd double %33, 1.000000e+00
%35 = fmul double %34, %34
%36 = fdiv double 1.000000e+00, %35
%37 = fadd double %32, %36
%38 = fmul double %37, 6.000000e+00
%39 = tail call double @sqrt(double %38)
%40 = fsub double %39, %8
%41 = tail call double @llvm.fabs.f64(double %40)
%42 = fcmp olt double %41, 1.000000e-05
br i1 %42, label %43, label %31
43: ; preds = %31, %3
%44 = phi double [ 1.000000e+00, %3 ], [ %34, %31 ]
%45 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), double %44)
ret i32 0
}