#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 INFINITY;
double NAN;
scalar_t__ isinf(double);
scalar_t__ isnan(double);
double logex(double, unsigned int);
double logax(double num, double base, unsigned int sigdig) {
  if (num <= 0 || base < 0 || base == 1) {
    return NAN;
  }
  if (base == 0) {
    return INFINITY;
  }
  if (isnan(num) || isinf(num)) {
    return num;
  }
  double log1 = logex(num, sigdig);
  double log2 = logex(base, sigdig);
  return log1 / log2;
}


x86 assembly (clang, -O0):
<logax>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jae    117e <logax+0x4e>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
ja     117e <logax+0x4e>
movsd  -0x18(%rbp),%xmm0
movsd  0xe92(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1193 <logax+0x63>
jp     1193 <logax+0x63>
mov    0x2e73(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122a <logax+0xfa>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11c0 <logax+0x90>
jp     11c0 <logax+0x90>
mov    0x2e2e(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122a <logax+0xfa>
movsd  -0x10(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
jne    11e8 <logax+0xb8>
movsd  -0x10(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     11f7 <logax+0xc7>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122a <logax+0xfa>
movsd  -0x10(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
call   1040 <logex@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
call   1040 <logex@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logax>:
push   %rbx
sub    $0x10,%rsp
ucomisd 0xec3(%rip),%xmm1
jne    1141 <logax+0x11>
jnp    1166 <logax+0x36>
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm2
jae    1166 <logax+0x36>
ucomisd %xmm1,%xmm2
ja     1166 <logax+0x36>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    117b <logax+0x4b>
jp     117b <logax+0x4b>
mov    0x2e7c(%rip),%rax
jmp    116d <logax+0x3d>
mov    0x2e8b(%rip),%rax
movsd  (%rax),%xmm1
movapd %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret
mov    %edi,%ebx
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
call   1030 <isnan@plt>
test   %rax,%rax
jne    11a1 <logax+0x71>
movsd  (%rsp),%xmm0
call   1050 <isinf@plt>
test   %rax,%rax
je     11a8 <logax+0x78>
movsd  (%rsp),%xmm1
jmp    1171 <logax+0x41>
movsd  (%rsp),%xmm0
mov    %ebx,%edi
call   1040 <logex@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
mov    %ebx,%edi
call   1040 <logex@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
jmp    1171 <logax+0x41>

LLVM IR (-O0):
@NAN = global double 0.000000e+00
@INFINITY = global double 0.000000e+00
define double @logax(double %0, double %1, i32 %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca double
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
%10 = load double, double* %5
%11 = fcmp ole double %10, 0.000000e+00
br i1 %11, label %18, label %12
12: ; preds = %3
%13 = load double, double* %6
%14 = fcmp olt double %13, 0.000000e+00
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load double, double* %6
%17 = fcmp oeq double %16, 1.000000e+00
br i1 %17, label %18, label %20
18: ; preds = %15, %12, %3
%19 = load double, double* @NAN
store double %19, double* %4
br label %45
20: ; preds = %15
%21 = load double, double* %6
%22 = fcmp oeq double %21, 0.000000e+00
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = load double, double* @INFINITY
store double %24, double* %4
br label %45
25: ; preds = %20
%26 = load double, double* %5
%27 = call i64 @isnan(double %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = load double, double* %5
%31 = call i64 @isinf(double %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29, %25
%34 = load double, double* %5
store double %34, double* %4
br label %45
35: ; preds = %29
%36 = load double, double* %5
%37 = load i32, i32* %7
%38 = call double @logex(double %36, i32 %37)
store double %38, double* %8
%39 = load double, double* %6
%40 = load i32, i32* %7
%41 = call double @logex(double %39, i32 %40)
store double %41, double* %9
%42 = load double, double* %8
%43 = load double, double* %9
%44 = fdiv double %42, %43
store double %44, double* %4
br label %45
45: ; preds = %35, %33, %23, %18
%46 = load double, double* %4
ret double %46
}

LLVM IR (-O2):
@NAN = global double 0.000000e+00
@INFINITY = global double 0.000000e+00
define double @logax(double %0, double %1, i32 %2) {
%4 = fcmp ole double %0, 0.000000e+00
%5 = fcmp olt double %1, 0.000000e+00
%6 = or i1 %4, %5
%7 = fcmp oeq double %1, 1.000000e+00
%8 = or i1 %7, %6
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = load double, double* @NAN
br label %25
11: ; preds = %3
%12 = fcmp oeq double %1, 0.000000e+00
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = load double, double* @INFINITY
br label %25
15: ; preds = %11
%16 = tail call i64 @isnan(double %0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = tail call i64 @isinf(double %0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = tail call double @logex(double %0, i32 %2)
%23 = tail call double @logex(double %1, i32 %2)
%24 = fdiv double %22, %23
br label %25
25: ; preds = %15, %18, %21, %13, %9
%26 = phi double [ %10, %9 ], [ %14, %13 ], [ %24, %21 ], [ %0, %18 ], [ %0, %15 ]
ret double %26
}