#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 acos(double);
double cos(double const);
double sin(double const);
int grid_search_nn(long min_add, long max_add, int *restrict nbr_add,
                   double *restrict nbr_dist, double plat, double plon,
                   const double *restrict src_center_lat,
                   const double *restrict src_center_lon) {
  int search_result = 0;
  long n, srch_add;
  long i;
  double dist_min, distance;
  double coslat_dst = cos(plat);
  double sinlat_dst = sin(plat);
  double coslon_dst = cos(plon);
  double sinlon_dst = sin(plon);
  dist_min = 1.e+20;
  for (n = 0; n < 4; ++n)
    nbr_dist[n] = 1.e+20;
  for (srch_add = min_add; srch_add <= max_add; ++srch_add) {
    distance = acos(coslat_dst * cos(src_center_lat[srch_add]) *
                        (coslon_dst * cos(src_center_lon[srch_add]) +
                         sinlon_dst * sin(src_center_lon[srch_add])) +
                    sinlat_dst * sin(src_center_lat[srch_add]));
    if (distance < dist_min) {
      for (n = 0; n < 4; ++n) {
        if (distance < nbr_dist[n]) {
          for (i = 3; i > n; --i) {
            nbr_add[i] = nbr_add[i - 1];
            nbr_dist[i] = nbr_dist[i - 1];
          }
          search_result = -1;
          nbr_add[n] = srch_add;
          nbr_dist[n] = distance;
          dist_min = nbr_dist[3];
          break;
        }
      }
    }
  }
  for (n = 0; n < 4; ++n)
    nbr_dist[n] = 1.0 / (nbr_dist[n] + 1.e-14);
  distance = 0.0;
  for (n = 0; n < 4; ++n)
    distance += nbr_dist[n];
  for (n = 0; n < 4; ++n)
    nbr_dist[n] /= distance;
  return (search_result);
}


x86 assembly (clang, -O0):
<grid_search_nn>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  %xmm1,-0x30(%rbp)
mov    %r8,-0x38(%rbp)
mov    %r9,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x90(%rbp)
ff
movsd  0xe52(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
movq   $0x0,-0x50(%rbp)
cmpq   $0x4,-0x50(%rbp)
jge    11ec <grid_search_nn+0xbc>
mov    -0x20(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  0xe2a(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    11bb <grid_search_nn+0x8b>
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
cmp    -0x10(%rbp),%rax
jg     1413 <grid_search_nn+0x2e3>
movsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0xc8(%rbp)
ff
mov    -0x38(%rbp),%rax
mov    -0x58(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0xc8(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0xb0(%rbp)
ff
mov    -0x40(%rbp),%rax
mov    -0x58(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
movsd  %xmm0,-0xc0(%rbp)
ff
mov    -0x40(%rbp),%rax
mov    -0x58(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <sin@plt>
movsd  -0xc0(%rbp),%xmm1
ff
movsd  -0xb8(%rbp),%xmm2
ff
movaps %xmm0,%xmm3
movsd  -0xb0(%rbp),%xmm0
ff
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
mov    -0x38(%rbp),%rax
mov    -0x58(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <sin@plt>
movsd  -0xa8(%rbp),%xmm1
ff
movsd  -0xa0(%rbp),%xmm2
ff
movaps %xmm0,%xmm3
movsd  -0x98(%rbp),%xmm0
ff
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <acos@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    13fd <grid_search_nn+0x2cd>
movq   $0x0,-0x50(%rbp)
cmpq   $0x4,-0x50(%rbp)
jge    13f8 <grid_search_nn+0x2c8>
movsd  -0x70(%rbp),%xmm1
mov    -0x20(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    13e2 <grid_search_nn+0x2b2>
movq   $0x3,-0x60(%rbp)
mov    -0x60(%rbp),%rax
cmp    -0x50(%rbp),%rax
jle    13a5 <grid_search_nn+0x275>
mov    -0x18(%rbp),%rax
mov    -0x60(%rbp),%rcx
sub    $0x1,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%rax
mov    -0x60(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    -0x60(%rbp),%rcx
sub    $0x1,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x60(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x60(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x60(%rbp)
jmp    134e <grid_search_nn+0x21e>
movl   $0xffffffff,-0x44(%rbp)
mov    -0x58(%rbp),%rax
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x50(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movsd  -0x70(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    13f8 <grid_search_nn+0x2c8>
jmp    13e7 <grid_search_nn+0x2b7>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    131f <grid_search_nn+0x1ef>
jmp    13fd <grid_search_nn+0x2cd>
jmp    1402 <grid_search_nn+0x2d2>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    11f4 <grid_search_nn+0xc4>
movq   $0x0,-0x50(%rbp)
cmpq   $0x4,-0x50(%rbp)
jge    1465 <grid_search_nn+0x335>
mov    -0x20(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  0xbda(%rip),%xmm1
addsd  (%rax,%rcx,8),%xmm1
movsd  0xbc5(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    141b <grid_search_nn+0x2eb>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
movq   $0x0,-0x50(%rbp)
cmpq   $0x4,-0x50(%rbp)
jge    14a8 <grid_search_nn+0x378>
mov    -0x20(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    1475 <grid_search_nn+0x345>
movq   $0x0,-0x50(%rbp)
cmpq   $0x4,-0x50(%rbp)
jge    14e7 <grid_search_nn+0x3b7>
movsd  -0x70(%rbp),%xmm1
mov    -0x20(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    14b0 <grid_search_nn+0x380>
mov    -0x44(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grid_search_nn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r9,0x30(%rsp)
mov    %r8,%r15
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbp
call   1050 <cos@plt>
movsd  %xmm0,0x50(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,0x48(%rsp)
movsd  0x10(%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,0x40(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,0x38(%rsp)
movapd 0xe5c(%rip),%xmm0
movupd %xmm0,(%rbx)
movupd %xmm0,0x10(%rbx)
cmp    %r13,%rbp
jle    11c6 <grid_search_nn+0x96>
xor    %r14d,%r14d
movsd  0xe73(%rip),%xmm4
movapd %xmm4,%xmm1
jmp    1351 <grid_search_nn+0x221>
lea    0x18(%rbx),%rax
mov    %rax,0x28(%rsp)
add    $0x1,%r13
xor    %r14d,%r14d
movsd  0xe52(%rip),%xmm4
jmp    1200 <grid_search_nn+0xd0>
mov    %ebp,(%r12,%rax,4)
movsd  %xmm0,(%rcx)
movsd  0x18(%rbx),%xmm4
mov    $0xffffffff,%r14d
add    $0x1,%rbp
cmp    %rbp,%r13
je     1338 <grid_search_nn+0x208>
movapd %xmm4,0x10(%rsp)
movsd  (%r15,%rbp,8),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1050 <cos@plt>
mulsd  0x50(%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    0x30(%rsp),%rax
movsd  (%rax,%rbp,8),%xmm0
movsd  %xmm0,0x58(%rsp)
call   1050 <cos@plt>
movsd  %xmm0,0x60(%rsp)
movsd  0x58(%rsp),%xmm0
call   1040 <sin@plt>
mulsd  0x38(%rsp),%xmm0
movsd  0x60(%rsp),%xmm1
mulsd  0x40(%rsp),%xmm1
addsd  %xmm1,%xmm0
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
mulsd  0x48(%rsp),%xmm0
addsd  (%rsp),%xmm0
call   1030 <acos@plt>
movapd 0x10(%rsp),%xmm4
ucomisd %xmm0,%xmm4
jbe    11f3 <grid_search_nn+0xc3>
movsd  (%rbx),%xmm1
mov    $0x1,%dl
ucomisd %xmm0,%xmm1
jbe    12b0 <grid_search_nn+0x180>
mov    $0x1,%sil
xor    %eax,%eax
jmp    12e4 <grid_search_nn+0x1b4>
cs nopw 0x0(%rax,%rax,1)
movsd  0x8(%rbx),%xmm1
ucomisd %xmm0,%xmm1
jbe    12c2 <grid_search_nn+0x192>
mov    $0x1,%eax
jmp    12e2 <grid_search_nn+0x1b2>
movsd  0x10(%rbx),%xmm1
mov    $0x3,%eax
ucomisd %xmm0,%xmm1
mov    0x28(%rsp),%rcx
jbe    11e0 <grid_search_nn+0xb0>
mov    $0x2,%eax
xor    %edx,%edx
xor    %esi,%esi
lea    (%rbx,%rax,8),%rcx
mov    0x8(%r12),%edi
mov    %edi,0xc(%r12)
movsd  0x10(%rbx),%xmm1
movsd  %xmm1,0x18(%rbx)
test   %dl,%dl
je     11e0 <grid_search_nn+0xb0>
mov    0x4(%r12),%edx
mov    %edx,0x8(%r12)
movsd  0x8(%rbx),%xmm1
movsd  %xmm1,0x10(%rbx)
test   %sil,%sil
je     11e0 <grid_search_nn+0xb0>
mov    (%r12),%edx
mov    %edx,0x4(%r12)
movsd  (%rbx),%xmm1
movsd  %xmm1,0x8(%rbx)
jmp    11e0 <grid_search_nn+0xb0>
movupd (%rbx),%xmm0
movsd  0x10(%rbx),%xmm1
addpd  0xcc7(%rip),%xmm0
addsd  0xce7(%rip),%xmm1
movapd 0xcc7(%rip),%xmm2
movapd %xmm2,%xmm3
divpd  %xmm0,%xmm3
addsd  0xccf(%rip),%xmm4
unpcklpd %xmm4,%xmm1
divpd  %xmm1,%xmm2
xorpd  %xmm0,%xmm0
addsd  %xmm3,%xmm0
movapd %xmm3,%xmm1
unpckhpd %xmm3,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
movapd %xmm2,%xmm0
unpckhpd %xmm2,%xmm0
addsd  %xmm1,%xmm0
unpcklpd %xmm0,%xmm0
divpd  %xmm0,%xmm3
movupd %xmm3,(%rbx)
divpd  %xmm0,%xmm2
movupd %xmm2,0x10(%rbx)
mov    %r14d,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @grid_search_nn(i64 %0, i64 %1, i32* noalias nocapture %2, double* noalias nocapture %3, double %4, double %5, double* noalias nocapture %6, double* noalias nocapture %7) {
%9 = tail call double @cos(double %4)
%10 = tail call double @sin(double %4)
%11 = tail call double @cos(double %5)
%12 = tail call double @sin(double %5)
%13 = getelementptr inbounds double, double* %3, i64 1
%14 = bitcast double* %3 to <2 x double>*
store <2 x double> <double 1.000000e+20, double 1.000000e+20>, <2 x double>* %14
%15 = getelementptr inbounds double, double* %3, i64 2
%16 = getelementptr inbounds double, double* %3, i64 3
%17 = bitcast double* %15 to <2 x double>*
store <2 x double> <double 1.000000e+20, double 1.000000e+20>, <2 x double>* %17
%18 = icmp sgt i64 %0, %1
br i1 %18, label %37, label %19
19: ; preds = %8
%20 = getelementptr inbounds double, double* %3, i64 3
%21 = getelementptr inbounds i32, i32* %2, i64 2
%22 = getelementptr inbounds i32, i32* %2, i64 3
%23 = getelementptr inbounds double, double* %3, i64 2
%24 = getelementptr inbounds double, double* %3, i64 3
%25 = getelementptr inbounds i32, i32* %2, i64 1
%26 = getelementptr inbounds i32, i32* %2, i64 2
%27 = getelementptr inbounds double, double* %3, i64 1
%28 = getelementptr inbounds double, double* %3, i64 2
%29 = getelementptr inbounds i32, i32* %2, i64 1
%30 = getelementptr inbounds double, double* %3, i64 1
br label %61
31: ; preds = %109
%32 = bitcast double* %3 to <2 x double>*
%33 = load <2 x double>, <2 x double>* %32
%34 = load double, double* %15
%35 = fadd <2 x double> %33, <double 0x3D06849B86A12B9B, double 0x3D06849B86A12B9B>
%36 = fadd double %34, 0x3D06849B86A12B9B
br label %37
37: ; preds = %31, %8
%38 = phi double [ 1.000000e+20, %8 ], [ %110, %31 ]
%39 = phi double [ 1.000000e+20, %8 ], [ %36, %31 ]
%40 = phi i32 [ 0, %8 ], [ %112, %31 ]
%41 = phi <2 x double> [ <double 1.000000e+20, double 1.000000e+20>, %8 ], [ %35, %31 ]
%42 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %41
%43 = fadd double %38, 0x3D06849B86A12B9B
%44 = insertelement <2 x double> poison, double %39, i64 0
%45 = insertelement <2 x double> %44, double %43, i64 1
%46 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %45
%47 = extractelement <2 x double> %42, i64 0
%48 = fadd double %47, 0.000000e+00
%49 = extractelement <2 x double> %42, i64 1
%50 = fadd double %48, %49
%51 = extractelement <2 x double> %46, i64 0
%52 = fadd double %50, %51
%53 = extractelement <2 x double> %46, i64 1
%54 = fadd double %52, %53
%55 = insertelement <2 x double> poison, double %54, i64 0
%56 = shufflevector <2 x double> %55, <2 x double> poison, <2 x i32> zeroinitializer
%57 = fdiv <2 x double> %42, %56
%58 = bitcast double* %3 to <2 x double>*
store <2 x double> %57, <2 x double>* %58
%59 = fdiv <2 x double> %46, %56
%60 = bitcast double* %15 to <2 x double>*
store <2 x double> %59, <2 x double>* %60
ret i32 %40
61: ; preds = %19, %109
%62 = phi double [ 1.000000e+20, %19 ], [ %110, %109 ]
%63 = phi i32 [ 0, %19 ], [ %112, %109 ]
%64 = phi i64 [ %0, %19 ], [ %113, %109 ]
%65 = phi double [ 1.000000e+20, %19 ], [ %111, %109 ]
%66 = getelementptr inbounds double, double* %6, i64 %64
%67 = load double, double* %66
%68 = tail call double @cos(double %67)
%69 = fmul double %9, %68
%70 = getelementptr inbounds double, double* %7, i64 %64
%71 = load double, double* %70
%72 = tail call double @cos(double %71)
%73 = tail call double @sin(double %71)
%74 = fmul double %12, %73
%75 = tail call double @llvm.fmuladd.f64(double %11, double %72, double %74)
%76 = tail call double @sin(double %67)
%77 = fmul double %10, %76
%78 = tail call double @llvm.fmuladd.f64(double %69, double %75, double %77)
%79 = tail call double @acos(double %78)
%80 = fcmp olt double %79, %65
br i1 %80, label %81, label %109
81: ; preds = %61
%82 = load double, double* %3
%83 = fcmp olt double %79, %82
br i1 %83, label %84, label %103
84: ; preds = %106, %103, %81
%85 = phi i1 [ false, %106 ], [ true, %103 ], [ true, %81 ]
%86 = phi i1 [ false, %106 ], [ false, %103 ], [ true, %81 ]
%87 = phi i64 [ 2, %106 ], [ 1, %103 ], [ 0, %81 ]
%88 = getelementptr inbounds double, double* %3, i64 %87
%89 = load i32, i32* %21
store i32 %89, i32* %22
%90 = load double, double* %23
store double %90, double* %24
br i1 %85, label %91, label %97
91: ; preds = %84
%92 = load i32, i32* %25
store i32 %92, i32* %26
%93 = load double, double* %27
store double %93, double* %28
br i1 %86, label %94, label %97
94: ; preds = %91
%95 = load i32, i32* %2
store i32 %95, i32* %29
%96 = load double, double* %3
store double %96, double* %30
br label %97
97: ; preds = %84, %91, %94, %106
%98 = phi double* [ %20, %106 ], [ %88, %94 ], [ %88, %91 ], [ %88, %84 ]
%99 = phi i64 [ 3, %106 ], [ %87, %94 ], [ %87, %91 ], [ %87, %84 ]
%100 = trunc i64 %64 to i32
%101 = getelementptr inbounds i32, i32* %2, i64 %99
store i32 %100, i32* %101
store double %79, double* %98
%102 = load double, double* %16
br label %109
103: ; preds = %81
%104 = load double, double* %13
%105 = fcmp olt double %79, %104
br i1 %105, label %84, label %106
106: ; preds = %103
%107 = load double, double* %15
%108 = fcmp olt double %79, %107
br i1 %108, label %84, label %97
109: ; preds = %61, %97
%110 = phi double [ %102, %97 ], [ %62, %61 ]
%111 = phi double [ %102, %97 ], [ %65, %61 ]
%112 = phi i32 [ -1, %97 ], [ %63, %61 ]
%113 = add i64 %64, 1
%114 = icmp eq i64 %64, %1
br i1 %114, label %31, label %61
}