#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__ M_PI;
int /*<<< orphan*/ printf(char *, int, long, double, double, scalar_t__);
int sqrt(int);
int main() {
  int i;
  long n;
  double s, p;
  i = 0;
  n = 2;
  s = sqrt(1.);
  p = n / s;
  printf("%3d   %10ld   %.14f    % .14f    % .14f\n", i, n, s, p, M_PI - p);
  for (i = 1; i < 28; i++) {
    s = sqrt((2 * s * s) + (2 * sqrt((s * s * s * s) - (s * s))));
    n *= 2;
    p = n / s;
    printf("%3d   %10ld   %.14f    % .14f    % .14f\n", i, n, s, p, M_PI - p);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x2,-0x10(%rbp)
mov    $0x1,%edi
call   1040 <sqrt@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
cvtsi2sdq -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    0x2e6f(%rip),%rax
cvtsi2sdq (%rax),%xmm2
subsd  -0x20(%rbp),%xmm2
cvttsd2si %xmm2,%rcx
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x1c,-0x8(%rbp)
jge    128f <main+0x16f>
movsd  0xe53(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
shl    $0x1,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x10(%rbp)
cvtsi2sdq -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    0x2d82(%rip),%rax
cvtsi2sdq (%rax),%xmm2
subsd  -0x20(%rbp),%xmm2
cvttsd2si %xmm2,%rcx
lea    0xd8c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119b <main+0x7b>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%ebp
mov    $0x1,%edi
call   1040 <sqrt@plt>
cvtsi2sd %eax,%xmm0
movsd  0xebb(%rip),%xmm1
mov    0x2e9c(%rip),%r15
cvtsi2sdq (%r15),%xmm2
divsd  %xmm0,%xmm1
subsd  %xmm1,%xmm2
cvttsd2si %xmm2,%rcx
lea    0xea3(%rip),%r14
mov    $0x2,%ebx
mov    $0x2,%edx
mov    %r14,%rdi
xor    %esi,%esi
movsd  %xmm0,0x8(%rsp)
call   1030 <printf@plt>
nop
movsd  0x8(%rsp),%xmm2
movsd  %xmm2,0x8(%rsp)
movapd %xmm2,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,0x10(%rsp)
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
movapd %xmm2,%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm2,%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1040 <sqrt@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1040 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    %rbx,%rbx
xorps  %xmm1,%xmm1
cvtsi2sd %rbx,%xmm1
xorps  %xmm2,%xmm2
cvtsi2sdq (%r15),%xmm2
divsd  %xmm0,%xmm1
subsd  %xmm1,%xmm2
cvttsd2si %xmm2,%rcx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
movsd  %xmm0,0x8(%rsp)
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    $0x1c,%ebp
jne    1180 <main+0x60>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"%3d %10ld %.14f % .14f % .14f\0A\00"
@M_PI = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca double
%5 = alloca double
store i32 0, i32* %1
store i32 0, i32* %2
store i64 2, i64* %3
%6 = call i32 @sqrt(i32 1)
%7 = sitofp i32 %6 to double
store double %7, double* %4
%8 = load i64, i64* %3
%9 = sitofp i64 %8 to double
%10 = load double, double* %4
%11 = fdiv double %9, %10
store double %11, double* %5
%12 = load i32, i32* %2
%13 = load i64, i64* %3
%14 = load double, double* %4
%15 = load double, double* %5
%16 = load i64, i64* @M_PI
%17 = sitofp i64 %16 to double
%18 = load double, double* %5
%19 = fsub double %17, %18
%20 = fptosi double %19 to i64
%21 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %12, i64 %13, double %14, double %15, i64 %20)
store i32 1, i32* %2
br label %22
22: ; preds = %64, %0
%23 = load i32, i32* %2
%24 = icmp slt i32 %23, 28
br i1 %24, label %25, label %67
25: ; preds = %22
%26 = load double, double* %4
%27 = fmul double 2.000000e+00, %26
%28 = load double, double* %4
%29 = load double, double* %4
%30 = load double, double* %4
%31 = fmul double %29, %30
%32 = load double, double* %4
%33 = fmul double %31, %32
%34 = load double, double* %4
%35 = load double, double* %4
%36 = load double, double* %4
%37 = fmul double %35, %36
%38 = fneg double %37
%39 = call double @llvm.fmuladd.f64(double %33, double %34, double %38)
%40 = fptosi double %39 to i32
%41 = call i32 @sqrt(i32 %40)
%42 = mul nsw i32 2, %41
%43 = sitofp i32 %42 to double
%44 = call double @llvm.fmuladd.f64(double %27, double %28, double %43)
%45 = fptosi double %44 to i32
%46 = call i32 @sqrt(i32 %45)
%47 = sitofp i32 %46 to double
store double %47, double* %4
%48 = load i64, i64* %3
%49 = mul nsw i64 %48, 2
store i64 %49, i64* %3
%50 = load i64, i64* %3
%51 = sitofp i64 %50 to double
%52 = load double, double* %4
%53 = fdiv double %51, %52
store double %53, double* %5
%54 = load i32, i32* %2
%55 = load i64, i64* %3
%56 = load double, double* %4
%57 = load double, double* %5
%58 = load i64, i64* @M_PI
%59 = sitofp i64 %58 to double
%60 = load double, double* %5
%61 = fsub double %59, %60
%62 = fptosi double %61 to i64
%63 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %54, i64 %55, double %56, double %57, i64 %62)
br label %64
64: ; preds = %25
%65 = load i32, i32* %2
%66 = add nsw i32 %65, 1
store i32 %66, i32* %2
br label %22
67: ; preds = %22
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c"%3d %10ld %.14f % .14f % .14f\0A\00"
@M_PI = global i64 0
define i32 @main() {
%1 = tail call i32 @sqrt(i32 1)
%2 = sitofp i32 %1 to double
%3 = fdiv double 2.000000e+00, %2
%4 = load i64, i64* @M_PI
%5 = sitofp i64 %4 to double
%6 = fsub double %5, %3
%7 = fptosi double %6 to i64
%8 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 0, i64 2, double %2, double %3, i64 %7)
br label %9
9: ; preds = %0, %9
%10 = phi double [ %2, %0 ], [ %25, %9 ]
%11 = phi i64 [ 2, %0 ], [ %26, %9 ]
%12 = phi i32 [ 1, %0 ], [ %34, %9 ]
%13 = fmul double %10, 2.000000e+00
%14 = fmul double %10, %10
%15 = fmul double %10, %14
%16 = fneg double %14
%17 = tail call double @llvm.fmuladd.f64(double %15, double %10, double %16)
%18 = fptosi double %17 to i32
%19 = tail call i32 @sqrt(i32 %18)
%20 = shl nsw i32 %19, 1
%21 = sitofp i32 %20 to double
%22 = tail call double @llvm.fmuladd.f64(double %13, double %10, double %21)
%23 = fptosi double %22 to i32
%24 = tail call i32 @sqrt(i32 %23)
%25 = sitofp i32 %24 to double
%26 = shl nsw i64 %11, 1
%27 = sitofp i64 %26 to double
%28 = fdiv double %27, %25
%29 = load i64, i64* @M_PI
%30 = sitofp i64 %29 to double
%31 = fsub double %30, %28
%32 = fptosi double %31 to i64
%33 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %12, i64 %26, double %25, double %28, i64 %32)
%34 = add nuw nsw i32 %12, 1
%35 = icmp eq i32 %34, 28
br i1 %35, label %36, label %9
36: ; preds = %9
ret i32 0
}