double pow(double base, double potencia) {
  if (potencia == 0.0 && base != 0.0)
    return 1.0;
  else if (potencia == 0.0 && base == 0.0)
    return 0.0;
  double m = 1.0;
  for (int i = 1; i <= potencia; i++) {
    m *= base;
  }
  return m;
}


x86 assembly (clang, -O0):
<pow>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1155 <pow+0x55>
jp     1155 <pow+0x55>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1143 <pow+0x43>
jp     1143 <pow+0x43>
jmp    1155 <pow+0x55>
movsd  0xeb5(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e6 <pow+0xe6>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1192 <pow+0x92>
jp     1192 <pow+0x92>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1192 <pow+0x92>
jp     1192 <pow+0x92>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e6 <pow+0xe6>
jmp    1197 <pow+0x97>
movsd  0xe61(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11dc <pow+0xdc>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ab <pow+0xab>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<pow>:
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jne    1110 <pow+0x10>
jnp    1125 <pow+0x25>
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm1
jne    1125 <pow+0x25>
jp     1125 <pow+0x25>
movsd  0xedc(%rip),%xmm0
ret
ucomisd %xmm0,%xmm2
jne    1139 <pow+0x39>
jp     1139 <pow+0x39>
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm1
jne    1139 <pow+0x39>
jnp    1174 <pow+0x74>
movsd  0xebf(%rip),%xmm0
ucomisd %xmm0,%xmm1
jb     1174 <pow+0x74>
movsd  0xeb1(%rip),%xmm0
mov    $0x2,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorps  %xmm3,%xmm3
cvtsi2sd %eax,%xmm3
mulsd  %xmm2,%xmm0
add    $0x1,%eax
ucomisd %xmm3,%xmm1
jae    1160 <pow+0x60>
ret

LLVM IR (-O0):
define double @pow(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store double %0, double* %4
store double %1, double* %5
%8 = load double, double* %5
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load double, double* %4
%12 = fcmp une double %11, 0.000000e+00
br i1 %12, label %13, label %14
13: ; preds = %10
store double 1.000000e+00, double* %3
br label %37
14: ; preds = %10, %2
%15 = load double, double* %5
%16 = fcmp oeq double %15, 0.000000e+00
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load double, double* %4
%19 = fcmp oeq double %18, 0.000000e+00
br i1 %19, label %20, label %21
20: ; preds = %17
store double 0.000000e+00, double* %3
br label %37
21: ; preds = %17, %14
br label %22
22: ; preds = %21
store double 1.000000e+00, double* %6
store i32 1, i32* %7
br label %23
23: ; preds = %32, %22
%24 = load i32, i32* %7
%25 = sitofp i32 %24 to double
%26 = load double, double* %5
%27 = fcmp ole double %25, %26
br i1 %27, label %28, label %35
28: ; preds = %23
%29 = load double, double* %4
%30 = load double, double* %6
%31 = fmul double %30, %29
store double %31, double* %6
br label %32
32: ; preds = %28
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %23
35: ; preds = %23
%36 = load double, double* %6
store double %36, double* %3
br label %37
37: ; preds = %35, %20, %13
%38 = load double, double* %3
ret double %38
}

LLVM IR (-O2):
define double @pow(double %0, double %1) {
%3 = fcmp oeq double %1, 0.000000e+00
%4 = fcmp une double %0, 0.000000e+00
%5 = and i1 %4, %3
br i1 %5, label %18, label %6
6: ; preds = %2
%7 = fcmp oeq double %0, 0.000000e+00
%8 = and i1 %7, %3
br i1 %8, label %18, label %9
9: ; preds = %6
%10 = fcmp ult double %1, 1.000000e+00
br i1 %10, label %18, label %11
11: ; preds = %9, %11
%12 = phi i32 [ %15, %11 ], [ 1, %9 ]
%13 = phi double [ %14, %11 ], [ 1.000000e+00, %9 ]
%14 = fmul double %13, %0
%15 = add nuw nsw i32 %12, 1
%16 = sitofp i32 %15 to double
%17 = fcmp ugt double %16, %1
br i1 %17, label %18, label %11
18: ; preds = %11, %9, %6, %2
%19 = phi double [ 1.000000e+00, %2 ], [ 0.000000e+00, %6 ], [ 1.000000e+00, %9 ], [ %14, %11 ]
ret double %19
}