double pow(double base, double exponent) {
  int buffer;
  if (exponent > 0) {
    if (((int)exponent) % 2 == 0) {
      buffer = pow(base, exponent / 2);
      return buffer * buffer;
    } else {
      return base * pow(base, ((int)exponent) - 1);
    }
  } else if (exponent < 0) {
    return 1.0 / pow(base, -exponent);
  }
  return 1;
}


x86 assembly (clang, -O0):
<pow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11b7 <pow+0xa7>
cvttsd2si -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1181 <pow+0x71>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xeac(%rip),%xmm2
divsd  %xmm2,%xmm1
call   1030 <pow@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x1c(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1216 <pow+0x106>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
cvttsd2si -0x18(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1216 <pow+0x106>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1204 <pow+0xf4>
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  0xe0a(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1216 <pow+0x106>
jmp    1209 <pow+0xf9>
movsd  0xdef(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pow>:
push   %rax
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jbe    1140 <pow+0x30>
cvttsd2si %xmm1,%eax
test   $0x1,%al
jne    1165 <pow+0x55>
mulsd  0xedd(%rip),%xmm1
call   1030 <pow@plt>
cvttsd2si %xmm0,%eax
imul   %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
pop    %rax
ret
ucomisd %xmm1,%xmm2
jbe    1180 <pow+0x70>
xorpd  0xec2(%rip),%xmm1
call   1030 <pow@plt>
movapd %xmm0,%xmm1
movsd  0xea1(%rip),%xmm0
divsd  %xmm1,%xmm0
pop    %rax
ret
add    $0xffffffff,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  %xmm0,(%rsp)
call   1030 <pow@plt>
mulsd  (%rsp),%xmm0
pop    %rax
ret
movsd  0xe78(%rip),%xmm0
pop    %rax
ret

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

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