#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 */
typedef int /*<<< orphan*/ vector;

/* Variables and functions */
scalar_t__ pow(float const, int);
float sqrt(float);
float vectorNorm(const float *vector) {
  float sum = 0;
  int i;
  int length = (sizeof(vector) / sizeof((vector)[0])) + 1;
  for (i = 0; i < length; i++) {
    sum += pow(vector[i], 2);
  }
  return sqrt(sum);
}


x86 assembly (clang, -O0):
<vectorNorm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movl   $0x3,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1182 <vectorNorm+0x62>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
cvtsi2ss %rax,%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1142 <vectorNorm+0x22>
movss  -0xc(%rbp),%xmm0
call   1040 <sqrt@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vectorNorm>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movss  (%rdi),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,0xc(%rsp)
movss  0x4(%rbx),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
movss  0x8(%rbx),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  0xc(%rsp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     1196 <vectorNorm+0x76>
sqrtss %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
ret
add    $0x10,%rsp
pop    %rbx
jmp    1040 <sqrt@plt>

LLVM IR (-O0):
define float @vectorNorm(float* %0) {
%2 = alloca float*
%3 = alloca float
%4 = alloca i32
%5 = alloca i32
store float* %0, float** %2
store float 0.000000e+00, float* %3
store i32 3, i32* %5
store i32 0, i32* %4
br label %6
6: ; preds = %20, %1
%7 = load i32, i32* %4
%8 = load i32, i32* %5
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %23
10: ; preds = %6
%11 = load float*, float** %2
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds float, float* %11, i64 %13
%15 = load float, float* %14
%16 = call i64 @pow(float %15, i32 2)
%17 = sitofp i64 %16 to float
%18 = load float, float* %3
%19 = fadd float %18, %17
store float %19, float* %3
br label %20
20: ; preds = %10
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %6
23: ; preds = %6
%24 = load float, float* %3
%25 = call float @sqrt(float %24)
ret float %25
}

LLVM IR (-O2):
define float @vectorNorm(float* nocapture %0) {
%2 = load float, float* %0
%3 = tail call i64 @pow(float %2, i32 2)
%4 = sitofp i64 %3 to float
%5 = getelementptr inbounds float, float* %0, i64 1
%6 = load float, float* %5
%7 = tail call i64 @pow(float %6, i32 2)
%8 = sitofp i64 %7 to float
%9 = fadd float %4, %8
%10 = getelementptr inbounds float, float* %0, i64 2
%11 = load float, float* %10
%12 = tail call i64 @pow(float %11, i32 2)
%13 = sitofp i64 %12 to float
%14 = fadd float %9, %13
%15 = tail call float @sqrt(float %14)
ret float %15
}