#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);
int /*<<< orphan*/ squared_distance_matrix(double const *, double const *,
                                           double const *, int, int, int,
                                           double *);
void distance_matrix(const double *X, const double *Y, const double *g, int m,
                     int n, int d, double *dist) {
  int i;
  squared_distance_matrix(X, Y, g, m, n, d, dist);
  for (i = 0; i < m * n; ++i) {
    dist[i] = sqrt(dist[i]);
  }
}


x86 assembly (clang, -O0):
<distance_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x24(%rbp),%r9d
mov    0x10(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <squared_distance_matrix@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
cmp    %ecx,%eax
jge    11ad <distance_matrix+0x8d>
mov    0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <sqrt@plt>
mov    0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    116e <distance_matrix+0x4e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance_matrix>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%ebx
mov    %ecx,%r14d
mov    0x30(%rsp),%rbp
mov    %rbp,(%rsp)
call   1030 <squared_distance_matrix@plt>
imul   %r14d,%ebx
test   %ebx,%ebx
jle    11a8 <distance_matrix+0x88>
mov    %ebx,%r15d
lea    -0x1(%r15),%rax
mov    %r15d,%r14d
and    $0x3,%r14d
cmp    $0x3,%rax
jae    11b3 <distance_matrix+0x93>
xor    %ebx,%ebx
test   %r14,%r14
je     11a8 <distance_matrix+0x88>
lea    0x0(,%rbx,8),%rbx
add    %rbp,%rbx
xor    %ebp,%ebp
xorpd  %xmm1,%xmm1
jmp    1197 <distance_matrix+0x77>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1040 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r14
je     11a8 <distance_matrix+0x88>
movsd  (%rbx,%rbp,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1180 <distance_matrix+0x60>
sqrtsd %xmm0,%xmm0
jmp    1189 <distance_matrix+0x69>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
and    $0xfffffffc,%r15d
xor    %ebx,%ebx
xorpd  %xmm1,%xmm1
jmp    11d8 <distance_matrix+0xb8>
nop
call   1040 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x18(%rbp,%rbx,8)
add    $0x4,%rbx
cmp    %rbx,%r15
je     1159 <distance_matrix+0x39>
movsd  0x0(%rbp,%rbx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     11f0 <distance_matrix+0xd0>
sqrtsd %xmm0,%xmm0
jmp    11f9 <distance_matrix+0xd9>
nopw   0x0(%rax,%rax,1)
call   1040 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x0(%rbp,%rbx,8)
movsd  0x8(%rbp,%rbx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1220 <distance_matrix+0x100>
sqrtsd %xmm0,%xmm0
jmp    1229 <distance_matrix+0x109>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1040 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x8(%rbp,%rbx,8)
movsd  0x10(%rbp,%rbx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1250 <distance_matrix+0x130>
sqrtsd %xmm0,%xmm0
jmp    1259 <distance_matrix+0x139>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1040 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x10(%rbp,%rbx,8)
movsd  0x18(%rbp,%rbx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     11c0 <distance_matrix+0xa0>
sqrtsd %xmm0,%xmm0
jmp    11c9 <distance_matrix+0xa9>

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

LLVM IR (-O2):
define void @distance_matrix(double* %0, double* %1, double* %2, i32 %3, i32 %4, i32 %5, double* %6) {
%8 = tail call i32 @squared_distance_matrix(double* %0, double* %1, double* %2, i32 %3, i32 %4, i32 %5, double* %6)
%9 = mul i32 %4, %3
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %51
11: ; preds = %7
%12 = zext i32 %9 to i64
%13 = add nsw i64 %12, -1
%14 = and i64 %12, 3
%15 = icmp ult i64 %13, 3
br i1 %15, label %39, label %16
16: ; preds = %11
%17 = and i64 %12, 4294967292
br label %18
18: ; preds = %18, %16
%19 = phi i64 [ 0, %16 ], [ %36, %18 ]
%20 = phi i64 [ 0, %16 ], [ %37, %18 ]
%21 = getelementptr inbounds double, double* %6, i64 %19
%22 = load double, double* %21
%23 = tail call double @sqrt(double %22)
store double %23, double* %21
%24 = or i64 %19, 1
%25 = getelementptr inbounds double, double* %6, i64 %24
%26 = load double, double* %25
%27 = tail call double @sqrt(double %26)
store double %27, double* %25
%28 = or i64 %19, 2
%29 = getelementptr inbounds double, double* %6, i64 %28
%30 = load double, double* %29
%31 = tail call double @sqrt(double %30)
store double %31, double* %29
%32 = or i64 %19, 3
%33 = getelementptr inbounds double, double* %6, i64 %32
%34 = load double, double* %33
%35 = tail call double @sqrt(double %34)
store double %35, double* %33
%36 = add nuw nsw i64 %19, 4
%37 = add i64 %20, 4
%38 = icmp eq i64 %37, %17
br i1 %38, label %39, label %18
39: ; preds = %18, %11
%40 = phi i64 [ 0, %11 ], [ %36, %18 ]
%41 = icmp eq i64 %14, 0
br i1 %41, label %51, label %42
42: ; preds = %39, %42
%43 = phi i64 [ %48, %42 ], [ %40, %39 ]
%44 = phi i64 [ %49, %42 ], [ 0, %39 ]
%45 = getelementptr inbounds double, double* %6, i64 %43
%46 = load double, double* %45
%47 = tail call double @sqrt(double %46)
store double %47, double* %45
%48 = add nuw nsw i64 %43, 1
%49 = add i64 %44, 1
%50 = icmp eq i64 %49, %14
br i1 %50, label %51, label %42
51: ; preds = %39, %42, %7
ret void
}