#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int sqrt(double);
int /*<<< orphan*/ stderr;
double archimedes(int N) {
  double ti, tii, fact, res;
  int i;
  fprintf(stderr, " i Ai+1                  Ti+1\n");
  ti = 1. / sqrt(3.);
  fact = 1;
  for (i = 1; i <= N; i++) {
    double s = sqrt(ti * ti + 1);
    tii = (s - 1) / ti;
    ti = tii;
    fact *= 2;
    res = 6 * fact * tii;
    fprintf(stderr, "%2d %.15e %.15e\n", i, res, tii);
  }
  return res;
}


x86 assembly (clang, -O0):
<archimedes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2eae(%rip),%rax
mov    (%rax),%edi
lea    0xee5(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movsd  0xebe(%rip),%xmm0
call   1040 <sqrt@plt>
cvtsi2sd %eax,%xmm1
movsd  0xea5(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe94(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     122c <archimedes+0x10c>
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe66(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe47(%rip),%xmm1
subsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe3f(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe25(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
movsd  -0x28(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
lea    0xe28(%rip),%rsi
mov    $0x2,%al
call   1030 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1178 <archimedes+0x58>
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<archimedes>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r14d
mov    0x2eab(%rip),%r12
mov    (%r12),%edi
lea    0xee0(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
movsd  0xeb1(%rip),%xmm0
call   1040 <sqrt@plt>
test   %r14d,%r14d
jle    120f <archimedes+0xef>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xe9c(%rip),%xmm1
movapd %xmm1,%xmm2
divsd  %xmm0,%xmm2
neg    %r14d
mov    $0x1,%ebx
lea    0xebc(%rip),%r15
movsd  %xmm1,0x8(%rsp)
nopl   0x0(%rax)
movsd  %xmm2,(%rsp)
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
addsd  0xe63(%rip),%xmm0
call   1040 <sqrt@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
addsd  0xe57(%rip),%xmm1
divsd  (%rsp),%xmm1
movsd  %xmm1,(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  0xe3d(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    (%r12),%edi
mov    %r15,%rsi
mov    %ebx,%edx
movsd  %xmm0,0x10(%rsp)
mov    $0x2,%al
call   1030 <fprintf@plt>
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
movsd  (%rsp),%xmm2
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1190 <archimedes+0x70>
jmp    120f <archimedes+0xef>
movsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c" i Ai+1 Ti+1\0A\00"
@.str.1 = [17 x i8] c"%2d %.15e %.15e\0A\00"
define double @archimedes(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
store i32 %0, i32* %2
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @sqrt(double 3.000000e+00)
%12 = sitofp i32 %11 to double
%13 = fdiv double 1.000000e+00, %12
store double %13, double* %3
store double 1.000000e+00, double* %5
store i32 1, i32* %7
br label %14
14: ; preds = %40, %1
%15 = load i32, i32* %7
%16 = load i32, i32* %2
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %43
18: ; preds = %14
%19 = load double, double* %3
%20 = load double, double* %3
%21 = call double @llvm.fmuladd.f64(double %19, double %20, double 1.000000e+00)
%22 = call i32 @sqrt(double %21)
%23 = sitofp i32 %22 to double
store double %23, double* %8
%24 = load double, double* %8
%25 = fsub double %24, 1.000000e+00
%26 = load double, double* %3
%27 = fdiv double %25, %26
store double %27, double* %4
%28 = load double, double* %4
store double %28, double* %3
%29 = load double, double* %5
%30 = fmul double %29, 2.000000e+00
store double %30, double* %5
%31 = load double, double* %5
%32 = fmul double 6.000000e+00, %31
%33 = load double, double* %4
%34 = fmul double %32, %33
store double %34, double* %6
%35 = load i32, i32* @stderr
%36 = load i32, i32* %7
%37 = load double, double* %6
%38 = load double, double* %4
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %36, double %37, double %38)
br label %40
40: ; preds = %18
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %14
43: ; preds = %14
%44 = load double, double* %6
ret double %44
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c" i Ai+1 Ti+1\0A\00"
@.str.1 = [17 x i8] c"%2d %.15e %.15e\0A\00"
define double @archimedes(i32 %0) {
%2 = load i32, i32* @stderr
%3 = tail call i32 (i32, i8*, ...) @fprintf(i32 %2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @sqrt(double 3.000000e+00)
%5 = icmp slt i32 %0, 1
br i1 %5, label %25, label %6
6: ; preds = %1
%7 = sitofp i32 %4 to double
%8 = fdiv double 1.000000e+00, %7
br label %9
9: ; preds = %6, %9
%10 = phi double [ %17, %9 ], [ %8, %6 ]
%11 = phi i32 [ %23, %9 ], [ 1, %6 ]
%12 = phi double [ %18, %9 ], [ 1.000000e+00, %6 ]
%13 = tail call double @llvm.fmuladd.f64(double %10, double %10, double 1.000000e+00)
%14 = tail call i32 @sqrt(double %13)
%15 = sitofp i32 %14 to double
%16 = fadd double %15, -1.000000e+00
%17 = fdiv double %16, %10
%18 = fmul double %12, 2.000000e+00
%19 = fmul double %18, 6.000000e+00
%20 = fmul double %19, %17
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %11, double %20, double %17)
%23 = add nuw i32 %11, 1
%24 = icmp eq i32 %11, %0
br i1 %24, label %25, label %9
25: ; preds = %9, %1
%26 = phi double [ undef, %1 ], [ %20, %9 ]
ret double %26
}