double myPow(double x, int n) {
  double temp = 0;
  if (n == 0 || x == 1) {
    return 1;
  }
  if (x == 0) {
    return 0;
  }
  temp = myPow(x, n / 2);
  if (n % 2 == 0) {
    return temp * temp;
  } else {
    if (n > 0) {
      return x * temp * temp;
    } else {
      return (temp * temp) / x;
    }
  }
}


x86 assembly (clang, -O0):
<myPow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     114f <myPow+0x3f>
movsd  -0x10(%rbp),%xmm0
movsd  0xec1(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1161 <myPow+0x51>
jp     1161 <myPow+0x51>
movsd  0xea9(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1201 <myPow+0xf1>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1186 <myPow+0x76>
jp     1186 <myPow+0x76>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1201 <myPow+0xf1>
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <myPow@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ca <myPow+0xba>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1201 <myPow+0xf1>
cmpl   $0x0,-0x14(%rbp)
jle    11ed <myPow+0xdd>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1201 <myPow+0xf1>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myPow>:
push   %rbx
sub    $0x10,%rsp
movapd %xmm0,%xmm1
movsd  0xedf(%rip),%xmm0
ucomisd %xmm0,%xmm1
jne    1129 <myPow+0x19>
jnp    117c <myPow+0x6c>
mov    %edi,%ebx
test   %edi,%edi
je     117c <myPow+0x6c>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    113b <myPow+0x2b>
jnp    117c <myPow+0x6c>
mov    %ebx,%edi
shr    $0x1f,%edi
add    %ebx,%edi
sar    %edi
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
call   1030 <myPow@plt>
test   $0x1,%bl
jne    115e <myPow+0x4e>
mulsd  %xmm0,%xmm0
jmp    117c <myPow+0x6c>
test   %ebx,%ebx
jle    1172 <myPow+0x62>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm1,%xmm0
jmp    117c <myPow+0x6c>
mulsd  %xmm0,%xmm0
divsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

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

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