#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 flt_add(float, float);
float flt_mul(float const, float const);
scalar_t__ isrealf(float const);
float sqrtf(float);
float flt_l2norm(const float *restrict x, const size_t n) {
  float square, sum, norm;
  size_t i;
  sum = 0.f;
  for (i = 0; i < n; i++) {
    if (isrealf(x[i])) {
      square = flt_mul(x[i], x[i]);
      sum = flt_add(sum, square);
    }
  }
  norm = sqrtf(sum);
  return norm;
}


x86 assembly (clang, -O0):
<flt_l2norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11d8 <flt_l2norm+0x98>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1050 <isrealf@plt>
cmp    $0x0,%rax
je     11c2 <flt_l2norm+0x82>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
call   1060 <flt_mul@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x18(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
call   1030 <flt_add@plt>
movss  %xmm0,-0x18(%rbp)
jmp    11c7 <flt_l2norm+0x87>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1160 <flt_l2norm+0x20>
movss  -0x18(%rbp),%xmm0
call   1040 <sqrtf@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flt_l2norm>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
test   %rsi,%rsi
je     11a9 <flt_l2norm+0x69>
mov    %rsi,%r15
mov    %rdi,%r14
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    1185 <flt_l2norm+0x45>
xchg   %ax,%ax
movss  0xc(%rsp),%xmm0
movaps %xmm0,%xmm1
call   1060 <flt_mul@plt>
movaps %xmm0,%xmm1
movss  0x8(%rsp),%xmm0
call   1030 <flt_add@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
je     11a9 <flt_l2norm+0x69>
movss  %xmm0,0x8(%rsp)
movss  (%r14,%rbx,4),%xmm0
movss  %xmm0,0xc(%rsp)
call   1050 <isrealf@plt>
test   %rax,%rax
jne    1160 <flt_l2norm+0x20>
movss  0x8(%rsp),%xmm0
jmp    117c <flt_l2norm+0x3c>
ucomiss 0xe50(%rip),%xmm0
jb     11c0 <flt_l2norm+0x80>
sqrtss %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <sqrtf@plt>

LLVM IR (-O0):
define float @flt_l2norm(float* noalias %0, i64 %1) {
%3 = alloca float*
%4 = alloca i64
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca i64
store float* %0, float** %3
store i64 %1, i64* %4
store float 0.000000e+00, float* %6
store i64 0, i64* %8
br label %9
9: ; preds = %34, %2
%10 = load i64, i64* %8
%11 = load i64, i64* %4
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %37
13: ; preds = %9
%14 = load float*, float** %3
%15 = load i64, i64* %8
%16 = getelementptr inbounds float, float* %14, i64 %15
%17 = load float, float* %16
%18 = call i64 @isrealf(float %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %13
%21 = load float*, float** %3
%22 = load i64, i64* %8
%23 = getelementptr inbounds float, float* %21, i64 %22
%24 = load float, float* %23
%25 = load float*, float** %3
%26 = load i64, i64* %8
%27 = getelementptr inbounds float, float* %25, i64 %26
%28 = load float, float* %27
%29 = call float @flt_mul(float %24, float %28)
store float %29, float* %5
%30 = load float, float* %6
%31 = load float, float* %5
%32 = call float @flt_add(float %30, float %31)
store float %32, float* %6
br label %33
33: ; preds = %20, %13
br label %34
34: ; preds = %33
%35 = load i64, i64* %8
%36 = add i64 %35, 1
store i64 %36, i64* %8
br label %9
37: ; preds = %9
%38 = load float, float* %6
%39 = call float @sqrtf(float %38)
store float %39, float* %7
%40 = load float, float* %7
ret float %40
}

LLVM IR (-O2):
define float @flt_l2norm(float* noalias nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %18, label %4
4: ; preds = %2, %14
%5 = phi i64 [ %16, %14 ], [ 0, %2 ]
%6 = phi float [ %15, %14 ], [ 0.000000e+00, %2 ]
%7 = getelementptr inbounds float, float* %0, i64 %5
%8 = load float, float* %7
%9 = tail call i64 @isrealf(float %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %4
%12 = tail call float @flt_mul(float %8, float %8)
%13 = tail call float @flt_add(float %6, float %12)
br label %14
14: ; preds = %4, %11
%15 = phi float [ %13, %11 ], [ %6, %4 ]
%16 = add nuw i64 %5, 1
%17 = icmp eq i64 %16, %1
br i1 %17, label %18, label %4
18: ; preds = %14, %2
%19 = phi float [ 0.000000e+00, %2 ], [ %15, %14 ]
%20 = tail call float @sqrtf(float %19)
ret float %20
}