double recursive_power(double b, int n) {
  if (n == 0)
    return 1.0;
  if (n > 0)
    return (b * recursive_power(b, n - 1));
  if (n < 0)
    return (recursive_power(1 / b, -1 * n));
  return 1.0;
}


x86 assembly (clang, -O0):
<recursive_power>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    113c <recursive_power+0x2c>
movsd  0xece(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b0 <recursive_power+0xa0>
cmpl   $0x0,-0x14(%rbp)
jle    1176 <recursive_power+0x66>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%edi
sub    $0x1,%edi
call   1030 <recursive_power@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b0 <recursive_power+0xa0>
cmpl   $0x0,-0x14(%rbp)
jge    11a3 <recursive_power+0x93>
movsd  0xe78(%rip),%xmm0
divsd  -0x10(%rbp),%xmm0
imul   $0xffffffff,-0x14(%rbp),%edi
call   1030 <recursive_power@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11b0 <recursive_power+0xa0>
movsd  0xe55(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recursive_power>:
push   %rax
test   %edi,%edi
je     1146 <recursive_power+0x36>
movapd %xmm0,%xmm2
movsd  0xedf(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %edi,%edi
jg     1150 <recursive_power+0x40>
movapd %xmm0,%xmm1
divsd  %xmm2,%xmm1
neg    %edi
movapd %xmm1,%xmm2
jb     1130 <recursive_power+0x20>
pop    %rax
ret
movsd  0xeb2(%rip),%xmm0
pop    %rax
ret
add    $0xffffffff,%edi
movapd %xmm2,%xmm0
movsd  %xmm2,(%rsp)
call   1030 <recursive_power@plt>
mulsd  (%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @recursive_power(double %0, i32 %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store double %0, double* %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
store double 1.000000e+00, double* %3
br label %29
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = load double, double* %4
%14 = load double, double* %4
%15 = load i32, i32* %5
%16 = sub nsw i32 %15, 1
%17 = call double @recursive_power(double %14, i32 %16)
%18 = fmul double %13, %17
store double %18, double* %3
br label %29
19: ; preds = %9
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load double, double* %4
%24 = fdiv double 1.000000e+00, %23
%25 = load i32, i32* %5
%26 = mul nsw i32 -1, %25
%27 = call double @recursive_power(double %24, i32 %26)
store double %27, double* %3
br label %29
28: ; preds = %19
store double 1.000000e+00, double* %3
br label %29
29: ; preds = %28, %22, %12, %8
%30 = load double, double* %3
ret double %30
}

LLVM IR (-O2):
define double @recursive_power(double %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %8, label %4
4: ; preds = %2, %14
%5 = phi i32 [ %16, %14 ], [ %1, %2 ]
%6 = phi double [ %15, %14 ], [ %0, %2 ]
%7 = icmp sgt i32 %5, 0
br i1 %7, label %10, label %14
8: ; preds = %14, %2, %10
%9 = phi double [ %13, %10 ], [ 1.000000e+00, %2 ], [ 1.000000e+00, %14 ]
ret double %9
10: ; preds = %4
%11 = add nsw i32 %5, -1
%12 = tail call double @recursive_power(double %6, i32 %11)
%13 = fmul double %6, %12
br label %8
14: ; preds = %4
%15 = fdiv double 1.000000e+00, %6
%16 = sub nsw i32 0, %5
%17 = icmp eq i32 %5, 0
br i1 %17, label %8, label %4
}