#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 log(double);
double log2f(double);
int /*<<< orphan*/ printf(char *, ...);
double sqrt(double);
int main() {
  unsigned int n = 12;
  double b = 2.0;
  double x = sqrt(2.0);
  double logtab[n];
  double inv_log_b = 1.0 / log(b);
  double inv_2_n = 1.0;
  unsigned int i;
  for (i = 0; i < n; i++) {
    logtab[i] = log(1.0 + inv_2_n) * inv_log_b;
    inv_2_n *= 0.5;
  }
  double tn = 0.0;
  double en = 1.0;
  double un = 0.0;
  double vn = 1.0;
  int dn;
  printf("   n           un           tn           en           An\n");
  printf("init            - %12.8f %12.8f %12.8f\n", tn, en, logtab[0]);
  for (i = 1; i < n; i++) {
    vn *= 0.5;
    while (1) {
      un = en + en * vn;
      dn = (un <= x);
      printf("%4u %12.8f %12.8f %12.8f %12.8f\n", i, un, tn, en, logtab[i]);
      if (dn == 0)
        break;
      tn += logtab[i];
      en = un;
    }
  }
  printf("true:%12.8f %12.8f\n", x, log2f(x));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xc,-0x8(%rbp)
movabs $0x4000000000000000,%rax
mov    %rax,-0x10(%rbp)
movsd  0xe99(%rip),%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe4b(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe3a(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    1221 <main+0xe1>
movsd  0xe1a(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
call   1050 <log@plt>
mov    -0x70(%rbp),%rax
mulsd  -0x30(%rbp),%xmm0
mov    -0x3c(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
movsd  0xe07(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d2 <main+0x92>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xdcf(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xdba(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x70(%rbp),%rax
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
movsd  (%rax),%xmm2
lea    0xde0(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    134c <main+0x20c>
movsd  0xd7c(%rip),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    12a3 <main+0x163>
mov    -0x70(%rbp),%rax
movsd  -0x50(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
setae  %cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x64(%rbp)
mov    -0x3c(%rbp),%esi
movsd  -0x58(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
mov    -0x3c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm3
lea    0xd7c(%rip),%rdi
mov    $0x4,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x64(%rbp)
jne    1314 <main+0x1d4>
jmp    1339 <main+0x1f9>
mov    -0x70(%rbp),%rax
mov    -0x3c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    129e <main+0x15e>
jmp    133e <main+0x1fe>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1280 <main+0x140>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <log2f@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
lea    0xd2c(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x98,%rsp
movaps 0xecf(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xed3(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xed7(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xedb(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xedf(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movapd 0xee2(%rip),%xmm0
movapd %xmm0,0x80(%rsp)
lea    0xf67(%rip),%rdi
call   1030 <puts@plt>
lea    0xefe(%rip),%rdi
movsd  0xece(%rip),%xmm1
xorpd  %xmm0,%xmm0
movaps %xmm1,%xmm2
mov    $0x3,%al
call   1040 <printf@plt>
movsd  0xeb8(%rip),%xmm5
xorps  %xmm1,%xmm1
mov    $0x1,%ebx
movsd  0xeb0(%rip),%xmm3
lea    0xef1(%rip),%r14
movapd %xmm5,%xmm2
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mulsd  0xe98(%rip),%xmm5
movapd %xmm2,%xmm0
movsd  %xmm5,0x18(%rsp)
mulsd  %xmm5,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
movsd  %xmm1,0x8(%rsp)
movsd  %xmm2,0x20(%rsp)
movsd  %xmm3,0x28(%rsp)
mov    $0x4,%al
call   1040 <printf@plt>
movsd  0x10(%rsp),%xmm4
movsd  0xe5c(%rip),%xmm0
ucomisd %xmm4,%xmm0
jae    1230 <main+0x110>
movsd  0x8(%rsp),%xmm1
movsd  0x18(%rsp),%xmm5
jmp    12a0 <main+0x180>
movsd  0x8(%rsp),%xmm1
movsd  0x18(%rsp),%xmm5
nopl   0x0(%rax)
movapd %xmm4,%xmm2
movsd  0x28(%rsp),%xmm3
addsd  %xmm3,%xmm1
movsd  %xmm1,0x8(%rsp)
mulsd  %xmm5,%xmm4
addsd  %xmm2,%xmm4
movsd  %xmm4,0x10(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
movapd %xmm4,%xmm0
movsd  0x8(%rsp),%xmm1
movsd  %xmm2,0x20(%rsp)
mov    $0x4,%al
call   1040 <printf@plt>
movsd  0x18(%rsp),%xmm5
movsd  0x8(%rsp),%xmm1
movsd  0xde6(%rip),%xmm2
ucomisd 0x10(%rsp),%xmm2
movsd  0x10(%rsp),%xmm4
jae    1240 <main+0x120>
movsd  0x20(%rsp),%xmm2
add    $0x1,%rbx
cmp    $0xc,%rbx
je     12bb <main+0x19b>
movsd  0x30(%rsp,%rbx,8),%xmm3
jmp    11d0 <main+0xb0>
lea    0xe0f(%rip),%rdi
movsd  0xdae(%rip),%xmm0
movsd  0xdae(%rip),%xmm1
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [58 x i8] c" n un tn en An\0A\00"
@.str.1 = [40 x i8] c"init - %12.8f %12.8f %12.8f\0A\00"
@.str.2 = [33 x i8] c"%4u %12.8f %12.8f %12.8f %12.8f\0A\00"
@.str.3 = [20 x i8] c"true:%12.8f %12.8f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca i8*
%6 = alloca i64
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
store i32 0, i32* %1
store i32 12, i32* %2
store double 2.000000e+00, double* %3
%15 = call double @sqrt(double 2.000000e+00)
store double %15, double* %4
%16 = load i32, i32* %2
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %5
%19 = alloca double, i64 %17
store i64 %17, i64* %6
%20 = load double, double* %3
%21 = call double @log(double %20)
%22 = fdiv double 1.000000e+00, %21
store double %22, double* %7
store double 1.000000e+00, double* %8
store i32 0, i32* %9
br label %23
23: ; preds = %38, %0
%24 = load i32, i32* %9
%25 = load i32, i32* %2
%26 = icmp ult i32 %24, %25
br i1 %26, label %27, label %41
27: ; preds = %23
%28 = load double, double* %8
%29 = fadd double 1.000000e+00, %28
%30 = call double @log(double %29)
%31 = load double, double* %7
%32 = fmul double %30, %31
%33 = load i32, i32* %9
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds double, double* %19, i64 %34
store double %32, double* %35
%36 = load double, double* %8
%37 = fmul double %36, 5.000000e-01
store double %37, double* %8
br label %38
38: ; preds = %27
%39 = load i32, i32* %9
%40 = add i32 %39, 1
store i32 %40, i32* %9
br label %23
41: ; preds = %23
store double 0.000000e+00, double* %10
store double 1.000000e+00, double* %11
store double 0.000000e+00, double* %12
store double 1.000000e+00, double* %13
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%43 = load double, double* %10
%44 = load double, double* %11
%45 = getelementptr inbounds double, double* %19, i64 0
%46 = load double, double* %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), double %43, double %44, double %46)
store i32 1, i32* %9
br label %48
48: ; preds = %86, %41
%49 = load i32, i32* %9
%50 = load i32, i32* %2
%51 = icmp ult i32 %49, %50
br i1 %51, label %52, label %89
52: ; preds = %48
%53 = load double, double* %13
%54 = fmul double %53, 5.000000e-01
store double %54, double* %13
br label %55
55: ; preds = %77, %52
br label %56
56: ; preds = %55
%57 = load double, double* %11
%58 = load double, double* %11
%59 = load double, double* %13
%60 = call double @llvm.fmuladd.f64(double %58, double %59, double %57)
store double %60, double* %12
%61 = load double, double* %12
%62 = load double, double* %4
%63 = fcmp ole double %61, %62
%64 = zext i1 %63 to i32
store i32 %64, i32* %14
%65 = load i32, i32* %9
%66 = load double, double* %12
%67 = load double, double* %10
%68 = load double, double* %11
%69 = load i32, i32* %9
%70 = zext i32 %69 to i64
%71 = getelementptr inbounds double, double* %19, i64 %70
%72 = load double, double* %71
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %65, double %66, double %67, double %68, double %72)
%74 = load i32, i32* %14
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %77
76: ; preds = %56
br label %85
77: ; preds = %56
%78 = load i32, i32* %9
%79 = zext i32 %78 to i64
%80 = getelementptr inbounds double, double* %19, i64 %79
%81 = load double, double* %80
%82 = load double, double* %10
%83 = fadd double %82, %81
store double %83, double* %10
%84 = load double, double* %12
store double %84, double* %11
br label %55
85: ; preds = %76
br label %86
86: ; preds = %85
%87 = load i32, i32* %9
%88 = add i32 %87, 1
store i32 %88, i32* %9
br label %48
89: ; preds = %48
%90 = load double, double* %4
%91 = load double, double* %4
%92 = call double @log2f(double %91)
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), double %90, double %92)
store i32 0, i32* %1
%94 = load i8*, i8** %5
%95 = load i32, i32* %1
ret i32 %95
}

LLVM IR (-O2):
@.str.1 = [40 x i8] c"init - %12.8f %12.8f %12.8f\0A\00"
@.str.2 = [33 x i8] c"%4u %12.8f %12.8f %12.8f %12.8f\0A\00"
@.str.3 = [20 x i8] c"true:%12.8f %12.8f\0A\00"
@str = [57 x i8] c" n un tn en An\00"
define i32 @main() {
%1 = alloca [12 x double]
%2 = bitcast [12 x double]* %1 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 0x3FE2B803473F7AD1>, <2 x double>* %2
%3 = getelementptr inbounds [12 x double], [12 x double]* %1, i64 0, i64 2
%4 = bitcast double* %3 to <2 x double>*
store <2 x double> <double 0x3FD49A784BCD1B8B, double 0x3FC5C01A39FBD688>, <2 x double>* %4
%5 = getelementptr inbounds [12 x double], [12 x double]* %1, i64 0, i64 4
%6 = bitcast double* %5 to <2 x double>*
store <2 x double> <double 0x3FB663F6FAC91316, double 0x3FA6BAD3758EFD87>, <2 x double>* %6
%7 = getelementptr inbounds [12 x double], [12 x double]* %1, i64 0, i64 6
%8 = bitcast double* %7 to <2 x double>*
store <2 x double> <double 0x3F96E79685C2D22A, double 0x3F86FE50B6EF0851>, <2 x double>* %8
%9 = getelementptr inbounds [12 x double], [12 x double]* %1, i64 0, i64 8
%10 = bitcast double* %9 to <2 x double>*
store <2 x double> <double 0x3F7709C46D7AAC77, double 0x3F670F83FF0A7564>, <2 x double>* %10
%11 = getelementptr inbounds [12 x double], [12 x double]* %1, i64 0, i64 10
%12 = bitcast double* %11 to <2 x double>*
store <2 x double> <double 0x3F5712653743F454, double 0x3F4713D62F7957C3>, <2 x double>* %12
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), double 0.000000e+00, double 1.000000e+00, double 1.000000e+00)
br label %15
15: ; preds = %38, %0
%16 = phi double [ 0x3FE2B803473F7AD1, %0 ], [ %40, %38 ]
%17 = phi i64 [ 1, %0 ], [ %36, %38 ]
%18 = phi double [ 1.000000e+00, %0 ], [ %21, %38 ]
%19 = phi double [ 1.000000e+00, %0 ], [ %35, %38 ]
%20 = phi double [ 0.000000e+00, %0 ], [ %34, %38 ]
%21 = fmul double %18, 5.000000e-01
%22 = tail call double @llvm.fmuladd.f64(double %19, double %21, double %19)
%23 = fcmp ugt double %22, 0x3FF6A09E667F3BCD
%24 = trunc i64 %17 to i32
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %24, double %22, double %20, double %19, double %16)
br i1 %23, label %33, label %26
26: ; preds = %15, %26
%27 = phi double [ %30, %26 ], [ %22, %15 ]
%28 = phi double [ %29, %26 ], [ %20, %15 ]
%29 = fadd double %28, %16
%30 = tail call double @llvm.fmuladd.f64(double %27, double %21, double %27)
%31 = fcmp ugt double %30, 0x3FF6A09E667F3BCD
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %24, double %30, double %29, double %27, double %16)
br i1 %31, label %33, label %26
33: ; preds = %26, %15
%34 = phi double [ %20, %15 ], [ %29, %26 ]
%35 = phi double [ %19, %15 ], [ %27, %26 ]
%36 = add nuw nsw i64 %17, 1
%37 = icmp eq i64 %36, 12
br i1 %37, label %41, label %38
38: ; preds = %33
%39 = getelementptr inbounds [12 x double], [12 x double]* %1, i64 0, i64 %36
%40 = load double, double* %39
br label %15
41: ; preds = %33
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), double 0x3FF6A09E667F3BCD, double 0x3FE0000000000001)
ret i32 0
}