#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 */
size_t cblas_idamax(int const, double *, int);
scalar_t__ fabs(double);
double calc_norm_2(const int N, const int LD, double (*A)[LD]) {
  double tmp_norma[N];
  for (int j = 0; j < N; j++) {
    tmp_norma[j] = 0.0;
    for (int i = 0; i < N; i++) {
      tmp_norma[j] += fabs(A[i][j]);
    }
  }
  return tmp_norma[cblas_idamax(N, tmp_norma, 1)];
}


x86 assembly (clang, -O0):
<calc_norm_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11f6 <calc_norm_2+0xd6>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e3 <calc_norm_2+0xc3>
mov    -0x38(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
imul   %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cvtsi2sd %rcx,%xmm0
movslq -0x24(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    118a <calc_norm_2+0x6a>
jmp    11e8 <calc_norm_2+0xc8>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1167 <calc_norm_2+0x47>
mov    -0x30(%rbp),%rsi
mov    -0x4(%rbp),%edi
mov    $0x1,%edx
call   1040 <cblas_idamax@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_norm_2>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,-0x40(%rbp)
mov    %edi,%ecx
mov    %rsp,%rbx
lea    0xf(,%rcx,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %edi,-0x34(%rbp)
test   %edi,%edi
jle    1259 <calc_norm_2+0x139>
mov    %esi,%r13d
mov    %ecx,%eax
and    $0xfffffffe,%eax
mov    %rax,-0x60(%rbp)
mov    %r13,%rax
shl    $0x4,%rax
mov    %rax,-0x58(%rbp)
xor    %r14d,%r14d
mov    -0x40(%rbp),%rax
mov    %rcx,-0x48(%rbp)
jmp    1195 <calc_norm_2+0x75>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
mov    -0x50(%rbp),%rax
add    $0x8,%rax
cmp    %r15,%r14
je     1259 <calc_norm_2+0x139>
movq   $0x0,(%rbx,%r14,8)
cmpl   $0x1,-0x34(%rbp)
mov    %rax,-0x50(%rbp)
xorpd  %xmm0,%xmm0
jne    11b0 <calc_norm_2+0x90>
xor    %r12d,%r12d
jmp    1213 <calc_norm_2+0xf3>
mov    %rax,%r15
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm0,-0x30(%rbp)
movsd  (%r15),%xmm0
call   1030 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  %xmm0,(%rbx,%r14,8)
movsd  (%r15,%r13,8),%xmm0
call   1030 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,(%rbx,%r14,8)
add    $0x2,%r12
add    -0x58(%rbp),%r15
cmp    %r12,-0x60(%rbp)
jne    11c0 <calc_norm_2+0xa0>
mov    -0x48(%rbp),%r15
test   $0x1,%r15b
je     1180 <calc_norm_2+0x60>
mov    -0x40(%rbp),%rax
lea    (%rax,%r14,8),%rax
imul   %r13,%r12
movsd  %xmm0,-0x30(%rbp)
movsd  (%rax,%r12,8),%xmm0
call   1030 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  -0x30(%rbp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%r14,8)
jmp    1180 <calc_norm_2+0x60>
mov    -0x34(%rbp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <cblas_idamax@plt>
movsd  (%rbx,%rax,8),%xmm0
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @calc_norm_2(i32 %0, i32 %1, double* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca double*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store double* %2, double** %6
%11 = load i32, i32* %5
%12 = zext i32 %11 to i64
%13 = load i32, i32* %4
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %7
%16 = alloca double, i64 %14
store i64 %14, i64* %8
store i32 0, i32* %9
br label %17
17: ; preds = %50, %3
%18 = load i32, i32* %9
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %53
21: ; preds = %17
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %16, i64 %23
store double 0.000000e+00, double* %24
store i32 0, i32* %10
br label %25
25: ; preds = %46, %21
%26 = load i32, i32* %10
%27 = load i32, i32* %4
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %49
29: ; preds = %25
%30 = load double*, double** %6
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = mul nsw i64 %32, %12
%34 = getelementptr inbounds double, double* %30, i64 %33
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
%38 = load double, double* %37
%39 = call i64 @fabs(double %38)
%40 = sitofp i64 %39 to double
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %16, i64 %42
%44 = load double, double* %43
%45 = fadd double %44, %40
store double %45, double* %43
br label %46
46: ; preds = %29
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
br label %25
49: ; preds = %25
br label %50
50: ; preds = %49
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %17
53: ; preds = %17
%54 = load i32, i32* %4
%55 = call i64 @cblas_idamax(i32 %54, double* %16, i32 1)
%56 = getelementptr inbounds double, double* %16, i64 %55
%57 = load double, double* %56
%58 = load i8*, i8** %7
ret double %57
}

LLVM IR (-O2):
define double @calc_norm_2(i32 %0, i32 %1, double* nocapture %2) {
%4 = zext i32 %1 to i64
%5 = zext i32 %0 to i64
%6 = alloca double, i64 %5
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = and i64 %5, 1
%10 = icmp eq i32 %0, 1
%11 = and i64 %5, 4294967294
%12 = icmp eq i64 %9, 0
br label %17
13: ; preds = %31, %3
%14 = call i64 @cblas_idamax(i32 %0, double* %6, i32 1)
%15 = getelementptr inbounds double, double* %6, i64 %14
%16 = load double, double* %15
ret double %16
17: ; preds = %8, %31
%18 = phi i64 [ %32, %31 ], [ 0, %8 ]
%19 = getelementptr inbounds double, double* %6, i64 %18
store double 0.000000e+00, double* %19
%20 = getelementptr inbounds double, double* %2, i64 %18
br i1 %10, label %21, label %34
21: ; preds = %34, %17
%22 = phi double [ 0.000000e+00, %17 ], [ %50, %34 ]
%23 = phi i64 [ 0, %17 ], [ %51, %34 ]
br i1 %12, label %31, label %24
24: ; preds = %21
%25 = mul nuw nsw i64 %23, %4
%26 = getelementptr inbounds double, double* %20, i64 %25
%27 = load double, double* %26
%28 = tail call i64 @fabs(double %27)
%29 = sitofp i64 %28 to double
%30 = fadd double %22, %29
store double %30, double* %19
br label %31
31: ; preds = %21, %24
%32 = add nuw nsw i64 %18, 1
%33 = icmp eq i64 %32, %5
br i1 %33, label %13, label %17
34: ; preds = %17, %34
%35 = phi double [ %50, %34 ], [ 0.000000e+00, %17 ]
%36 = phi i64 [ %51, %34 ], [ 0, %17 ]
%37 = phi i64 [ %52, %34 ], [ 0, %17 ]
%38 = mul nuw nsw i64 %36, %4
%39 = getelementptr inbounds double, double* %20, i64 %38
%40 = load double, double* %39
%41 = tail call i64 @fabs(double %40)
%42 = sitofp i64 %41 to double
%43 = fadd double %35, %42
store double %43, double* %19
%44 = or i64 %36, 1
%45 = mul nuw nsw i64 %44, %4
%46 = getelementptr inbounds double, double* %20, i64 %45
%47 = load double, double* %46
%48 = tail call i64 @fabs(double %47)
%49 = sitofp i64 %48 to double
%50 = fadd double %43, %49
store double %50, double* %19
%51 = add nuw nsw i64 %36, 2
%52 = add i64 %37, 2
%53 = icmp eq i64 %52, %11
br i1 %53, label %21, label %34
}