#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 pow(double, int);
int find_minimum(double *a, double v, int n) {
  int c, index;
  double min;
  min = pow((a[0] - v), 2);
  index = 0;
  for (c = 1; c < n; c++) {
    if (pow((a[c] - v), 2) < min) {
      index = c;
      min = pow((a[c] - v), 2);
    }
  }
  return index;
}


x86 assembly (clang, -O0):
<find_minimum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
subsd  -0x10(%rbp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c2 <find_minimum+0xb2>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x10(%rbp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11af <find_minimum+0x9f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x10(%rbp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  %xmm0,-0x28(%rbp)
jmp    11b4 <find_minimum+0xa4>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114e <find_minimum+0x3e>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_minimum>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
movapd %xmm0,%xmm1
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
movsd  %xmm1,(%rsp)
subsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
xor    %r15d,%r15d
cmp    $0x2,%r14d
jl     119e <find_minimum+0x8e>
mov    %r14d,%r12d
add    $0xffffffffffffffff,%r12
cmp    $0x2,%r14d
jne    11ae <find_minimum+0x9e>
xor    %r15d,%r15d
mov    $0x1,%ebp
test   $0x1,%r12b
je     119e <find_minimum+0x8e>
movsd  %xmm0,0x8(%rsp)
movsd  (%rbx,%rbp,8),%xmm0
subsd  (%rsp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    119e <find_minimum+0x8e>
movsd  (%rbx,%rbp,8),%xmm0
subsd  (%rsp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %ebp,%r15d
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%r14
and    $0xfffffffffffffffe,%r14
neg    %r14
xor    %r15d,%r15d
mov    $0x1,%ebp
movsd  (%rsp),%xmm1
jmp    11eb <find_minimum+0xdb>
nopw   0x0(%rax,%rax,1)
lea    (%r14,%rbp,1),%rax
add    $0x2,%rax
add    $0x2,%rbp
cmp    $0x1,%rax
movsd  (%rsp),%xmm1
je     115b <find_minimum+0x4b>
movsd  %xmm0,0x8(%rsp)
movsd  (%rbx,%rbp,8),%xmm0
subsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
jbe    122d <find_minimum+0x11d>
movsd  (%rbx,%rbp,8),%xmm0
subsd  (%rsp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %ebp,%r15d
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rbx,%rbp,8),%xmm0
subsd  (%rsp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
jbe    11d0 <find_minimum+0xc0>
movsd  0x8(%rbx,%rbp,8),%xmm0
subsd  (%rsp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
lea    0x1(%rbp),%r15d
jmp    11d0 <find_minimum+0xc0>

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

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