#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 powf(float, float);
float spectrum_p_norm(float *spectrum, float N, float p) {
  float sum = 0.f;
  for (int k = 0; k < N; k++) {
    sum += powf(spectrum[k], p);
  }
  return powf(sum, 1.f / p);
}


x86 assembly (clang, -O0):
<spectrum_p_norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  %xmm1,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cvtsi2ssl -0x18(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1177 <spectrum_p_norm+0x67>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  -0x10(%rbp),%xmm1
call   1030 <powf@plt>
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1135 <spectrum_p_norm+0x25>
movss  -0x14(%rbp),%xmm0
movss  0xe7c(%rip),%xmm1
divss  -0x10(%rbp),%xmm1
call   1030 <powf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spectrum_p_norm>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movaps %xmm1,%xmm2
movaps %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jbe    1186 <spectrum_p_norm+0x76>
mov    %rdi,%r14
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
movss  %xmm2,0x14(%rsp)
movss  %xmm1,0x10(%rsp)
nopl   0x0(%rax)
movss  %xmm0,0xc(%rsp)
movss  (%r14,%rbx,4),%xmm0
movaps %xmm2,%xmm1
call   1030 <powf@plt>
movss  0x14(%rsp),%xmm2
add    $0x1,%rbx
xorps  %xmm1,%xmm1
cvtsi2ss %ebx,%xmm1
movss  0xc(%rsp),%xmm3
addss  %xmm0,%xmm3
movss  %xmm3,0xc(%rsp)
movss  0xc(%rsp),%xmm0
movss  0x10(%rsp),%xmm3
ucomiss %xmm1,%xmm3
ja     1140 <spectrum_p_norm+0x30>
movss  0xe72(%rip),%xmm1
divss  %xmm2,%xmm1
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1030 <powf@plt>

LLVM IR (-O0):
define float @spectrum_p_norm(float* %0, float %1, float %2) {
%4 = alloca float*
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca i32
store float* %0, float** %4
store float %1, float* %5
store float %2, float* %6
store float 0.000000e+00, float* %7
store i32 0, i32* %8
br label %9
9: ; preds = %24, %3
%10 = load i32, i32* %8
%11 = sitofp i32 %10 to float
%12 = load float, float* %5
%13 = fcmp olt float %11, %12
br i1 %13, label %14, label %27
14: ; preds = %9
%15 = load float*, float** %4
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds float, float* %15, i64 %17
%19 = load float, float* %18
%20 = load float, float* %6
%21 = call float @powf(float %19, float %20)
%22 = load float, float* %7
%23 = fadd float %22, %21
store float %23, float* %7
br label %24
24: ; preds = %14
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
br label %9
27: ; preds = %9
%28 = load float, float* %7
%29 = load float, float* %6
%30 = fdiv float 1.000000e+00, %29
%31 = call float @powf(float %28, float %30)
ret float %31
}

LLVM IR (-O2):
define float @spectrum_p_norm(float* nocapture %0, float %1, float %2) {
%4 = fcmp ogt float %1, 0.000000e+00
br i1 %4, label %9, label %5
5: ; preds = %9, %3
%6 = phi float [ 0.000000e+00, %3 ], [ %15, %9 ]
%7 = fdiv float 1.000000e+00, %2
%8 = tail call float @powf(float %6, float %7)
ret float %8
9: ; preds = %3, %9
%10 = phi i64 [ %16, %9 ], [ 0, %3 ]
%11 = phi float [ %15, %9 ], [ 0.000000e+00, %3 ]
%12 = getelementptr inbounds float, float* %0, i64 %10
%13 = load float, float* %12
%14 = tail call float @powf(float %13, float %2)
%15 = fadd float %11, %14
%16 = add nuw i64 %10, 1
%17 = trunc i64 %16 to i32
%18 = sitofp i32 %17 to float
%19 = fcmp olt float %18, %1
br i1 %19, label %9, label %5
}