#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 exp2f(double);
double log(double);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  unsigned int n = 12;
  double b = 2.0;
  double x = 0.5f;
  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 = tn + logtab[i];
      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 = un;
      en += en * vn;
    }
  }
  printf("true:%12.8f              %12.8f\n", x, exp2f(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)
movabs $0x3fe0000000000000,%rax
mov    %rax,-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  0xe5f(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe4e(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    120d <main+0xdd>
movsd  0xe2e(%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  0xe13(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11be <main+0x8e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xde3(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xdce(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
lea    0xdd2(%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    0xdec(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    1334 <main+0x204>
movsd  0xd88(%rip),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    128f <main+0x15f>
mov    -0x70(%rbp),%rax
movsd  -0x48(%rbp),%xmm0
mov    -0x3c(%rbp),%ecx
addsd  (%rax,%rcx,8),%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    0xd92(%rip),%rdi
mov    $0x4,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x64(%rbp)
jne    12f6 <main+0x1c6>
jmp    1321 <main+0x1f1>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    128a <main+0x15a>
jmp    1326 <main+0x1f6>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    126c <main+0x13c>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <exp2f@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
lea    0xd3c(%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)
movaps 0xee3(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
lea    0xf6e(%rip),%rdi
call   1030 <puts@plt>
lea    0xef8(%rip),%rdi
xorps  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0xec7(%rip),%xmm1
xorps  %xmm0,%xmm0
movaps %xmm1,%xmm2
mov    $0x3,%al
call   1040 <printf@plt>
movsd  0xeb2(%rip),%xmm0
mov    $0x1,%ebx
movsd  0xead(%rip),%xmm3
movsd  0xead(%rip),%xmm1
lea    0xede(%rip),%r14
movapd %xmm0,%xmm2
xchg   %ax,%ax
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x18(%rsp),%xmm1
movapd %xmm1,%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
movsd  %xmm1,0x18(%rsp)
movsd  %xmm2,0x10(%rsp)
movsd  %xmm3,0x28(%rsp)
mov    $0x4,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0xe56(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    1230 <main+0x110>
movsd  0x10(%rsp),%xmm2
jmp    12ac <main+0x18c>
nopl   0x0(%rax,%rax,1)
movsd  0x10(%rsp),%xmm2
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
movapd %xmm0,%xmm1
movapd %xmm2,%xmm0
mulsd  0x20(%rsp),%xmm0
addsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  0x28(%rsp),%xmm3
addsd  %xmm3,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
movsd  0x8(%rsp),%xmm0
movsd  %xmm1,0x18(%rsp)
movsd  0x10(%rsp),%xmm2
mov    $0x4,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm2
movsd  0xdca(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    1240 <main+0x120>
add    $0x1,%rbx
cmp    $0xc,%rbx
je     12c7 <main+0x1a7>
movsd  0x30(%rsp,%rbx,8),%xmm3
movsd  0x20(%rsp),%xmm0
jmp    11d0 <main+0xb0>
lea    0xdfb(%rip),%rdi
movsd  0xd9a(%rip),%xmm0
movsd  0xd9a(%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 = [33 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
store double 5.000000e-01, double* %4
%15 = load i32, i32* %2
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %5
%18 = alloca double, i64 %16
store i64 %16, i64* %6
%19 = load double, double* %3
%20 = call double @log(double %19)
%21 = fdiv double 1.000000e+00, %20
store double %21, double* %7
store double 1.000000e+00, double* %8
store i32 0, i32* %9
br label %22
22: ; preds = %37, %0
%23 = load i32, i32* %9
%24 = load i32, i32* %2
%25 = icmp ult i32 %23, %24
br i1 %25, label %26, label %40
26: ; preds = %22
%27 = load double, double* %8
%28 = fadd double 1.000000e+00, %27
%29 = call double @log(double %28)
%30 = load double, double* %7
%31 = fmul double %29, %30
%32 = load i32, i32* %9
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds double, double* %18, i64 %33
store double %31, double* %34
%35 = load double, double* %8
%36 = fmul double %35, 5.000000e-01
store double %36, double* %8
br label %37
37: ; preds = %26
%38 = load i32, i32* %9
%39 = add i32 %38, 1
store i32 %39, i32* %9
br label %22
40: ; preds = %22
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
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%42 = load double, double* %10
%43 = load double, double* %11
%44 = getelementptr inbounds double, double* %18, i64 0
%45 = load double, double* %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), double %42, double %43, double %45)
store i32 1, i32* %9
br label %47
47: ; preds = %85, %40
%48 = load i32, i32* %9
%49 = load i32, i32* %2
%50 = icmp ult i32 %48, %49
br i1 %50, label %51, label %88
51: ; preds = %47
%52 = load double, double* %13
%53 = fmul double %52, 5.000000e-01
store double %53, double* %13
br label %54
54: ; preds = %78, %51
br label %55
55: ; preds = %54
%56 = load double, double* %10
%57 = load i32, i32* %9
%58 = zext i32 %57 to i64
%59 = getelementptr inbounds double, double* %18, i64 %58
%60 = load double, double* %59
%61 = fadd double %56, %60
store double %61, double* %12
%62 = load double, double* %12
%63 = load double, double* %4
%64 = fcmp ole double %62, %63
%65 = zext i1 %64 to i32
store i32 %65, i32* %14
%66 = load i32, i32* %9
%67 = load double, double* %12
%68 = load double, double* %10
%69 = load double, double* %11
%70 = load i32, i32* %9
%71 = zext i32 %70 to i64
%72 = getelementptr inbounds double, double* %18, i64 %71
%73 = load double, double* %72
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %66, double %67, double %68, double %69, double %73)
%75 = load i32, i32* %14
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %55
br label %84
78: ; preds = %55
%79 = load double, double* %12
store double %79, double* %10
%80 = load double, double* %11
%81 = load double, double* %13
%82 = load double, double* %11
%83 = call double @llvm.fmuladd.f64(double %80, double %81, double %82)
store double %83, double* %11
br label %54
84: ; preds = %77
br label %85
85: ; preds = %84
%86 = load i32, i32* %9
%87 = add i32 %86, 1
store i32 %87, i32* %9
br label %47
88: ; preds = %47
%89 = load double, double* %4
%90 = load double, double* %4
%91 = call double @exp2f(double %90)
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), double %89, double %91)
store i32 0, i32* %1
%93 = load i8*, i8** %5
%94 = load i32, i32* %1
ret i32 %94
}

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 = [33 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 = fadd double %20, %16
%23 = fcmp ugt double %22, 5.000000e-01
%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 ], [ %19, %15 ]
%29 = tail call double @llvm.fmuladd.f64(double %28, double %21, double %28)
%30 = fadd double %27, %16
%31 = fcmp ugt double %30, 5.000000e-01
%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 %27, double %29, double %16)
br i1 %31, label %33, label %26
33: ; preds = %26, %15
%34 = phi double [ %20, %15 ], [ %27, %26 ]
%35 = phi double [ %19, %15 ], [ %29, %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 ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), double 5.000000e-01, double 0x3FF6A09E667F3BCD)
ret i32 0
}