#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
float pow(float, int);
float ml_fast_pow(float x, int p) {
  switch (p) {
  case 2:
    return x * x;
  case 3:
    return x * x * x;
  case 4:
    return ml_fast_pow(x * x, 2);
  default:
    return pow(x, p);
  }
}


x86 assembly (clang, -O0):
<ml_fast_pow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x2,%eax
je     1166 <ml_fast_pow+0x46>
jmp    1144 <ml_fast_pow+0x24>
mov    -0x10(%rbp),%eax
sub    $0x3,%eax
je     117a <ml_fast_pow+0x5a>
jmp    1155 <ml_fast_pow+0x35>
mov    -0x10(%rbp),%eax
sub    $0x4,%eax
je     1193 <ml_fast_pow+0x73>
jmp    11b1 <ml_fast_pow+0x91>
movss  -0x8(%rbp),%xmm0
mulss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11c3 <ml_fast_pow+0xa3>
movss  -0x8(%rbp),%xmm0
mulss  -0x8(%rbp),%xmm0
mulss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11c3 <ml_fast_pow+0xa3>
movss  -0x8(%rbp),%xmm0
mulss  -0x8(%rbp),%xmm0
mov    $0x2,%edi
call   1030 <ml_fast_pow@plt>
movss  %xmm0,-0x4(%rbp)
jmp    11c3 <ml_fast_pow+0xa3>
movss  -0x8(%rbp),%xmm0
mov    -0xc(%rbp),%edi
call   1040 <pow@plt>
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ml_fast_pow>:
cmp    $0x4,%edi
je     1124 <ml_fast_pow+0x14>
cmp    $0x3,%edi
je     112d <ml_fast_pow+0x1d>
cmp    $0x2,%edi
jne    1139 <ml_fast_pow+0x29>
mulss  %xmm0,%xmm0
ret
mulss  %xmm0,%xmm0
mulss  %xmm0,%xmm0
ret
movaps %xmm0,%xmm1
mulss  %xmm0,%xmm1
mulss  %xmm1,%xmm0
ret
jmp    1030 <pow@plt>

LLVM IR (-O0):
define float @ml_fast_pow(float %0, i32 %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca i32
store float %0, float* %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
switch i32 %6, label %22 [
i32 2, label %7
i32 3, label %11
i32 4, label %17
]
7: ; preds = %2
%8 = load float, float* %4
%9 = load float, float* %4
%10 = fmul float %8, %9
store float %10, float* %3
br label %26
11: ; preds = %2
%12 = load float, float* %4
%13 = load float, float* %4
%14 = fmul float %12, %13
%15 = load float, float* %4
%16 = fmul float %14, %15
store float %16, float* %3
br label %26
17: ; preds = %2
%18 = load float, float* %4
%19 = load float, float* %4
%20 = fmul float %18, %19
%21 = call float @ml_fast_pow(float %20, i32 2)
store float %21, float* %3
br label %26
22: ; preds = %2
%23 = load float, float* %4
%24 = load i32, i32* %5
%25 = call float @pow(float %23, i32 %24)
store float %25, float* %3
br label %26
26: ; preds = %22, %17, %11, %7
%27 = load float, float* %3
ret float %27
}

LLVM IR (-O2):
define float @ml_fast_pow(float %0, i32 %1) {
switch i32 %1, label %11 [
i32 2, label %3
i32 3, label %5
i32 4, label %8
]
3: ; preds = %2
%4 = fmul float %0, %0
br label %13
5: ; preds = %2
%6 = fmul float %0, %0
%7 = fmul float %6, %0
br label %13
8: ; preds = %2
%9 = fmul float %0, %0
%10 = fmul float %9, %9
br label %13
11: ; preds = %2
%12 = tail call float @pow(float %0, i32 %1)
br label %13
13: ; preds = %11, %8, %5, %3
%14 = phi float [ %12, %11 ], [ %10, %8 ], [ %7, %5 ], [ %4, %3 ]
ret float %14
}