#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 */
float log2l(long double);
float subtractLongDouble(long double *ap, long double b) {
  long double a = *ap;
  float precisionLost;
  long double value;
  if (b >= a) {
    *ap = 0;
    return 100;
  }
  value = -b / a + 1.0;
  precisionLost = (float)-1 * log2l(value);
  *ap = a - b;
  return precisionLost;
}


x86 assembly (clang, -O0):
<subtractLongDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
fldt   0x10(%rbp)
mov    %rdi,-0x10(%rbp)
fstpt  -0x20(%rbp)
mov    -0x10(%rbp),%rax
fldt   (%rax)
fstpt  -0x30(%rbp)
fldt   -0x20(%rbp)
fldt   -0x30(%rbp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jb     115c <subtractLongDouble+0x4c>
jmp    1142 <subtractLongDouble+0x32>
mov    -0x10(%rbp),%rax
fldz
fstpt  (%rax)
movss  0xebe(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11a0 <subtractLongDouble+0x90>
fldt   -0x20(%rbp)
fldt   -0x30(%rbp)
fdivrp %st,%st(1)
fld1
fsubp  %st,%st(1)
fstpt  -0x50(%rbp)
fldt   -0x50(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <log2l@plt>
movaps 0xe81(%rip),%xmm1
pxor   %xmm1,%xmm0
movss  %xmm0,-0x34(%rbp)
fldt   -0x30(%rbp)
fldt   -0x20(%rbp)
fsubrp %st,%st(1)
mov    -0x10(%rbp),%rax
fstpt  (%rax)
movss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<subtractLongDouble>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
fldt   0x40(%rsp)
fldt   (%rdi)
fldz
fxch   %st(2)
fucomi %st(1),%st
jae    1157 <subtractLongDouble+0x47>
fstp   %st(2)
fld    %st(1)
fdiv   %st(1),%st
fxch   %st(2)
fstpt  0x24(%rsp)
fld1
fsubp  %st,%st(2)
fxch   %st(1)
fstpt  (%rsp)
fstpt  0x18(%rsp)
call   1030 <log2l@plt>
xorps  0xec5(%rip),%xmm0
fldt   0x24(%rsp)
fldt   0x18(%rsp)
fsubp  %st,%st(1)
jmp    1163 <subtractLongDouble+0x53>
fstp   %st(0)
fstp   %st(0)
movss  0xe9d(%rip),%xmm0
fstpt  (%rbx)
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define float @subtractLongDouble(x86_fp80* %0, x86_fp80 %1) {
%3 = alloca float
%4 = alloca x86_fp80*
%5 = alloca x86_fp80
%6 = alloca x86_fp80
%7 = alloca float
%8 = alloca x86_fp80
store x86_fp80* %0, x86_fp80** %4
store x86_fp80 %1, x86_fp80* %5
%9 = load x86_fp80*, x86_fp80** %4
%10 = load x86_fp80, x86_fp80* %9
store x86_fp80 %10, x86_fp80* %6
%11 = load x86_fp80, x86_fp80* %5
%12 = load x86_fp80, x86_fp80* %6
%13 = fcmp oge x86_fp80 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load x86_fp80*, x86_fp80** %4
store x86_fp80 0xK00000000000000000000, x86_fp80* %15
store float 1.000000e+02, float* %3
br label %30
16: ; preds = %2
%17 = load x86_fp80, x86_fp80* %5
%18 = fneg x86_fp80 %17
%19 = load x86_fp80, x86_fp80* %6
%20 = fdiv x86_fp80 %18, %19
%21 = fadd x86_fp80 %20, 0xK3FFF8000000000000000
store x86_fp80 %21, x86_fp80* %8
%22 = load x86_fp80, x86_fp80* %8
%23 = call float @log2l(x86_fp80 %22)
%24 = fmul float -1.000000e+00, %23
store float %24, float* %7
%25 = load x86_fp80, x86_fp80* %6
%26 = load x86_fp80, x86_fp80* %5
%27 = fsub x86_fp80 %25, %26
%28 = load x86_fp80*, x86_fp80** %4
store x86_fp80 %27, x86_fp80* %28
%29 = load float, float* %7
store float %29, float* %3
br label %30
30: ; preds = %16, %14
%31 = load float, float* %3
ret float %31
}

LLVM IR (-O2):
define float @subtractLongDouble(x86_fp80* nocapture %0, x86_fp80 %1) {
%3 = load x86_fp80, x86_fp80* %0
%4 = fcmp ugt x86_fp80 %3, %1
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = fdiv x86_fp80 %1, %3
%7 = fsub x86_fp80 0xK3FFF8000000000000000, %6
%8 = tail call float @log2l(x86_fp80 %7)
%9 = fneg float %8
%10 = fsub x86_fp80 %3, %1
br label %11
11: ; preds = %2, %5
%12 = phi x86_fp80 [ %10, %5 ], [ 0xK00000000000000000000, %2 ]
%13 = phi float [ %9, %5 ], [ 1.000000e+02, %2 ]
store x86_fp80 %12, x86_fp80* %0
ret float %13
}