double pow(double base, double exponent) {
  int result = 1;
  if (exponent == 0)
    return result;
  if (exponent < 0)
    return 1 / pow(base, -exponent);
  float temp = pow(base, exponent / 2);
  if ((int)exponent % 2 == 0)
    return temp * temp;
  else
    return (base * temp * temp);
}


x86 assembly (clang, -O0):
<pow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1150 <pow+0x40>
jp     1150 <pow+0x40>
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1213 <pow+0x103>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    119d <pow+0x8d>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xe79(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1213 <pow+0x103>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe51(%rip),%xmm2
divsd  %xmm2,%xmm1
call   1030 <pow@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
cvttsd2si -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ef <pow+0xdf>
movss  -0x20(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1213 <pow+0x103>
movsd  -0x10(%rbp),%xmm0
movss  -0x20(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movss  -0x20(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pow>:
sub    $0x28,%rsp
movapd %xmm1,%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
jne    112e <pow+0x1e>
jp     112e <pow+0x1e>
movsd  0xed4(%rip),%xmm1
jmp    119d <pow+0x8d>
ucomisd %xmm2,%xmm1
jbe    1153 <pow+0x43>
xorpd  0xed4(%rip),%xmm2
movapd %xmm2,%xmm1
call   1030 <pow@plt>
movsd  0xeb3(%rip),%xmm1
divsd  %xmm0,%xmm1
jmp    119d <pow+0x8d>
movsd  0xead(%rip),%xmm1
mulsd  %xmm2,%xmm1
movsd  %xmm0,0x8(%rsp)
movapd %xmm2,0x10(%rsp)
call   1030 <pow@plt>
cvtsd2ss %xmm0,%xmm0
cvttsd2si 0x10(%rsp),%eax
test   $0x1,%al
jne    118b <pow+0x7b>
mulss  %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
jmp    119d <pow+0x8d>
cvtss2sd %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @pow(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca float
store double %0, double* %4
store double %1, double* %5
store i32 1, i32* %6
%8 = load double, double* %5
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* %6
%12 = sitofp i32 %11 to double
store double %12, double* %3
br label %45
13: ; preds = %2
%14 = load double, double* %5
%15 = fcmp olt double %14, 0.000000e+00
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load double, double* %4
%18 = load double, double* %5
%19 = fneg double %18
%20 = call double @pow(double %17, double %19)
%21 = fdiv double 1.000000e+00, %20
store double %21, double* %3
br label %45
22: ; preds = %13
%23 = load double, double* %4
%24 = load double, double* %5
%25 = fdiv double %24, 2.000000e+00
%26 = call double @pow(double %23, double %25)
%27 = fptrunc double %26 to float
store float %27, float* %7
%28 = load double, double* %5
%29 = fptosi double %28 to i32
%30 = srem i32 %29, 2
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %22
%33 = load float, float* %7
%34 = load float, float* %7
%35 = fmul float %33, %34
%36 = fpext float %35 to double
store double %36, double* %3
br label %45
37: ; preds = %22
%38 = load double, double* %4
%39 = load float, float* %7
%40 = fpext float %39 to double
%41 = fmul double %38, %40
%42 = load float, float* %7
%43 = fpext float %42 to double
%44 = fmul double %41, %43
store double %44, double* %3
br label %45
45: ; preds = %37, %32, %16, %10
%46 = load double, double* %3
ret double %46
}

LLVM IR (-O2):
define double @pow(double %0, double %1) {
%3 = fcmp oeq double %1, 0.000000e+00
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = fcmp olt double %1, 0.000000e+00
br i1 %5, label %8, label %12
6: ; preds = %2, %22, %19, %8
%7 = phi double [ %11, %8 ], [ 1.000000e+00, %2 ], [ %21, %19 ], [ %25, %22 ]
ret double %7
8: ; preds = %4
%9 = fneg double %1
%10 = tail call double @pow(double %0, double %9)
%11 = fdiv double 1.000000e+00, %10
br label %6
12: ; preds = %4
%13 = fmul double %1, 5.000000e-01
%14 = tail call double @pow(double %0, double %13)
%15 = fptrunc double %14 to float
%16 = fptosi double %1 to i32
%17 = and i32 %16, 1
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = fmul float %15, %15
%21 = fpext float %20 to double
br label %6
22: ; preds = %12
%23 = fpext float %15 to double
%24 = fmul double %23, %0
%25 = fmul double %24, %23
br label %6
}