#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__ fabs(double);
void closerFurther(double *valueArray, double *targetArray, double *lastValues,
                   double *closestValues, int valueArrayCnt, double tolerance,
                   int *valueIsCloserArray, int *valueIsMostClosestArray,
                   double *valueToTargetSum) {
  int i;
  *valueToTargetSum = 0.0;
  for (i = 0; i < valueArrayCnt; i++) {
    *valueToTargetSum += fabs(targetArray[i] - valueArray[i]);
    if ((valueArray[i] + tolerance >= targetArray[i]) &&
        (valueArray[i] - tolerance <= targetArray[i])) {
      valueIsCloserArray[i] = -1;
      closestValues[i] = valueArray[i];
      valueIsMostClosestArray[i] = -1;
    } else {
      if (fabs(targetArray[i] - valueArray[i]) <
          fabs(targetArray[i] - lastValues[i]))
        valueIsCloserArray[i] = 1;
      else
        valueIsCloserArray[i] = 0;
      if (fabs(targetArray[i] - valueArray[i]) <
          fabs(targetArray[i] - closestValues[i])) {
        closestValues[i] = valueArray[i];
        valueIsMostClosestArray[i] = 1;
      } else {
        valueIsMostClosestArray[i] = 0;
      }
    }
    lastValues[i] = valueArray[i];
  }
}


x86 assembly (clang, -O0):
<closerFurther>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movsd  %xmm0,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1347 <closerFurther+0x237>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %rax,%xmm0
mov    0x18(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
ucomisd (%rax,%rcx,8),%xmm0
jb     1216 <closerFurther+0x106>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
subsd  -0x30(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1216 <closerFurther+0x106>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
jmp    131f <closerFurther+0x20f>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
call   1030 <fabs@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
cmp    %rcx,%rax
jge    127c <closerFurther+0x16c>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    128b <closerFurther+0x17b>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
call   1030 <fabs@plt>
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
cmp    %rcx,%rax
jge    130b <closerFurther+0x1fb>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    131a <closerFurther+0x20a>
mov    0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    131f <closerFurther+0x20f>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    114f <closerFurther+0x3f>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<closerFurther>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,0x8(%rsp)
movsd  %xmm0,0x20(%rsp)
mov    %rcx,(%rsp)
mov    %rdx,0x10(%rsp)
mov    0x68(%rsp),%rbp
movq   $0x0,0x0(%rbp)
test   %r8d,%r8d
jle    128a <closerFurther+0x17a>
mov    %rsi,%r13
mov    %rdi,%rbx
mov    0x60(%rsp),%r15
mov    %r8d,%r12d
xor    %r14d,%r14d
mov    %r12,0x18(%rsp)
jmp    119e <closerFurther+0x8e>
mov    0x8(%rsp),%rax
movl   $0xffffffff,(%rax,%r14,4)
ff
mov    (%rsp),%rax
movsd  %xmm1,(%rax,%r14,8)
mov    $0xffffffff,%ecx
mov    %ecx,(%r15,%r14,4)
movsd  (%rbx,%r14,8),%xmm0
mov    0x10(%rsp),%rax
movsd  %xmm0,(%rax,%r14,8)
add    $0x1,%r14
cmp    %r14,%r12
je     128a <closerFurther+0x17a>
movsd  0x0(%r13,%r14,8),%xmm0
subsd  (%rbx,%r14,8),%xmm0
call   1030 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x0(%rbp),%xmm0
movsd  %xmm0,0x0(%rbp)
movsd  (%rbx,%r14,8),%xmm1
movapd %xmm1,%xmm2
movsd  0x20(%rsp),%xmm3
addsd  %xmm3,%xmm2
movsd  0x0(%r13,%r14,8),%xmm0
ucomisd %xmm0,%xmm2
jb     11f5 <closerFurther+0xe5>
movapd %xmm1,%xmm2
subsd  %xmm3,%xmm2
ucomisd %xmm2,%xmm0
jae    1160 <closerFurther+0x50>
subsd  %xmm1,%xmm0
call   1030 <fabs@plt>
mov    %r15,%r12
mov    %rbp,%r15
mov    %rax,%rbp
movsd  0x0(%r13,%r14,8),%xmm0
mov    0x10(%rsp),%rax
subsd  (%rax,%r14,8),%xmm0
call   1030 <fabs@plt>
xor    %ecx,%ecx
cmp    %rax,%rbp
setl   %cl
mov    0x8(%rsp),%rax
mov    %ecx,(%rax,%r14,4)
movsd  0x0(%r13,%r14,8),%xmm0
subsd  (%rbx,%r14,8),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rbp
movsd  0x0(%r13,%r14,8),%xmm0
mov    (%rsp),%rax
subsd  (%rax,%r14,8),%xmm0
call   1030 <fabs@plt>
xor    %ecx,%ecx
cmp    %rax,%rbp
mov    %r15,%rbp
mov    %r12,%r15
mov    0x18(%rsp),%r12
jge    117c <closerFurther+0x6c>
movsd  (%rbx,%r14,8),%xmm0
mov    (%rsp),%rax
movsd  %xmm0,(%rax,%r14,8)
mov    $0x1,%ecx
jmp    117c <closerFurther+0x6c>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @closerFurther(double* %0, double* %1, double* %2, double* %3, i32 %4, double %5, i32* %6, i32* %7, double* %8) {
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca i32
%15 = alloca double
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca double*
%19 = alloca i32
store double* %0, double** %10
store double* %1, double** %11
store double* %2, double** %12
store double* %3, double** %13
store i32 %4, i32* %14
store double %5, double* %15
store i32* %6, i32** %16
store i32* %7, i32** %17
store double* %8, double** %18
%20 = load double*, double** %18
store double 0.000000e+00, double* %20
store i32 0, i32* %19
br label %21
21: ; preds = %179, %9
%22 = load i32, i32* %19
%23 = load i32, i32* %14
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %182
25: ; preds = %21
%26 = load double*, double** %11
%27 = load i32, i32* %19
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = load double*, double** %10
%32 = load i32, i32* %19
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = fsub double %30, %35
%37 = call i64 @fabs(double %36)
%38 = sitofp i64 %37 to double
%39 = load double*, double** %18
%40 = load double, double* %39
%41 = fadd double %40, %38
store double %41, double* %39
%42 = load double*, double** %10
%43 = load i32, i32* %19
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
%46 = load double, double* %45
%47 = load double, double* %15
%48 = fadd double %46, %47
%49 = load double*, double** %11
%50 = load i32, i32* %19
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %49, i64 %51
%53 = load double, double* %52
%54 = fcmp oge double %48, %53
br i1 %54, label %55, label %87
55: ; preds = %25
%56 = load double*, double** %10
%57 = load i32, i32* %19
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
%60 = load double, double* %59
%61 = load double, double* %15
%62 = fsub double %60, %61
%63 = load double*, double** %11
%64 = load i32, i32* %19
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
%67 = load double, double* %66
%68 = fcmp ole double %62, %67
br i1 %68, label %69, label %87
69: ; preds = %55
%70 = load i32*, i32** %16
%71 = load i32, i32* %19
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %70, i64 %72
store i32 -1, i32* %73
%74 = load double*, double** %10
%75 = load i32, i32* %19
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %74, i64 %76
%78 = load double, double* %77
%79 = load double*, double** %13
%80 = load i32, i32* %19
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds double, double* %79, i64 %81
store double %78, double* %82
%83 = load i32*, i32** %17
%84 = load i32, i32* %19
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i32, i32* %83, i64 %85
store i32 -1, i32* %86
br label %169
87: ; preds = %55, %25
%88 = load double*, double** %11
%89 = load i32, i32* %19
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds double, double* %88, i64 %90
%92 = load double, double* %91
%93 = load double*, double** %10
%94 = load i32, i32* %19
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds double, double* %93, i64 %95
%97 = load double, double* %96
%98 = fsub double %92, %97
%99 = call i64 @fabs(double %98)
%100 = load double*, double** %11
%101 = load i32, i32* %19
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds double, double* %100, i64 %102
%104 = load double, double* %103
%105 = load double*, double** %12
%106 = load i32, i32* %19
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds double, double* %105, i64 %107
%109 = load double, double* %108
%110 = fsub double %104, %109
%111 = call i64 @fabs(double %110)
%112 = icmp slt i64 %99, %111
br i1 %112, label %113, label %118
113: ; preds = %87
%114 = load i32*, i32** %16
%115 = load i32, i32* %19
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i32, i32* %114, i64 %116
store i32 1, i32* %117
br label %123
118: ; preds = %87
%119 = load i32*, i32** %16
%120 = load i32, i32* %19
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i32, i32* %119, i64 %121
store i32 0, i32* %122
br label %123
123: ; preds = %118, %113
%124 = load double*, double** %11
%125 = load i32, i32* %19
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds double, double* %124, i64 %126
%128 = load double, double* %127
%129 = load double*, double** %10
%130 = load i32, i32* %19
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds double, double* %129, i64 %131
%133 = load double, double* %132
%134 = fsub double %128, %133
%135 = call i64 @fabs(double %134)
%136 = load double*, double** %11
%137 = load i32, i32* %19
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds double, double* %136, i64 %138
%140 = load double, double* %139
%141 = load double*, double** %13
%142 = load i32, i32* %19
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds double, double* %141, i64 %143
%145 = load double, double* %144
%146 = fsub double %140, %145
%147 = call i64 @fabs(double %146)
%148 = icmp slt i64 %135, %147
br i1 %148, label %149, label %163
149: ; preds = %123
%150 = load double*, double** %10
%151 = load i32, i32* %19
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds double, double* %150, i64 %152
%154 = load double, double* %153
%155 = load double*, double** %13
%156 = load i32, i32* %19
%157 = sext i32 %156 to i64
%158 = getelementptr inbounds double, double* %155, i64 %157
store double %154, double* %158
%159 = load i32*, i32** %17
%160 = load i32, i32* %19
%161 = sext i32 %160 to i64
%162 = getelementptr inbounds i32, i32* %159, i64 %161
store i32 1, i32* %162
br label %168
163: ; preds = %123
%164 = load i32*, i32** %17
%165 = load i32, i32* %19
%166 = sext i32 %165 to i64
%167 = getelementptr inbounds i32, i32* %164, i64 %166
store i32 0, i32* %167
br label %168
168: ; preds = %163, %149
br label %169
169: ; preds = %168, %69
%170 = load double*, double** %10
%171 = load i32, i32* %19
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds double, double* %170, i64 %172
%174 = load double, double* %173
%175 = load double*, double** %12
%176 = load i32, i32* %19
%177 = sext i32 %176 to i64
%178 = getelementptr inbounds double, double* %175, i64 %177
store double %174, double* %178
br label %179
179: ; preds = %169
%180 = load i32, i32* %19
%181 = add nsw i32 %180, 1
store i32 %181, i32* %19
br label %21
182: ; preds = %21
ret void
}

LLVM IR (-O2):
define void @closerFurther(double* nocapture %0, double* nocapture %1, double* nocapture %2, double* nocapture %3, i32 %4, double %5, i32* nocapture writeonly %6, i32* nocapture writeonly %7, double* nocapture %8) {
store double 0.000000e+00, double* %8
%10 = icmp sgt i32 %4, 0
br i1 %10, label %11, label %64
11: ; preds = %9
%12 = zext i32 %4 to i64
br label %13
13: ; preds = %11, %57
%14 = phi i64 [ 0, %11 ], [ %62, %57 ]
%15 = getelementptr inbounds double, double* %1, i64 %14
%16 = load double, double* %15
%17 = getelementptr inbounds double, double* %0, i64 %14
%18 = load double, double* %17
%19 = fsub double %16, %18
%20 = tail call i64 @fabs(double %19)
%21 = sitofp i64 %20 to double
%22 = load double, double* %8
%23 = fadd double %22, %21
store double %23, double* %8
%24 = load double, double* %17
%25 = fadd double %24, %5
%26 = load double, double* %15
%27 = fcmp ult double %25, %26
%28 = fsub double %24, %5
%29 = fcmp ugt double %28, %26
%30 = or i1 %27, %29
br i1 %30, label %34, label %31
31: ; preds = %13
%32 = getelementptr inbounds i32, i32* %6, i64 %14
store i32 -1, i32* %32
%33 = getelementptr inbounds double, double* %3, i64 %14
store double %24, double* %33
br label %57
34: ; preds = %13
%35 = fsub double %26, %24
%36 = tail call i64 @fabs(double %35)
%37 = load double, double* %15
%38 = getelementptr inbounds double, double* %2, i64 %14
%39 = load double, double* %38
%40 = fsub double %37, %39
%41 = tail call i64 @fabs(double %40)
%42 = icmp slt i64 %36, %41
%43 = zext i1 %42 to i32
%44 = getelementptr inbounds i32, i32* %6, i64 %14
store i32 %43, i32* %44
%45 = load double, double* %15
%46 = load double, double* %17
%47 = fsub double %45, %46
%48 = tail call i64 @fabs(double %47)
%49 = load double, double* %15
%50 = getelementptr inbounds double, double* %3, i64 %14
%51 = load double, double* %50
%52 = fsub double %49, %51
%53 = tail call i64 @fabs(double %52)
%54 = icmp slt i64 %48, %53
br i1 %54, label %55, label %57
55: ; preds = %34
%56 = load double, double* %17
store double %56, double* %50
br label %57
57: ; preds = %34, %55, %31
%58 = phi i32 [ 1, %55 ], [ -1, %31 ], [ 0, %34 ]
%59 = getelementptr inbounds i32, i32* %7, i64 %14
store i32 %58, i32* %59
%60 = load double, double* %17
%61 = getelementptr inbounds double, double* %2, i64 %14
store double %60, double* %61
%62 = add nuw nsw i64 %14, 1
%63 = icmp eq i64 %62, %12
br i1 %63, label %64, label %13
64: ; preds = %57, %9
ret void
}