#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 hypot(float, float);
int vector_norm(float *r, float *a, int n) {
  *r = 0;
  for (int i = 0; i < n; i++)
    *r = hypot(*r, a[i]);
  return 1;
}


x86 assembly (clang, -O0):
<vector_norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1171 <vector_norm+0x61>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
call   1030 <hypot@plt>
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1135 <vector_norm+0x25>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vector_norm>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movl   $0x0,(%rdi)
test   %edx,%edx
jle    1149 <vector_norm+0x39>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
movss  (%r14,%rbx,4),%xmm1
call   1030 <hypot@plt>
movss  %xmm0,(%r15)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <vector_norm+0x20>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @vector_norm(float* %0, float* %1, i32 %2) {
%4 = alloca float*
%5 = alloca float*
%6 = alloca i32
%7 = alloca i32
store float* %0, float** %4
store float* %1, float** %5
store i32 %2, i32* %6
%8 = load float*, float** %4
store float 0.000000e+00, float* %8
store i32 0, i32* %7
br label %9
9: ; preds = %23, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %26
13: ; preds = %9
%14 = load float*, float** %4
%15 = load float, float* %14
%16 = load float*, float** %5
%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 @hypot(float %15, float %20)
%22 = load float*, float** %4
store float %21, float* %22
br label %23
23: ; preds = %13
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %9
26: ; preds = %9
ret i32 1
}

LLVM IR (-O2):
define i32 @vector_norm(float* nocapture %0, float* nocapture %1, i32 %2) {
store float 0.000000e+00, float* %0
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %8
7: ; preds = %8, %3
ret i32 1
8: ; preds = %5, %8
%9 = phi float [ 0.000000e+00, %5 ], [ %13, %8 ]
%10 = phi i64 [ 0, %5 ], [ %14, %8 ]
%11 = getelementptr inbounds float, float* %1, i64 %10
%12 = load float, float* %11
%13 = tail call float @hypot(float %9, float %12)
store float %13, float* %0
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, %6
br i1 %15, label %7, label %8
}