#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 const);
float hypot(float, float const);
float vnormf(const float *x, int n) {
  if (n == 1)
    return fabs(x[0]);
  else {
    float r = 0;
    for (int i = 0; i < n; i++)
      r = hypot(r, x[i]);
    return r;
  }
}


x86 assembly (clang, -O0):
<vnormf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1150 <vnormf+0x30>
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
call   1030 <fabs@plt>
movss  %xmm0,-0x4(%rbp)
jmp    119f <vnormf+0x7f>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1195 <vnormf+0x75>
movss  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
call   1040 <hypot@plt>
movss  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115f <vnormf+0x3f>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vnormf>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
cmp    $0x1,%esi
jne    112b <vnormf+0x1b>
movss  (%r14),%xmm0
andps  0xed7(%rip),%xmm0
jmp    1159 <vnormf+0x49>
jl     1156 <vnormf+0x46>
mov    %esi,%r15d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movss  (%r14,%rbx,4),%xmm1
call   1030 <hypot@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <vnormf+0x30>
jmp    1159 <vnormf+0x49>
xorps  %xmm0,%xmm0
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define float @vnormf(float* %0, i32 %1) {
%3 = alloca float
%4 = alloca float*
%5 = alloca i32
%6 = alloca float
%7 = alloca i32
store float* %0, float** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load float*, float** %4
%12 = getelementptr inbounds float, float* %11, i64 0
%13 = load float, float* %12
%14 = call float @fabs(float %13)
store float %14, float* %3
br label %33
15: ; preds = %2
store float 0.000000e+00, float* %6
store i32 0, i32* %7
br label %16
16: ; preds = %28, %15
%17 = load i32, i32* %7
%18 = load i32, i32* %5
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %31
20: ; preds = %16
%21 = load float, float* %6
%22 = load float*, float** %4
%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 @hypot(float %21, float %26)
store float %27, float* %6
br label %28
28: ; preds = %20
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %16
31: ; preds = %16
%32 = load float, float* %6
store float %32, float* %3
br label %33
33: ; preds = %31, %10
%34 = load float, float* %3
ret float %34
}

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