#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 */
unsigned int log(int);
double logdual(long double x) {
  unsigned exp = 0;
  while (x >= 18446744073709551616.)
    x /= 18446744073709551616., exp += 64;
  while (x >= 256.)
    x /= 256., exp += 8;
  while (x >= 2.)
    x /= 2., exp += 1;
  return exp + log(x) / log(2);
}


x86 assembly (clang, -O0):
<logdual>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
movl   $0x0,-0x14(%rbp)
fldt   -0x10(%rbp)
flds   0xed2(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jb     115b <logdual+0x4b>
jmp    113f <logdual+0x2f>
fldt   -0x10(%rbp)
flds   0xeb8(%rip)
fdivrp %st,%st(1)
fstpt  -0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x40,%eax
mov    %eax,-0x14(%rbp)
jmp    1125 <logdual+0x15>
jmp    1160 <logdual+0x50>
fldt   -0x10(%rbp)
flds   0xe9b(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jb     1196 <logdual+0x86>
jmp    117a <logdual+0x6a>
fldt   -0x10(%rbp)
flds   0xe81(%rip)
fdivrp %st,%st(1)
fstpt  -0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x14(%rbp)
jmp    1160 <logdual+0x50>
jmp    119b <logdual+0x8b>
fldt   -0x10(%rbp)
flds   0xe64(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jb     11d1 <logdual+0xc1>
jmp    11b5 <logdual+0xa5>
fldt   -0x10(%rbp)
flds   0xe4a(%rip)
fdivrp %st,%st(1)
fstpt  -0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119b <logdual+0x8b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
fldt   -0x10(%rbp)
fnstcw -0x1a(%rbp)
movzwl -0x1a(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x1c(%rbp)
fldcw  -0x1c(%rbp)
fistpl -0x18(%rbp)
fldcw  -0x1a(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <log@plt>
mov    %eax,-0x24(%rbp)
mov    $0x2,%edi
call   1030 <log@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
cvtsi2sd %rax,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logdual>:
push   %rbp
push   %rbx
push   %rax
fldt   0x20(%rsp)
xor    %ebp,%ebp
flds   0xee1(%rip)
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
jae    112b <logdual+0x1b>
fldz
jmp    1151 <logdual+0x41>
xor    %ebp,%ebp
flds   0xecd(%rip)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
fxch   %st(1)
fmuls  0xebc(%rip)
add    $0x40,%ebp
fucomi %st(1),%st
fxch   %st(1)
jae    1140 <logdual+0x30>
fstp   %st(0)
flds   0xeaf(%rip)
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
jae    1165 <logdual+0x55>
fldz
jmp    1181 <logdual+0x71>
flds   0xe9d(%rip)
nopl   0x0(%rax,%rax,1)
fxch   %st(1)
fmuls  0xe94(%rip)
add    $0x8,%ebp
fucomi %st(1),%st
fxch   %st(1)
jae    1170 <logdual+0x60>
fstp   %st(0)
flds   0xe87(%rip)
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
jae    1195 <logdual+0x85>
fldz
jmp    11b1 <logdual+0xa1>
flds   0xe75(%rip)
nopl   0x0(%rax,%rax,1)
fxch   %st(1)
fmuls  0xe6c(%rip)
add    $0x1,%ebp
fucomi %st(1),%st
fxch   %st(1)
jae    11a0 <logdual+0x90>
fstp   %st(0)
fnstcw (%rsp)
movzwl (%rsp),%eax
or     $0xc00,%eax
mov    %ax,0x2(%rsp)
fldcw  0x2(%rsp)
fistpl 0x4(%rsp)
fldcw  (%rsp)
mov    0x4(%rsp),%edi
call   1030 <log@plt>
mov    %eax,%ebx
mov    $0x2,%edi
call   1030 <log@plt>
mov    %eax,%ecx
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
add    %ebp,%eax
cvtsi2sd %rax,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @logdual(x86_fp80 %0) {
%2 = alloca x86_fp80
%3 = alloca i32
store x86_fp80 %0, x86_fp80* %2
store i32 0, i32* %3
br label %4
4: ; preds = %7, %1
%5 = load x86_fp80, x86_fp80* %2
%6 = fcmp oge x86_fp80 %5, 0xK403F8000000000000000
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = load x86_fp80, x86_fp80* %2
%9 = fdiv x86_fp80 %8, 0xK403F8000000000000000
store x86_fp80 %9, x86_fp80* %2
%10 = load i32, i32* %3
%11 = add i32 %10, 64
store i32 %11, i32* %3
br label %4
12: ; preds = %4
br label %13
13: ; preds = %16, %12
%14 = load x86_fp80, x86_fp80* %2
%15 = fcmp oge x86_fp80 %14, 0xK40078000000000000000
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load x86_fp80, x86_fp80* %2
%18 = fdiv x86_fp80 %17, 0xK40078000000000000000
store x86_fp80 %18, x86_fp80* %2
%19 = load i32, i32* %3
%20 = add i32 %19, 8
store i32 %20, i32* %3
br label %13
21: ; preds = %13
br label %22
22: ; preds = %25, %21
%23 = load x86_fp80, x86_fp80* %2
%24 = fcmp oge x86_fp80 %23, 0xK40008000000000000000
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load x86_fp80, x86_fp80* %2
%27 = fdiv x86_fp80 %26, 0xK40008000000000000000
store x86_fp80 %27, x86_fp80* %2
%28 = load i32, i32* %3
%29 = add i32 %28, 1
store i32 %29, i32* %3
br label %22
30: ; preds = %22
%31 = load i32, i32* %3
%32 = load x86_fp80, x86_fp80* %2
%33 = fptosi x86_fp80 %32 to i32
%34 = call i32 @log(i32 %33)
%35 = call i32 @log(i32 2)
%36 = udiv i32 %34, %35
%37 = add i32 %31, %36
%38 = uitofp i32 %37 to double
ret double %38
}

LLVM IR (-O2):
define double @logdual(x86_fp80 %0) {
%2 = fcmp ult x86_fp80 %0, 0xK403F8000000000000000
br i1 %2, label %3, label %7
3: ; preds = %7, %1
%4 = phi x86_fp80 [ %0, %1 ], [ %10, %7 ]
%5 = phi i32 [ 0, %1 ], [ %11, %7 ]
%6 = fcmp ult x86_fp80 %4, 0xK40078000000000000000
br i1 %6, label %13, label %17
7: ; preds = %1, %7
%8 = phi i32 [ %11, %7 ], [ 0, %1 ]
%9 = phi x86_fp80 [ %10, %7 ], [ %0, %1 ]
%10 = fmul x86_fp80 %9, 0xK3FBF8000000000000000
%11 = add i32 %8, 64
%12 = fcmp ult x86_fp80 %10, 0xK403F8000000000000000
br i1 %12, label %3, label %7
13: ; preds = %17, %3
%14 = phi x86_fp80 [ %4, %3 ], [ %20, %17 ]
%15 = phi i32 [ %5, %3 ], [ %21, %17 ]
%16 = fcmp ult x86_fp80 %14, 0xK40008000000000000000
br i1 %16, label %29, label %23
17: ; preds = %3, %17
%18 = phi i32 [ %21, %17 ], [ %5, %3 ]
%19 = phi x86_fp80 [ %20, %17 ], [ %4, %3 ]
%20 = fmul x86_fp80 %19, 0xK3FF78000000000000000
%21 = add i32 %18, 8
%22 = fcmp ult x86_fp80 %20, 0xK40078000000000000000
br i1 %22, label %13, label %17
23: ; preds = %13, %23
%24 = phi i32 [ %27, %23 ], [ %15, %13 ]
%25 = phi x86_fp80 [ %26, %23 ], [ %14, %13 ]
%26 = fmul x86_fp80 %25, 0xK3FFE8000000000000000
%27 = add i32 %24, 1
%28 = fcmp ult x86_fp80 %26, 0xK40008000000000000000
br i1 %28, label %29, label %23
29: ; preds = %23, %13
%30 = phi x86_fp80 [ %14, %13 ], [ %26, %23 ]
%31 = phi i32 [ %15, %13 ], [ %27, %23 ]
%32 = fptosi x86_fp80 %30 to i32
%33 = tail call i32 @log(i32 %32)
%34 = tail call i32 @log(i32 2)
%35 = udiv i32 %33, %34
%36 = add i32 %35, %31
%37 = uitofp i32 %36 to double
ret double %37
}