#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 didot(double *, int *, int);
void getGrad(double *Grad, double *x0, double *x, int **A, int numSS,
             int numTotal) {
  int i;
  for (i = 0; i < numSS; i++) {
    Grad[i] = -x0[i] + didot(x, A[i], numTotal);
  }
}


x86 assembly (clang, -O0):
<getGrad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11ab <getGrad+0x9b>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x28(%rbp),%edx
call   1030 <didot@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1137 <getGrad+0x27>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getGrad>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %r8d,%r8d
jle    1173 <getGrad+0x63>
mov    %r9d,%r15d
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %r8d,%eax
mov    %rax,0x8(%rsp)
xor    %r14d,%r14d
nopl   (%rax)
movsd  0x0(%rbp,%r14,8),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    (%r12,%r14,8),%rsi
mov    %r13,%rdi
mov    %r15d,%edx
call   1030 <didot@plt>
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%rbx,%r14,8)
add    $0x1,%r14
cmp    %r14,0x8(%rsp)
jne    1140 <getGrad+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @getGrad(double* %0, double* %1, double* %2, i32** %3, i32 %4, i32 %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32**
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store double* %0, double** %7
store double* %1, double** %8
store double* %2, double** %9
store i32** %3, i32*** %10
store i32 %4, i32* %11
store i32 %5, i32* %12
store i32 0, i32* %13
br label %14
14: ; preds = %38, %6
%15 = load i32, i32* %13
%16 = load i32, i32* %11
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %41
18: ; preds = %14
%19 = load double*, double** %8
%20 = load i32, i32* %13
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = fneg double %23
%25 = load double*, double** %9
%26 = load i32**, i32*** %10
%27 = load i32, i32* %13
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32*, i32** %26, i64 %28
%30 = load i32*, i32** %29
%31 = load i32, i32* %12
%32 = call double @didot(double* %25, i32* %30, i32 %31)
%33 = fadd double %24, %32
%34 = load double*, double** %7
%35 = load i32, i32* %13
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
store double %33, double* %37
br label %38
38: ; preds = %18
%39 = load i32, i32* %13
%40 = add nsw i32 %39, 1
store i32 %40, i32* %13
br label %14
41: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @getGrad(double* nocapture writeonly %0, double* nocapture %1, double* %2, i32** nocapture %3, i32 %4, i32 %5) {
%7 = icmp sgt i32 %4, 0
br i1 %7, label %8, label %21
8: ; preds = %6
%9 = zext i32 %4 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %19, %10 ]
%12 = getelementptr inbounds double, double* %1, i64 %11
%13 = load double, double* %12
%14 = getelementptr inbounds i32*, i32** %3, i64 %11
%15 = load i32*, i32** %14
%16 = tail call double @didot(double* %2, i32* %15, i32 %5)
%17 = fsub double %16, %13
%18 = getelementptr inbounds double, double* %0, i64 %11
store double %17, double* %18
%19 = add nuw nsw i64 %11, 1
%20 = icmp eq i64 %19, %9
br i1 %20, label %21, label %10
21: ; preds = %10, %6
ret void
}