#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 fabs(float);
float sqrtf(float);
float spectral_flux(float *spectrum, float *spectrum_prev, float N) {
  int i;
  float spectral_flux = 0.f;
  float temp;
  for (i = 0; i <= N; i++) {
    temp = sqrtf(spectrum[i]) - sqrtf(spectrum_prev[i]);
    spectral_flux += (temp + fabs(temp)) / 2.f;
  }
  return spectral_flux;
}


x86 assembly (clang, -O0):
<spectral_flux>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movss  %xmm0,-0x14(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
cvtsi2ssl -0x18(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     11d5 <spectral_flux+0xb5>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1040 <sqrtf@plt>
movss  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1040 <sqrtf@plt>
movaps %xmm0,%xmm1
movss  -0x28(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x20(%rbp),%xmm0
call   1030 <fabs@plt>
movaps %xmm0,%xmm1
movss  -0x24(%rbp),%xmm0
addss  %xmm1,%xmm0
movss  0xe47(%rip),%xmm1
divss  %xmm1,%xmm0
addss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1144 <spectral_flux+0x24>
movss  -0x1c(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spectral_flux>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
xorps  %xmm2,%xmm2
movss  %xmm0,0xc(%rsp)
ucomiss %xmm2,%xmm0
jae    1134 <spectral_flux+0x24>
movaps %xmm2,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rsi,%r14
mov    %rdi,%r15
xorps  %xmm3,%xmm3
xor    %ebx,%ebx
xorps  %xmm2,%xmm2
jmp    119c <spectral_flux+0x8c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movaps %xmm1,0x10(%rsp)
call   1030 <sqrtf@plt>
movaps 0x10(%rsp),%xmm1
xorps  %xmm3,%xmm3
movss  0x8(%rsp),%xmm2
subss  %xmm0,%xmm1
movaps %xmm1,%xmm0
andps  0xe8a(%rip),%xmm0
addss  %xmm1,%xmm0
add    $0x1,%rbx
xorps  %xmm1,%xmm1
cvtsi2ss %ebx,%xmm1
mulss  0xe83(%rip),%xmm0
addss  %xmm0,%xmm2
movss  0xc(%rsp),%xmm0
ucomiss %xmm1,%xmm0
jb     1127 <spectral_flux+0x17>
movss  (%r15,%rbx,4),%xmm0
ucomiss %xmm3,%xmm0
movss  %xmm2,0x8(%rsp)
jb     11c0 <spectral_flux+0xb0>
xorps  %xmm1,%xmm1
sqrtss %xmm0,%xmm1
jmp    11cb <spectral_flux+0xbb>
cs nopw 0x0(%rax,%rax,1)
call   1030 <sqrtf@plt>
xorps  %xmm3,%xmm3
movaps %xmm0,%xmm1
movss  (%r14,%rbx,4),%xmm0
ucomiss %xmm3,%xmm0
jb     1150 <spectral_flux+0x40>
sqrtss %xmm0,%xmm0
jmp    1162 <spectral_flux+0x52>

LLVM IR (-O0):
define float @spectral_flux(float* %0, float* %1, float %2) {
%4 = alloca float*
%5 = alloca float*
%6 = alloca float
%7 = alloca i32
%8 = alloca float
%9 = alloca float
store float* %0, float** %4
store float* %1, float** %5
store float %2, float* %6
store float 0.000000e+00, float* %8
store i32 0, i32* %7
br label %10
10: ; preds = %36, %3
%11 = load i32, i32* %7
%12 = sitofp i32 %11 to float
%13 = load float, float* %6
%14 = fcmp ole float %12, %13
br i1 %14, label %15, label %39
15: ; preds = %10
%16 = load float*, float** %4
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds float, float* %16, i64 %18
%20 = load float, float* %19
%21 = call float @sqrtf(float %20)
%22 = load float*, float** %5
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds float, float* %22, i64 %24
%26 = load float, float* %25
%27 = call float @sqrtf(float %26)
%28 = fsub float %21, %27
store float %28, float* %9
%29 = load float, float* %9
%30 = load float, float* %9
%31 = call float @fabs(float %30)
%32 = fadd float %29, %31
%33 = fdiv float %32, 2.000000e+00
%34 = load float, float* %8
%35 = fadd float %34, %33
store float %35, float* %8
br label %36
36: ; preds = %15
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %10
39: ; preds = %10
%40 = load float, float* %8
ret float %40
}

LLVM IR (-O2):
define float @spectral_flux(float* nocapture %0, float* nocapture %1, float %2) {
%4 = fcmp ult float %2, 0.000000e+00
br i1 %4, label %23, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %19, %5 ], [ 0, %3 ]
%7 = phi float [ %18, %5 ], [ 0.000000e+00, %3 ]
%8 = getelementptr inbounds float, float* %0, i64 %6
%9 = load float, float* %8
%10 = tail call float @sqrtf(float %9)
%11 = getelementptr inbounds float, float* %1, i64 %6
%12 = load float, float* %11
%13 = tail call float @sqrtf(float %12)
%14 = fsub float %10, %13
%15 = tail call float @llvm.fabs.f32(float %14)
%16 = fadd float %14, %15
%17 = fmul float %16, 5.000000e-01
%18 = fadd float %7, %17
%19 = add nuw i64 %6, 1
%20 = trunc i64 %19 to i32
%21 = sitofp i32 %20 to float
%22 = fcmp ugt float %21, %2
br i1 %22, label %23, label %5
23: ; preds = %5, %3
%24 = phi float [ 0.000000e+00, %3 ], [ %18, %5 ]
ret float %24
}