#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 hamming_distance(double const *, double const *, int);
void pdist_hamming(const double *X, double *dm, int m, int n) {
  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 = hamming_distance(u, v, n);
    }
  }
}


x86 assembly (clang, -O0):
<pdist_hamming>:
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    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11cd <pdist_hamming+0xbd>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ba <pdist_hamming+0xaa>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
imul   -0x20(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <hamming_distance@plt>
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x38(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
jmp    114a <pdist_hamming+0x3a>
jmp    11bf <pdist_hamming+0xaf>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1135 <pdist_hamming+0x25>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pdist_hamming>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,0x8(%rsp)
test   %edx,%edx
jle    11d6 <pdist_hamming+0xc6>
mov    %ecx,%r14d
mov    %rsi,%rbx
movslq %ecx,%rsi
mov    %edx,%r15d
mov    0x8(%rsp),%rax
lea    (%rax,%rsi,8),%rbp
mov    %rsi,0x10(%rsp)
lea    0x0(,%rsi,8),%r13
mov    $0x1,%r12d
xor    %eax,%eax
mov    %r15,0x18(%rsp)
jmp    117b <pdist_hamming+0x6b>
nopl   0x0(%rax)
add    $0x1,%r12
mov    0x28(%rsp),%rbp
add    %r13,%rbp
mov    0x18(%rsp),%r15
mov    0x20(%rsp),%rax
cmp    %r15,%rax
je     11d6 <pdist_hamming+0xc6>
lea    0x1(%rax),%rdx
cmp    %r15,%rdx
mov    %rbp,0x28(%rsp)
mov    %rdx,0x20(%rsp)
jae    1160 <pdist_hamming+0x50>
imul   0x10(%rsp),%rax
mov    0x8(%rsp),%rdx
lea    (%rdx,%rax,8),%rax
mov    %rax,0x30(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x30(%rsp),%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1030 <hamming_distance@plt>
movsd  %xmm0,(%rbx)
add    $0x8,%rbx
add    %r13,%rbp
add    $0xffffffffffffffff,%r15
cmp    %r15,%r12
jne    11b0 <pdist_hamming+0xa0>
jmp    1160 <pdist_hamming+0x50>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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