#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 */
int /*<<< orphan*/ free(double *);
double mahalanobis_distance(double const *, double const *, double const *,
                            double *, double *, int);
scalar_t__ malloc(int);
void pdist_mahalanobis(const double *X, const double *covinv, double *dm, int m,
                       int n) {
  int i, j;
  const double *u, *v;
  double *it = dm;
  double *dimbuf1, *dimbuf2;
  dimbuf1 = (double *)malloc(sizeof(double) * 2 * n);
  dimbuf2 = dimbuf1 + n;
  for (i = 0; i < m; i++) {
    for (j = i + 1; j < m; j++, it++) {
      u = X + (n * i);
      v = X + (n * j);
      *it = mahalanobis_distance(u, v, covinv, dimbuf1, dimbuf2, n);
    }
  }
  dimbuf2 = 0;
  free(dimbuf1);
}


x86 assembly (clang, -O0):
<pdist_mahalanobis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x4,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movslq -0x20(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1225 <pdist_mahalanobis+0xf5>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1212 <pdist_mahalanobis+0xe2>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x24(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x28(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%r8
mov    -0x20(%rbp),%r9d
call   1040 <mahalanobis_distance@plt>
mov    -0x40(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x40(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x40(%rbp)
jmp    1195 <pdist_mahalanobis+0x65>
jmp    1217 <pdist_mahalanobis+0xe7>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1180 <pdist_mahalanobis+0x50>
movq   $0x0,-0x50(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pdist_mahalanobis>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8d,%r12d
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rsi,%r13
mov    %rdi,(%rsp)
mov    %r8d,%edi
shl    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r9
test   %r14d,%r14d
jle    123f <pdist_mahalanobis+0x10f>
movslq %r12d,%rcx
lea    (%r9,%rcx,8),%r15
mov    %r14d,%ebp
mov    (%rsp),%rax
lea    (%rax,%rcx,8),%r14
mov    %rcx,0x8(%rsp)
lea    0x0(,%rcx,8),%rdx
mov    $0x1,%esi
xor    %eax,%eax
mov    %rbp,0x10(%rsp)
mov    %r13,0x28(%rsp)
jmp    11bf <pdist_mahalanobis+0x8f>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rsi
mov    0x20(%rsp),%r14
add    %rdx,%r14
mov    0x10(%rsp),%rbp
mov    0x18(%rsp),%rax
cmp    %rbp,%rax
je     123f <pdist_mahalanobis+0x10f>
lea    0x1(%rax),%rcx
cmp    %rbp,%rcx
mov    %r14,0x20(%rsp)
mov    %rcx,0x18(%rsp)
jae    11a0 <pdist_mahalanobis+0x70>
imul   0x8(%rsp),%rax
mov    (%rsp),%rcx
lea    (%rcx,%rax,8),%rax
mov    %rax,0x30(%rsp)
mov    %rsi,0x38(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %rbx,0x40(%rsp)
mov    0x30(%rsp),%rdi
mov    %r14,%rsi
mov    %rdx,%rbx
mov    0x28(%rsp),%rdx
mov    %r9,%rcx
mov    %r9,%r13
mov    %r15,%r8
mov    %r12d,%r9d
call   1040 <mahalanobis_distance@plt>
mov    0x38(%rsp),%rsi
mov    %rbx,%rdx
mov    0x40(%rsp),%rbx
mov    %r13,%r9
movsd  %xmm0,(%rbx)
add    $0x8,%rbx
add    %rdx,%r14
add    $0xffffffffffffffff,%rbp
cmp    %rbp,%rsi
jne    11f0 <pdist_mahalanobis+0xc0>
jmp    11a0 <pdist_mahalanobis+0x70>
mov    %r9,%rdi
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @pdist_mahalanobis(double* %0, double* %1, double* %2, i32 %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca double*
%14 = alloca double*
%15 = alloca double*
%16 = alloca double*
%17 = alloca double*
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%18 = load double*, double** %8
store double* %18, double** %15
%19 = load i32, i32* %10
%20 = sext i32 %19 to i64
%21 = mul i64 16, %20
%22 = trunc i64 %21 to i32
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to double*
store double* %24, double** %16
%25 = load double*, double** %16
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
store double* %28, double** %17
store i32 0, i32* %11
br label %29
29: ; preds = %67, %5
%30 = load i32, i32* %11
%31 = load i32, i32* %9
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %70
33: ; preds = %29
%34 = load i32, i32* %11
%35 = add nsw i32 %34, 1
store i32 %35, i32* %12
br label %36
36: ; preds = %61, %33
%37 = load i32, i32* %12
%38 = load i32, i32* %9
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %66
40: ; preds = %36
%41 = load double*, double** %6
%42 = load i32, i32* %10
%43 = load i32, i32* %11
%44 = mul nsw i32 %42, %43
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %41, i64 %45
store double* %46, double** %13
%47 = load double*, double** %6
%48 = load i32, i32* %10
%49 = load i32, i32* %12
%50 = mul nsw i32 %48, %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %47, i64 %51
store double* %52, double** %14
%53 = load double*, double** %13
%54 = load double*, double** %14
%55 = load double*, double** %7
%56 = load double*, double** %16
%57 = load double*, double** %17
%58 = load i32, i32* %10
%59 = call double @mahalanobis_distance(double* %53, double* %54, double* %55, double* %56, double* %57, i32 %58)
%60 = load double*, double** %15
store double %59, double* %60
br label %61
61: ; preds = %40
%62 = load i32, i32* %12
%63 = add nsw i32 %62, 1
store i32 %63, i32* %12
%64 = load double*, double** %15
%65 = getelementptr inbounds double, double* %64, i32 1
store double* %65, double** %15
br label %36
66: ; preds = %36
br label %67
67: ; preds = %66
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 1
store i32 %69, i32* %11
br label %29
70: ; preds = %29
store double* null, double** %17
%71 = load double*, double** %16
%72 = call i32 @free(double* %71)
ret void
}

LLVM IR (-O2):
define void @pdist_mahalanobis(double* %0, double* %1, double* nocapture writeonly %2, i32 %3, i32 %4) {
%6 = sext i32 %4 to i64
%7 = shl i32 %4, 4
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to double*
%10 = getelementptr inbounds double, double* %9, i64 %6
%11 = icmp sgt i32 %3, 0
br i1 %11, label %12, label %37
12: ; preds = %5
%13 = zext i32 %3 to i64
%14 = zext i32 %3 to i64
br label %19
15: ; preds = %28, %19
%16 = phi double* [ %22, %19 ], [ %35, %28 ]
%17 = add nuw nsw i64 %21, 1
%18 = icmp eq i64 %23, %14
br i1 %18, label %37, label %19
19: ; preds = %12, %15
%20 = phi i64 [ 0, %12 ], [ %23, %15 ]
%21 = phi i64 [ 1, %12 ], [ %17, %15 ]
%22 = phi double* [ %2, %12 ], [ %16, %15 ]
%23 = add nuw nsw i64 %20, 1
%24 = icmp ult i64 %23, %13
br i1 %24, label %25, label %15
25: ; preds = %19
%26 = mul nsw i64 %20, %6
%27 = getelementptr inbounds double, double* %0, i64 %26
br label %28
28: ; preds = %25, %28
%29 = phi i64 [ %21, %25 ], [ %34, %28 ]
%30 = phi double* [ %22, %25 ], [ %35, %28 ]
%31 = mul nsw i64 %29, %6
%32 = getelementptr inbounds double, double* %0, i64 %31
%33 = tail call double @mahalanobis_distance(double* %27, double* %32, double* %1, double* %9, double* %10, i32 %4)
store double %33, double* %30
%34 = add nuw nsw i64 %29, 1
%35 = getelementptr inbounds double, double* %30, i64 1
%36 = icmp eq i64 %34, %14
br i1 %36, label %15, label %28
37: ; preds = %15, %5
%38 = tail call i32 @free(double* %9)
ret void
}