#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 abs(double);
int /*<<< orphan*/ printf(char *, double, double);
double sqrt(double);
double distance(double **r, double *r_distance, double l, int i, int j,
                int dimension) {
  int dim;
  double dist;
  dist = 0;
  for (dim = 0; dim < dimension; dim++) {
    r_distance[dim] = abs(r[i][dim] - r[j][dim]);
    if (r_distance[dim] > l / 2) {
      r_distance[dim] = l - r_distance[dim];
    }
    dist += r_distance[dim] * r_distance[dim];
    printf("wfnew/wfold %12.5E%12.5E\n", dist, r_distance[dim]);
  }
  return sqrt(dist);
}


x86 assembly (clang, -O0):
<distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1245 <distance+0x115>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
call   1030 <abs@plt>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe40(%rip),%xmm2
divsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    11ed <distance+0xbd>
movsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xdd6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    115e <distance+0x2e>
movsd  -0x30(%rbp),%xmm0
call   1050 <sqrt@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
test   %r8d,%r8d
jle    11fb <distance+0xcb>
mov    %rsi,%r14
mov    %rdi,%rbx
movslq %edx,%r12
movslq %ecx,%r13
movsd  0xe96(%rip),%xmm0
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %r8d,%ebp
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx,%r12,8),%rax
movsd  (%rax,%r15,8),%xmm0
mov    (%rbx,%r13,8),%rax
subsd  (%rax,%r15,8),%xmm0
call   1030 <abs@plt>
movsd  0x8(%rsp),%xmm2
subsd  %xmm0,%xmm2
movsd  0x10(%rsp),%xmm1
cmpltsd %xmm0,%xmm1
andpd  %xmm1,%xmm2
andnpd %xmm0,%xmm1
orpd   %xmm2,%xmm1
movlpd %xmm1,(%r14,%r15,8)
movapd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
movsd  (%rsp),%xmm0
addsd  %xmm2,%xmm0
lea    0xe28(%rip),%rdi
movsd  %xmm0,(%rsp)
call   1040 <printf@plt>
add    $0x1,%r15
cmp    %r15,%rbp
jne    1190 <distance+0x60>
movsd  (%rsp),%xmm0
ucomisd 0xe00(%rip),%xmm0
jb     121d <distance+0xed>
sqrtsd %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <sqrt@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"wfnew/wfold %12.5E%12.5E\0A\00"
define double @distance(double** %0, double* %1, double %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca double**
%8 = alloca double*
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
store double** %0, double*** %7
store double* %1, double** %8
store double %2, double* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
store double 0.000000e+00, double* %14
store i32 0, i32* %13
br label %15
15: ; preds = %84, %6
%16 = load i32, i32* %13
%17 = load i32, i32* %12
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %87
19: ; preds = %15
%20 = load double**, double*** %7
%21 = load i32, i32* %10
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double*, double** %20, i64 %22
%24 = load double*, double** %23
%25 = load i32, i32* %13
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
%28 = load double, double* %27
%29 = load double**, double*** %7
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double*, double** %29, i64 %31
%33 = load double*, double** %32
%34 = load i32, i32* %13
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = load double, double* %36
%38 = fsub double %28, %37
%39 = call double @abs(double %38)
%40 = load double*, double** %8
%41 = load i32, i32* %13
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
store double %39, double* %43
%44 = load double*, double** %8
%45 = load i32, i32* %13
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = load double, double* %47
%49 = load double, double* %9
%50 = fdiv double %49, 2.000000e+00
%51 = fcmp ogt double %48, %50
br i1 %51, label %52, label %64
52: ; preds = %19
%53 = load double, double* %9
%54 = load double*, double** %8
%55 = load i32, i32* %13
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %54, i64 %56
%58 = load double, double* %57
%59 = fsub double %53, %58
%60 = load double*, double** %8
%61 = load i32, i32* %13
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %60, i64 %62
store double %59, double* %63
br label %64
64: ; preds = %52, %19
%65 = load double*, double** %8
%66 = load i32, i32* %13
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %65, i64 %67
%69 = load double, double* %68
%70 = load double*, double** %8
%71 = load i32, i32* %13
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %70, i64 %72
%74 = load double, double* %73
%75 = load double, double* %14
%76 = call double @llvm.fmuladd.f64(double %69, double %74, double %75)
store double %76, double* %14
%77 = load double, double* %14
%78 = load double*, double** %8
%79 = load i32, i32* %13
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds double, double* %78, i64 %80
%82 = load double, double* %81
%83 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double %77, double %82)
br label %84
84: ; preds = %64
%85 = load i32, i32* %13
%86 = add nsw i32 %85, 1
store i32 %86, i32* %13
br label %15
87: ; preds = %15
%88 = load double, double* %14
%89 = call double @sqrt(double %88)
ret double %89
}

LLVM IR (-O2):
@.str = [26 x i8] c"wfnew/wfold %12.5E%12.5E\0A\00"
define double @distance(double** nocapture %0, double* nocapture writeonly %1, double %2, i32 %3, i32 %4, i32 %5) {
%7 = icmp sgt i32 %5, 0
br i1 %7, label %8, label %34
8: ; preds = %6
%9 = sext i32 %3 to i64
%10 = getelementptr inbounds double*, double** %0, i64 %9
%11 = sext i32 %4 to i64
%12 = getelementptr inbounds double*, double** %0, i64 %11
%13 = fmul double %2, 5.000000e-01
%14 = zext i32 %5 to i64
br label %15
15: ; preds = %8, %15
%16 = phi i64 [ 0, %8 ], [ %32, %15 ]
%17 = phi double [ 0.000000e+00, %8 ], [ %30, %15 ]
%18 = load double*, double** %10
%19 = getelementptr inbounds double, double* %18, i64 %16
%20 = load double, double* %19
%21 = load double*, double** %12
%22 = getelementptr inbounds double, double* %21, i64 %16
%23 = load double, double* %22
%24 = fsub double %20, %23
%25 = tail call double @abs(double %24)
%26 = getelementptr inbounds double, double* %1, i64 %16
%27 = fcmp ogt double %25, %13
%28 = fsub double %2, %25
%29 = select i1 %27, double %28, double %25
store double %29, double* %26
%30 = tail call double @llvm.fmuladd.f64(double %29, double %29, double %17)
%31 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), double %30, double %29)
%32 = add nuw nsw i64 %16, 1
%33 = icmp eq i64 %32, %14
br i1 %33, label %34, label %15
34: ; preds = %15, %6
%35 = phi double [ 0.000000e+00, %6 ], [ %30, %15 ]
%36 = tail call double @sqrt(double %35)
ret double %36
}