#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 */
double *new_vector(int);
double *compute_initial_gradient(double **X, double *y, int N, int p) {
  int i, j;
  double *g;
  g = new_vector(p);
  for (j = 0; j < p; ++j) {
    for (i = 0; i < N; ++i)
      g[j] += X[i][j] * y[i];
  }
  return g;
}


x86 assembly (clang, -O0):
<compute_initial_gradient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <new_vector@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11b5 <compute_initial_gradient+0xa5>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a2 <compute_initial_gradient+0x92>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114c <compute_initial_gradient+0x3c>
jmp    11a7 <compute_initial_gradient+0x97>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1139 <compute_initial_gradient+0x29>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_initial_gradient>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %ecx,%edi
call   1030 <new_vector@plt>
test   %r15d,%r15d
jle    11ca <compute_initial_gradient+0xba>
mov    %r15d,%r9d
mov    %r14d,%r8d
mov    %r8d,%esi
and    $0xfffffffe,%esi
xor    %edi,%edi
jmp    1159 <compute_initial_gradient+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rdi
cmp    %r9,%rdi
je     11ca <compute_initial_gradient+0xba>
test   %r14d,%r14d
jle    1150 <compute_initial_gradient+0x40>
movsd  (%rax,%rdi,8),%xmm0
xor    %edx,%edx
cmp    $0x1,%r14d
je     11aa <compute_initial_gradient+0x9a>
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp,%rdx,8),%rcx
movsd  (%rcx,%rdi,8),%xmm1
mulsd  (%rbx,%rdx,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rax,%rdi,8)
mov    0x8(%rbp,%rdx,8),%rcx
movsd  (%rcx,%rdi,8),%xmm0
mulsd  0x8(%rbx,%rdx,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rdi,8)
add    $0x2,%rdx
cmp    %rdx,%rsi
jne    1170 <compute_initial_gradient+0x60>
test   $0x1,%r8b
je     1150 <compute_initial_gradient+0x40>
mov    0x0(%rbp,%rdx,8),%rcx
movsd  (%rcx,%rdi,8),%xmm1
mulsd  (%rbx,%rdx,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rax,%rdi,8)
jmp    1150 <compute_initial_gradient+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double* @compute_initial_gradient(double** %0, double* %1, i32 %2, i32 %3) {
%5 = alloca double**
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double*
store double** %0, double*** %5
store double* %1, double** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %8
%13 = call double* @new_vector(i32 %12)
store double* %13, double** %11
store i32 0, i32* %10
br label %14
14: ; preds = %48, %4
%15 = load i32, i32* %10
%16 = load i32, i32* %8
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %51
18: ; preds = %14
store i32 0, i32* %9
br label %19
19: ; preds = %44, %18
%20 = load i32, i32* %9
%21 = load i32, i32* %7
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %47
23: ; preds = %19
%24 = load double**, double*** %5
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double*, double** %24, i64 %26
%28 = load double*, double** %27
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = load double*, double** %6
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = load double, double* %36
%38 = load double*, double** %11
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = call double @llvm.fmuladd.f64(double %32, double %37, double %42)
store double %43, double* %41
br label %44
44: ; preds = %23
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %19
47: ; preds = %19
br label %48
48: ; preds = %47
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
br label %14
51: ; preds = %14
%52 = load double*, double** %11
ret double* %52
}

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