#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 */
scalar_t__ square(int /*<<< orphan*/);
double distance(double *c1, double *c2, int dim) {
  double distance = 0;
  while (dim-- > 0) {
    distance += square(*c1++ - *c2++);
  }
  return distance;
}


x86 assembly (clang, -O0):
<distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jle    1182 <distance+0x72>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
subsd  (%rax),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <square@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    112b <distance+0x1b>
movsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    1173 <distance+0x63>
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
add    $0x1,%ebp
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
movsd  (%r15,%rbx,1),%xmm0
subsd  (%r14,%rbx,1),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <square@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    $0xffffffff,%ebp
add    $0x8,%rbx
cmp    $0x1,%ebp
ja     1130 <distance+0x20>
jmp    1176 <distance+0x66>
xorps  %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @distance(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %7
br label %8
8: ; preds = %12, %3
%9 = load i32, i32* %6
%10 = add nsw i32 %9, -1
store i32 %10, i32* %6
%11 = icmp sgt i32 %9, 0
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = load double*, double** %4
%14 = getelementptr inbounds double, double* %13, i32 1
store double* %14, double** %4
%15 = load double, double* %13
%16 = load double*, double** %5
%17 = getelementptr inbounds double, double* %16, i32 1
store double* %17, double** %5
%18 = load double, double* %16
%19 = fsub double %15, %18
%20 = fptosi double %19 to i32
%21 = call i64 @square(i32 %20)
%22 = sitofp i64 %21 to double
%23 = load double, double* %7
%24 = fadd double %23, %22
store double %24, double* %7
br label %8
25: ; preds = %8
%26 = load double, double* %7
ret double %26
}

LLVM IR (-O2):
define double @distance(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %21
5: ; preds = %3, %5
%6 = phi double [ %19, %5 ], [ 0.000000e+00, %3 ]
%7 = phi i32 [ %10, %5 ], [ %2, %3 ]
%8 = phi double* [ %13, %5 ], [ %1, %3 ]
%9 = phi double* [ %11, %5 ], [ %0, %3 ]
%10 = add nsw i32 %7, -1
%11 = getelementptr inbounds double, double* %9, i64 1
%12 = load double, double* %9
%13 = getelementptr inbounds double, double* %8, i64 1
%14 = load double, double* %8
%15 = fsub double %12, %14
%16 = fptosi double %15 to i32
%17 = tail call i64 @square(i32 %16)
%18 = sitofp i64 %17 to double
%19 = fadd double %6, %18
%20 = icmp ugt i32 %7, 1
br i1 %20, label %5, label %21
21: ; preds = %5, %3
%22 = phi double [ 0.000000e+00, %3 ], [ %19, %5 ]
ret double %22
}