#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 FP_NAN;
double fabs(double);
scalar_t__ isinf(double);
double log(double);
double bd0(double x, double np) {
  double ej, s, s1, v;
  int j;
  if (isinf(x) || isinf(np) || np == 0.0)
    return FP_NAN;
  if (fabs(x - np) < 0.1 * (x + np)) {
    v = (x - np) / (x + np);
    s = (x - np) * v;
    ej = 2 * x * v;
    v = v * v;
    for (j = 1;; j++) {
      ej *= v;
      s1 = s + ej / ((j << 1) + 1);
      if (s1 == s)
        return (s1);
      s = s1;
    }
  }
  return (x * log(x / np) + np - x);
}


x86 assembly (clang, -O0):
<bd0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <isinf@plt>
cmp    $0x0,%rax
jne    1172 <bd0+0x52>
movsd  -0x18(%rbp),%xmm0
call   1040 <isinf@plt>
cmp    $0x0,%rax
jne    1172 <bd0+0x52>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1187 <bd0+0x67>
jp     1187 <bd0+0x67>
mov    0x2e6f(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c2 <bd0+0x1a2>
movsd  -0x10(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movaps 0xe78(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm2
addsd  -0x18(%rbp),%xmm2
movsd  0xe52(%rip),%xmm0
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    128a <bd0+0x16a>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
addsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe13(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x3c(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    -0x3c(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jne    1272 <bd0+0x152>
jp     1272 <bd0+0x152>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c2 <bd0+0x1a2>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    121a <bd0+0xfa>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bd0>:
sub    $0x18,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1040 <isinf@plt>
test   %rax,%rax
je     114a <bd0+0x2a>
mov    0x2ea7(%rip),%rax
movsd  (%rax),%xmm0
add    $0x18,%rsp
ret
movsd  0x8(%rsp),%xmm0
call   1040 <isinf@plt>
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    1167 <bd0+0x47>
jnp    113a <bd0+0x1a>
test   %rax,%rax
jne    113a <bd0+0x1a>
movsd  0x10(%rsp),%xmm4
movapd %xmm4,%xmm1
movsd  0x8(%rsp),%xmm5
subsd  %xmm5,%xmm1
movapd 0xe78(%rip),%xmm2
andpd  %xmm1,%xmm2
movapd %xmm4,%xmm0
addsd  %xmm5,%xmm0
movsd  0xe74(%rip),%xmm3
mulsd  %xmm0,%xmm3
ucomisd %xmm2,%xmm3
jbe    11fb <bd0+0xdb>
movapd %xmm1,%xmm2
divsd  %xmm0,%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm4,%xmm4
mulsd  %xmm2,%xmm4
mulsd  %xmm2,%xmm2
mov    $0x3,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mulsd  %xmm2,%xmm4
xorps  %xmm3,%xmm3
cvtsi2sd %eax,%xmm3
movapd %xmm4,%xmm0
divsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
add    $0x2,%eax
ucomisd %xmm1,%xmm0
movapd %xmm0,%xmm1
jne    11d0 <bd0+0xb0>
jp     11d0 <bd0+0xb0>
add    $0x18,%rsp
ret
movapd %xmm4,%xmm0
divsd  %xmm5,%xmm0
call   1030 <log@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm0
addsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@FP_NAN = global double 0.000000e+00
define double @bd0(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
store double %0, double* %4
store double %1, double* %5
%11 = load double, double* %4
%12 = call i64 @isinf(double %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %2
%15 = load double, double* %5
%16 = call i64 @isinf(double %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load double, double* %5
%20 = fcmp oeq double %19, 0.000000e+00
br i1 %20, label %21, label %23
21: ; preds = %18, %14, %2
%22 = load double, double* @FP_NAN
store double %22, double* %3
br label %85
23: ; preds = %18
%24 = load double, double* %4
%25 = load double, double* %5
%26 = fsub double %24, %25
%27 = call double @llvm.fabs.f64(double %26)
%28 = load double, double* %4
%29 = load double, double* %5
%30 = fadd double %28, %29
%31 = fmul double 1.000000e-01, %30
%32 = fcmp olt double %27, %31
br i1 %32, label %33, label %75
33: ; preds = %23
%34 = load double, double* %4
%35 = load double, double* %5
%36 = fsub double %34, %35
%37 = load double, double* %4
%38 = load double, double* %5
%39 = fadd double %37, %38
%40 = fdiv double %36, %39
store double %40, double* %9
%41 = load double, double* %4
%42 = load double, double* %5
%43 = fsub double %41, %42
%44 = load double, double* %9
%45 = fmul double %43, %44
store double %45, double* %7
%46 = load double, double* %4
%47 = fmul double 2.000000e+00, %46
%48 = load double, double* %9
%49 = fmul double %47, %48
store double %49, double* %6
%50 = load double, double* %9
%51 = load double, double* %9
%52 = fmul double %50, %51
store double %52, double* %9
store i32 1, i32* %10
br label %53
53: ; preds = %72, %33
%54 = load double, double* %9
%55 = load double, double* %6
%56 = fmul double %55, %54
store double %56, double* %6
%57 = load double, double* %7
%58 = load double, double* %6
%59 = load i32, i32* %10
%60 = shl i32 %59, 1
%61 = add nsw i32 %60, 1
%62 = sitofp i32 %61 to double
%63 = fdiv double %58, %62
%64 = fadd double %57, %63
store double %64, double* %8
%65 = load double, double* %8
%66 = load double, double* %7
%67 = fcmp oeq double %65, %66
br i1 %67, label %68, label %70
68: ; preds = %53
%69 = load double, double* %8
store double %69, double* %3
br label %85
70: ; preds = %53
%71 = load double, double* %8
store double %71, double* %7
br label %72
72: ; preds = %70
%73 = load i32, i32* %10
%74 = add nsw i32 %73, 1
store i32 %74, i32* %10
br label %53
75: ; preds = %23
%76 = load double, double* %4
%77 = load double, double* %4
%78 = load double, double* %5
%79 = fdiv double %77, %78
%80 = call double @log(double %79)
%81 = load double, double* %5
%82 = call double @llvm.fmuladd.f64(double %76, double %80, double %81)
%83 = load double, double* %4
%84 = fsub double %82, %83
store double %84, double* %3
br label %85
85: ; preds = %75, %68, %21
%86 = load double, double* %3
ret double %86
}

LLVM IR (-O2):
@FP_NAN = global double 0.000000e+00
define double @bd0(double %0, double %1) {
%3 = tail call i64 @isinf(double %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = tail call i64 @isinf(double %1)
%7 = icmp ne i64 %6, 0
%8 = fcmp oeq double %1, 0.000000e+00
%9 = or i1 %8, %7
br i1 %9, label %10, label %12
10: ; preds = %5, %2
%11 = load double, double* @FP_NAN
br label %41
12: ; preds = %5
%13 = fsub double %0, %1
%14 = tail call double @llvm.fabs.f64(double %13)
%15 = fadd double %0, %1
%16 = fmul double %15, 1.000000e-01
%17 = fcmp olt double %14, %16
br i1 %17, label %18, label %36
18: ; preds = %12
%19 = fdiv double %13, %15
%20 = fmul double %13, %19
%21 = fmul double %0, 2.000000e+00
%22 = fmul double %21, %19
%23 = fmul double %19, %19
br label %24
24: ; preds = %24, %18
%25 = phi double [ %22, %18 ], [ %28, %24 ]
%26 = phi double [ %20, %18 ], [ %33, %24 ]
%27 = phi i32 [ 1, %18 ], [ %35, %24 ]
%28 = fmul double %23, %25
%29 = shl nuw i32 %27, 1
%30 = or i32 %29, 1
%31 = sitofp i32 %30 to double
%32 = fdiv double %28, %31
%33 = fadd double %26, %32
%34 = fcmp oeq double %33, %26
%35 = add nuw nsw i32 %27, 1
br i1 %34, label %41, label %24
36: ; preds = %12
%37 = fdiv double %0, %1
%38 = tail call double @log(double %37)
%39 = tail call double @llvm.fmuladd.f64(double %0, double %38, double %1)
%40 = fsub double %39, %0
br label %41
41: ; preds = %24, %36, %10
%42 = phi double [ %11, %10 ], [ %40, %36 ], [ %33, %24 ]
ret double %42
}