#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 naiseki_double(double *, double *, int);
void calc_kl_component(double *kl, int dim, double *a, double **vec, int n) {
  int d;
  for (d = 0; d < dim; d++)
    kl[d] = naiseki_double(a, (double *)((double *)vec + d * n), n);
}


x86 assembly (clang, -O0):
<calc_kl_component>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1179 <calc_kl_component+0x69>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%eax
imul   -0x24(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x24(%rbp),%edx
call   1030 <naiseki_double@plt>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1132 <calc_kl_component+0x22>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_kl_component>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,0x4(%rsp)
test   %esi,%esi
jle    1161 <calc_kl_component+0x51>
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rdi,%r12
movslq 0x4(%rsp),%rbp
mov    %esi,%r13d
shl    $0x3,%rbp
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    0x4(%rsp),%edx
call   1030 <naiseki_double@plt>
movsd  %xmm0,(%r12,%r14,8)
add    $0x1,%r14
add    %rbp,%rbx
cmp    %r14,%r13
jne    1140 <calc_kl_component+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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