#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 cosine_distance(double const *, double const *, int, double const,
                       double const);
void pdist_cosine(const double *X, double *dm, int m, int n,
                  const double *norms) {
  int i, j;
  const double *u, *v;
  double *it = dm;
  for (i = 0; i < m; i++) {
    for (j = i + 1; j < m; j++, it++) {
      u = X + (n * i);
      v = X + (n * j);
      *it = cosine_distance(u, v, n, norms[i], norms[j]);
    }
  }
}


x86 assembly (clang, -O0):
<pdist_cosine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11eb <pdist_cosine+0xdb>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d8 <pdist_cosine+0xc8>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
imul   -0x24(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%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    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
call   1030 <cosine_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    114e <pdist_cosine+0x3e>
jmp    11dd <pdist_cosine+0xcd>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1139 <pdist_cosine+0x29>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pdist_cosine>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdi,0x8(%rsp)
test   %edx,%edx
jle    1200 <pdist_cosine+0xf0>
mov    %r8,%r12
mov    %ecx,%r14d
mov    %rsi,%rbp
movslq %ecx,%rsi
mov    %edx,%edi
mov    0x8(%rsp),%rax
lea    (%rax,%rsi,8),%rbx
mov    %rsi,0x18(%rsp)
lea    0x0(,%rsi,8),%r13
mov    $0x1,%r15d
xor    %eax,%eax
mov    %rdi,0x38(%rsp)
jmp    117f <pdist_cosine+0x6f>
xchg   %ax,%ax
mov    0x28(%rsp),%r15
add    $0x1,%r15
mov    0x30(%rsp),%rbx
add    %r13,%rbx
mov    0x20(%rsp),%rax
cmp    %rdi,%rax
je     1200 <pdist_cosine+0xf0>
mov    %rax,%rdx
mov    %rax,0x10(%rsp)
add    $0x1,%rax
cmp    %rdi,%rax
mov    %rbx,0x30(%rsp)
mov    %r15,0x28(%rsp)
mov    %rax,0x20(%rsp)
jae    1160 <pdist_cosine+0x50>
mov    0x10(%rsp),%rax
imul   0x18(%rsp),%rax
mov    0x8(%rsp),%rdx
lea    (%rdx,%rax,8),%rax
mov    %rax,0x40(%rsp)
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
movsd  (%r12,%rax,8),%xmm0
movsd  (%r12,%r15,8),%xmm1
mov    0x40(%rsp),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <cosine_distance@plt>
mov    0x38(%rsp),%rdi
movsd  %xmm0,0x0(%rbp)
add    $0x1,%r15
add    $0x8,%rbp
add    %r13,%rbx
cmp    %r15,%rdi
jne    11c0 <pdist_cosine+0xb0>
jmp    1160 <pdist_cosine+0x50>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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