#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__ vec_norm(double *, int);
double avg_norm(double **X, int m, int n) {
  int i;
  double r = 0.0;
  for (i = 0; i < m; i++)
    r += vec_norm(X[i], n);
  return r / ((double)m);
}


x86 assembly (clang, -O0):
<avg_norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    116e <avg_norm+0x5e>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%esi
call   1030 <vec_norm@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1131 <avg_norm+0x21>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<avg_norm>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
test   %esi,%esi
jle    116f <avg_norm+0x5f>
mov    %edx,%r15d
mov    %rdi,%r12
mov    %r14d,%ebp
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm0,0x8(%rsp)
mov    (%r12,%rbx,8),%rdi
mov    %r15d,%esi
call   1030 <vec_norm@plt>
movsd  0x8(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm0
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <avg_norm+0x30>
jmp    1173 <avg_norm+0x63>
xorpd  %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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