#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 log10(double);
double trio_nan();
double trio_ninf();
double TrioLogarithm(double number, int base) {
  double result;
  if (number <= 0.0) {
    result = (number == 0.0) ? trio_ninf() : trio_nan();
  } else {
    if (base == 10) {
      result = log10(number);
    } else {
      result = log10(number) / log10((double)base);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<TrioLogarithm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jb     1192 <TrioLogarithm+0x62>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1177 <TrioLogarithm+0x47>
jp     1177 <TrioLogarithm+0x47>
mov    $0x0,%al
call   1030 <trio_ninf@plt>
movsd  %xmm0,-0x20(%rbp)
jmp    1183 <TrioLogarithm+0x53>
mov    $0x0,%al
call   1040 <trio_nan@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11df <TrioLogarithm+0xaf>
cmpl   $0xa,-0xc(%rbp)
jne    11b0 <TrioLogarithm+0x80>
movsd  -0x8(%rbp),%xmm0
call   1050 <log10@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    11da <TrioLogarithm+0xaa>
movsd  -0x8(%rbp),%xmm0
call   1050 <log10@plt>
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
call   1050 <log10@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11df <TrioLogarithm+0xaf>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TrioLogarithm>:
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    1179 <TrioLogarithm+0x49>
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
call   1050 <log10@plt>
cmp    $0xa,%ebx
je     1173 <TrioLogarithm+0x43>
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
call   1050 <log10@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
ucomisd %xmm1,%xmm0
jne    1188 <TrioLogarithm+0x58>
jp     1188 <TrioLogarithm+0x58>
jmp    1030 <trio_ninf@plt>
jmp    1040 <trio_nan@plt>

LLVM IR (-O0):
define double @TrioLogarithm(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
store double %0, double* %3
store i32 %1, i32* %4
%6 = load double, double* %3
%7 = fcmp ole double %6, 0.000000e+00
br i1 %7, label %8, label %17
8: ; preds = %2
%9 = load double, double* %3
%10 = fcmp oeq double %9, 0.000000e+00
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call double (...) @trio_ninf()
br label %15
13: ; preds = %8
%14 = call double (...) @trio_nan()
br label %15
15: ; preds = %13, %11
%16 = phi double [ %12, %11 ], [ %14, %13 ]
store double %16, double* %5
br label %31
17: ; preds = %2
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load double, double* %3
%22 = call double @log10(double %21)
store double %22, double* %5
br label %30
23: ; preds = %17
%24 = load double, double* %3
%25 = call double @log10(double %24)
%26 = load i32, i32* %4
%27 = sitofp i32 %26 to double
%28 = call double @log10(double %27)
%29 = fdiv double %25, %28
store double %29, double* %5
br label %30
30: ; preds = %23, %20
br label %31
31: ; preds = %30, %15
%32 = load double, double* %5
ret double %32
}

LLVM IR (-O2):
define double @TrioLogarithm(double %0, i32 %1) {
%3 = fcmp ugt double %0, 0.000000e+00
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = fcmp oeq double %0, 0.000000e+00
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call double (...) @trio_ninf()
br label %17
8: ; preds = %4
%9 = tail call double (...) @trio_nan()
br label %17
10: ; preds = %2
%11 = icmp eq i32 %1, 10
%12 = tail call double @log10(double %0)
br i1 %11, label %17, label %13
13: ; preds = %10
%14 = sitofp i32 %1 to double
%15 = tail call double @log10(double %14)
%16 = fdiv double %12, %15
br label %17
17: ; preds = %10, %6, %8, %13
%18 = phi double [ %16, %13 ], [ %7, %6 ], [ %9, %8 ], [ %12, %10 ]
ret double %18
}