#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 sqrt(double const);
void scale_eigvec_grid(double *restrict out, int tsID, int npack,
                       const int *restrict pack, const double *restrict weight,
                       double **covar, double sum_w) {
  for (int i = 0; i < npack; ++i)
    out[pack[i]] = covar[tsID][i] / sqrt(weight[pack[i]] / sum_w);
}


x86 assembly (clang, -O0):
<scale_eigvec_grid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11ae <scale_eigvec_grid+0x9e>
mov    -0x28(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x34(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x30(%rbp),%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x34(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    113a <scale_eigvec_grid+0x2a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scale_eigvec_grid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %edx,%edx
jle    11bd <scale_eigvec_grid+0xad>
movapd %xmm0,%xmm1
mov    %r9,%r12
mov    %rcx,%rbx
mov    %rdi,%rbp
movslq %esi,%r13
mov    %edx,%edx
xor    %r14d,%r14d
xorpd  %xmm2,%xmm2
movsd  %xmm0,0x18(%rsp)
mov    %r8,0x10(%rsp)
mov    %rdx,0x8(%rsp)
jmp    1199 <scale_eigvec_grid+0x89>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm3,0x20(%rsp)
call   1030 <sqrt@plt>
movsd  0x20(%rsp),%xmm3
xorpd  %xmm2,%xmm2
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%r8
movsd  0x18(%rsp),%xmm1
divsd  %xmm0,%xmm3
movsd  %xmm3,0x0(%rbp,%r15,8)
add    $0x1,%r14
cmp    %r14,%rdx
je     11bd <scale_eigvec_grid+0xad>
mov    (%r12,%r13,8),%rax
movsd  (%rax,%r14,8),%xmm3
movslq (%rbx,%r14,4),%r15
movsd  (%r8,%r15,8),%xmm0
divsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     1160 <scale_eigvec_grid+0x50>
sqrtsd %xmm0,%xmm0
jmp    1185 <scale_eigvec_grid+0x75>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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