double power(base, pwr)
double base, pwr;
{
  if (base == 0)
    return (0);
  if (base < 0)
    return (-exp(pwr * log(-base)));
  else
    return (exp(pwr * log(base)));
}


x86 assembly (clang, -O0):
<power>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1157 <power+0x37>
jp     1157 <power+0x37>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ec <power+0xcc>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11c2 <power+0xa2>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <exp@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ec <power+0xcc>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<power>:
push   %rax
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jne    112d <power+0xd>
jnp    115f <power+0x3f>
movsd  %xmm1,(%rsp)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    1165 <power+0x45>
xorpd  0xebc(%rip),%xmm0
call   1040 <log@plt>
mulsd  (%rsp),%xmm0
call   1030 <exp@plt>
movapd %xmm0,%xmm2
xorpd  0xea1(%rip),%xmm2
movapd %xmm2,%xmm0
pop    %rax
ret
call   1040 <log@plt>
mulsd  (%rsp),%xmm0
pop    %rax
jmp    1030 <exp@plt>

LLVM IR (-O0):
define double @power(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %4
store double %1, double* %5
%6 = load double, double* %4
%7 = fcmp oeq double %6, 0.000000e+00
br i1 %7, label %8, label %9
8: ; preds = %2
store double 0.000000e+00, double* %3
br label %26
9: ; preds = %2
%10 = load double, double* %4
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load double, double* %5
%14 = load double, double* %4
%15 = fneg double %14
%16 = call double @log(double %15)
%17 = fmul double %13, %16
%18 = call double @exp(double %17)
%19 = fneg double %18
store double %19, double* %3
br label %26
20: ; preds = %9
%21 = load double, double* %5
%22 = load double, double* %4
%23 = call double @log(double %22)
%24 = fmul double %21, %23
%25 = call double @exp(double %24)
store double %25, double* %3
br label %26
26: ; preds = %20, %12, %8
%27 = load double, double* %3
ret double %27
}

LLVM IR (-O2):
define double @power(double %0, double %1) {
%3 = fcmp oeq double %0, 0.000000e+00
br i1 %3, label %16, label %4
4: ; preds = %2
%5 = fcmp olt double %0, 0.000000e+00
br i1 %5, label %6, label %12
6: ; preds = %4
%7 = fneg double %0
%8 = tail call double @log(double %7)
%9 = fmul double %8, %1
%10 = tail call double @exp(double %9)
%11 = fneg double %10
br label %16
12: ; preds = %4
%13 = tail call double @log(double %0)
%14 = fmul double %13, %1
%15 = tail call double @exp(double %14)
br label %16
16: ; preds = %2, %12, %6
%17 = phi double [ %11, %6 ], [ %15, %12 ], [ 0.000000e+00, %2 ]
ret double %17
}