#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 */
scalar_t__ sqf(float);
double sqrtf(double);
double compute_norm(unsigned w, unsigned h, float *data) {
  double norm = 0.;
  for (size_t i = 0; i < (size_t)h * w; i++) {
    norm += sqf(data[i]);
  }
  return sqrtf(norm);
}


x86 assembly (clang, -O0):
<compute_norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%edx
imul   %rdx,%rcx
cmp    %rcx,%rax
jae    118b <compute_norm+0x6b>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1030 <sqf@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1142 <compute_norm+0x22>
movsd  -0x18(%rbp),%xmm0
call   1040 <sqrtf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_norm>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%eax
mov    %edi,%r15d
imul   %rax,%r15
xorpd  %xmm0,%xmm0
test   %r15,%r15
je     1188 <compute_norm+0x68>
mov    %rdx,%r14
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm0,0x8(%rsp)
movss  (%r14,%rbx,4),%xmm0
call   1030 <sqf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <compute_norm+0x30>
ucomisd 0xe70(%rip),%xmm0
jb     11a0 <compute_norm+0x80>
sqrtsd %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 double @compute_norm(i32 %0, i32 %1, float* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca float*
%7 = alloca double
%8 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
store float* %2, float** %6
store double 0.000000e+00, double* %7
store i64 0, i64* %8
br label %9
9: ; preds = %26, %3
%10 = load i64, i64* %8
%11 = load i32, i32* %5
%12 = zext i32 %11 to i64
%13 = load i32, i32* %4
%14 = zext i32 %13 to i64
%15 = mul i64 %12, %14
%16 = icmp ult i64 %10, %15
br i1 %16, label %17, label %29
17: ; preds = %9
%18 = load float*, float** %6
%19 = load i64, i64* %8
%20 = getelementptr inbounds float, float* %18, i64 %19
%21 = load float, float* %20
%22 = call i64 @sqf(float %21)
%23 = sitofp i64 %22 to double
%24 = load double, double* %7
%25 = fadd double %24, %23
store double %25, double* %7
br label %26
26: ; preds = %17
%27 = load i64, i64* %8
%28 = add i64 %27, 1
store i64 %28, i64* %8
br label %9
29: ; preds = %9
%30 = load double, double* %7
%31 = call double @sqrtf(double %30)
ret double %31
}

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