#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 */
int /*<<< orphan*/ vis5d_get_sizePRIME(int, int *, int *, int *, int *, int *,
                                       int *);
int /*<<< orphan*/ vis5d_gridPRIME_to_xyzPRIME(int, int, int, float, float,
                                               float, float *, float *,
                                               float *);
int /*<<< orphan*/ vis5d_project(int, float *, float *, float *);
float distance_to_hslice(int index, int curx, int cury, int time, int var,
                         float level, int *corner) {
  float cx, cy, px, py;
  float dist, neardist, p[3];
  float r, c;
  float flevel = (float)level;
  int i;
  int Nr, Nc, Nl, LowLev, MaxNlVar, WindNl, WindLow;
  vis5d_get_sizePRIME(index, &Nr, &Nc, &Nl, &LowLev, &WindNl, &WindLow);
  neardist = 1000000.0;
  cx = (float)curx;
  cy = (float)cury;
  for (i = 0; i < 4; i++) {
    switch (i) {
    case 0:
      r = 0.0;
      c = (float)(Nc - 1);
      break;
    case 1:
      r = (float)(Nr - 1);
      c = (float)(Nc - 1);
      break;
    case 2:
      r = (float)(Nr - 1);
      c = 0.0;
      break;
    case 3:
      r = 0.0;
      c = 0.0;
      break;
    }
    vis5d_gridPRIME_to_xyzPRIME(index, time, var, r, c, flevel, &p[0], &p[1],
                                &p[2]);
    vis5d_project(index, p, &px, &py);
    dist = (px - cx) * (px - cx) + (py - cy) * (py - cy);
    if (dist <= neardist) {
      neardist = dist;
      *corner = i;
    }
  }
  return neardist;
}


x86 assembly (clang, -O0):
<distance_to_hslice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
movss  %xmm0,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x50(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x58(%rbp),%rsi
lea    -0x5c(%rbp),%rdx
lea    -0x60(%rbp),%rcx
lea    -0x64(%rbp),%r8
lea    -0x6c(%rbp),%r9
lea    -0x70(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <vis5d_get_sizePRIME@plt>
movss  0xe76(%rip),%xmm0
movss  %xmm0,-0x38(%rbp)
cvtsi2ssl -0x8(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
cvtsi2ssl -0xc(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x4,-0x54(%rbp)
jge    12fb <distance_to_hslice+0x1cb>
mov    -0x54(%rbp),%eax
mov    %rax,-0x78(%rbp)
sub    $0x3,%rax
ja     1244 <distance_to_hslice+0x114>
mov    -0x78(%rbp),%rax
lea    0xe34(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xorps  %xmm0,%xmm0
movss  %xmm0,-0x48(%rbp)
mov    -0x5c(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x4c(%rbp)
jmp    1244 <distance_to_hslice+0x114>
mov    -0x58(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x48(%rbp)
mov    -0x5c(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x4c(%rbp)
jmp    1244 <distance_to_hslice+0x114>
mov    -0x58(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4c(%rbp)
jmp    1244 <distance_to_hslice+0x114>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
movss  -0x48(%rbp),%xmm0
movss  -0x4c(%rbp),%xmm1
movss  -0x50(%rbp),%xmm2
lea    -0x44(%rbp),%rcx
lea    -0x44(%rbp),%r8
add    $0x4,%r8
lea    -0x44(%rbp),%r9
add    $0x8,%r9
call   1050 <vis5d_gridPRIME_to_xyzPRIME@plt>
mov    -0x4(%rbp),%edi
lea    -0x44(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1030 <vis5d_project@plt>
movss  -0x2c(%rbp),%xmm0
subss  -0x24(%rbp),%xmm0
movss  -0x2c(%rbp),%xmm2
subss  -0x24(%rbp),%xmm2
movss  -0x30(%rbp),%xmm1
subss  -0x28(%rbp),%xmm1
movss  -0x30(%rbp),%xmm3
subss  -0x28(%rbp),%xmm3
mulss  %xmm3,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm1
movss  -0x38(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     12e8 <distance_to_hslice+0x1b8>
movss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
mov    -0x54(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    12ed <distance_to_hslice+0x1bd>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11aa <distance_to_hslice+0x7a>
movss  -0x38(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance_to_hslice>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r9,0x30(%rsp)
movss  %xmm0,0x24(%rsp)
mov    %r8d,%r15d
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %esi,%r12d
mov    %edi,%ebp
lea    0x3c(%rsp),%rax
mov    %rax,(%rsp)
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x48(%rsp),%rcx
lea    0x44(%rsp),%r8
lea    0x40(%rsp),%r9
call   1040 <vis5d_get_sizePRIME@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %r12d,%xmm0
movss  %xmm0,0x20(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %r14d,%xmm0
movss  %xmm0,0x1c(%rsp)
xor    %r12d,%r12d
movss  0xe5c(%rip),%xmm0
movss  %xmm0,0x10(%rsp)
lea    0x4c(%rsp),%r14
lea    0xe4e(%rip),%r13
jmp    11ce <distance_to_hslice+0x9e>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12d
cmp    $0x4,%r12d
je     12e7 <distance_to_hslice+0x1b7>
cmp    $0x3,%r12d
ja     1262 <distance_to_hslice+0x132>
mov    %r12d,%eax
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    0x14(%rsp),%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
jmp    1253 <distance_to_hslice+0x123>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x18(%rsp),%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0xc(%rsp)
mov    0x14(%rsp),%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x8(%rsp)
jmp    1262 <distance_to_hslice+0x132>
nopw   0x0(%rax,%rax,1)
mov    0x18(%rsp),%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0xc(%rsp)
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
jmp    1262 <distance_to_hslice+0x132>
nop
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r15d,%edx
movss  0xc(%rsp),%xmm0
movss  0x8(%rsp),%xmm1
movss  0x24(%rsp),%xmm2
mov    %r14,%rcx
lea    0x50(%rsp),%r8
lea    0x54(%rsp),%r9
call   1050 <vis5d_gridPRIME_to_xyzPRIME@plt>
mov    %ebp,%edi
mov    %r14,%rsi
lea    0x2c(%rsp),%rdx
lea    0x28(%rsp),%rcx
call   1030 <vis5d_project@plt>
movss  0x2c(%rsp),%xmm0
subss  0x20(%rsp),%xmm0
movss  0x28(%rsp),%xmm1
subss  0x1c(%rsp),%xmm1
mulss  %xmm1,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
movss  0x10(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jb     11c0 <distance_to_hslice+0x90>
mov    0x30(%rsp),%rax
mov    %r12d,(%rax)
movss  %xmm0,0x10(%rsp)
jmp    11c0 <distance_to_hslice+0x90>
movss  0x10(%rsp),%xmm0
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define float @distance_to_hslice(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, float %5, i32* %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca float
%14 = alloca i32*
%15 = alloca float
%16 = alloca float
%17 = alloca float
%18 = alloca float
%19 = alloca float
%20 = alloca float
%21 = alloca [3 x float]
%22 = alloca float
%23 = alloca float
%24 = alloca float
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32
%30 = alloca i32
%31 = alloca i32
%32 = alloca i32
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store float %5, float* %13
store i32* %6, i32** %14
%33 = load float, float* %13
store float %33, float* %24
%34 = load i32, i32* %8
%35 = call i32 @vis5d_get_sizePRIME(i32 %34, i32* %26, i32* %27, i32* %28, i32* %29, i32* %31, i32* %32)
store float 1.000000e+06, float* %20
%36 = load i32, i32* %9
%37 = sitofp i32 %36 to float
store float %37, float* %15
%38 = load i32, i32* %10
%39 = sitofp i32 %38 to float
store float %39, float* %16
store i32 0, i32* %25
br label %40
40: ; preds = %97, %7
%41 = load i32, i32* %25
%42 = icmp slt i32 %41, 4
br i1 %42, label %43, label %100
43: ; preds = %40
%44 = load i32, i32* %25
switch i32 %44, label %61 [
i32 0, label %45
i32 1, label %49
i32 2, label %56
i32 3, label %60
]
45: ; preds = %43
store float 0.000000e+00, float* %22
%46 = load i32, i32* %27
%47 = sub nsw i32 %46, 1
%48 = sitofp i32 %47 to float
store float %48, float* %23
br label %61
49: ; preds = %43
%50 = load i32, i32* %26
%51 = sub nsw i32 %50, 1
%52 = sitofp i32 %51 to float
store float %52, float* %22
%53 = load i32, i32* %27
%54 = sub nsw i32 %53, 1
%55 = sitofp i32 %54 to float
store float %55, float* %23
br label %61
56: ; preds = %43
%57 = load i32, i32* %26
%58 = sub nsw i32 %57, 1
%59 = sitofp i32 %58 to float
store float %59, float* %22
store float 0.000000e+00, float* %23
br label %61
60: ; preds = %43
store float 0.000000e+00, float* %22
store float 0.000000e+00, float* %23
br label %61
61: ; preds = %43, %60, %56, %49, %45
%62 = load i32, i32* %8
%63 = load i32, i32* %11
%64 = load i32, i32* %12
%65 = load float, float* %22
%66 = load float, float* %23
%67 = load float, float* %24
%68 = getelementptr inbounds [3 x float], [3 x float]* %21, i64 0, i64 0
%69 = getelementptr inbounds [3 x float], [3 x float]* %21, i64 0, i64 1
%70 = getelementptr inbounds [3 x float], [3 x float]* %21, i64 0, i64 2
%71 = call i32 @vis5d_gridPRIME_to_xyzPRIME(i32 %62, i32 %63, i32 %64, float %65, float %66, float %67, float* %68, float* %69, float* %70)
%72 = load i32, i32* %8
%73 = getelementptr inbounds [3 x float], [3 x float]* %21, i64 0, i64 0
%74 = call i32 @vis5d_project(i32 %72, float* %73, float* %17, float* %18)
%75 = load float, float* %17
%76 = load float, float* %15
%77 = fsub float %75, %76
%78 = load float, float* %17
%79 = load float, float* %15
%80 = fsub float %78, %79
%81 = load float, float* %18
%82 = load float, float* %16
%83 = fsub float %81, %82
%84 = load float, float* %18
%85 = load float, float* %16
%86 = fsub float %84, %85
%87 = fmul float %83, %86
%88 = call float @llvm.fmuladd.f32(float %77, float %80, float %87)
store float %88, float* %19
%89 = load float, float* %19
%90 = load float, float* %20
%91 = fcmp ole float %89, %90
br i1 %91, label %92, label %96
92: ; preds = %61
%93 = load float, float* %19
store float %93, float* %20
%94 = load i32, i32* %25
%95 = load i32*, i32** %14
store i32 %94, i32* %95
br label %96
96: ; preds = %92, %61
br label %97
97: ; preds = %96
%98 = load i32, i32* %25
%99 = add nsw i32 %98, 1
store i32 %99, i32* %25
br label %40
100: ; preds = %40
%101 = load float, float* %20
ret float %101
}

LLVM IR (-O2):
define float @distance_to_hslice(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, float %5, i32* nocapture writeonly %6) {
%8 = alloca float
%9 = alloca float
%10 = alloca [3 x float]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = bitcast float* %8 to i8*
%18 = bitcast float* %9 to i8*
%19 = bitcast [3 x float]* %10 to i8*
%20 = bitcast i32* %11 to i8*
%21 = bitcast i32* %12 to i8*
%22 = bitcast i32* %13 to i8*
%23 = bitcast i32* %14 to i8*
%24 = bitcast i32* %15 to i8*
%25 = bitcast i32* %16 to i8*
%26 = call i32 @vis5d_get_sizePRIME(i32 %0, i32* %11, i32* %12, i32* %13, i32* %14, i32* %15, i32* %16)
%27 = sitofp i32 %1 to float
%28 = sitofp i32 %2 to float
%29 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 0
%30 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 1
%31 = getelementptr inbounds [3 x float], [3 x float]* %10, i64 0, i64 2
br label %32
32: ; preds = %7, %66
%33 = phi float [ 1.000000e+06, %7 ], [ %67, %66 ]
%34 = phi i32 [ 0, %7 ], [ %68, %66 ]
%35 = phi float [ undef, %7 ], [ %55, %66 ]
%36 = phi float [ undef, %7 ], [ %54, %66 ]
switch i32 %34, label %53 [
i32 0, label %37
i32 1, label %41
i32 2, label %48
i32 3, label %52
]
37: ; preds = %32
%38 = load i32, i32* %12
%39 = add nsw i32 %38, -1
%40 = sitofp i32 %39 to float
br label %53
41: ; preds = %32
%42 = load i32, i32* %11
%43 = add nsw i32 %42, -1
%44 = sitofp i32 %43 to float
%45 = load i32, i32* %12
%46 = add nsw i32 %45, -1
%47 = sitofp i32 %46 to float
br label %53
48: ; preds = %32
%49 = load i32, i32* %11
%50 = add nsw i32 %49, -1
%51 = sitofp i32 %50 to float
br label %53
52: ; preds = %32
br label %53
53: ; preds = %32, %52, %48, %41, %37
%54 = phi float [ %36, %32 ], [ 0.000000e+00, %52 ], [ 0.000000e+00, %48 ], [ %47, %41 ], [ %40, %37 ]
%55 = phi float [ %35, %32 ], [ 0.000000e+00, %52 ], [ %51, %48 ], [ %44, %41 ], [ 0.000000e+00, %37 ]
%56 = call i32 @vis5d_gridPRIME_to_xyzPRIME(i32 %0, i32 %3, i32 %4, float %55, float %54, float %5, float* %29, float* %30, float* %31)
%57 = call i32 @vis5d_project(i32 %0, float* %29, float* %8, float* %9)
%58 = load float, float* %8
%59 = fsub float %58, %27
%60 = load float, float* %9
%61 = fsub float %60, %28
%62 = fmul float %61, %61
%63 = call float @llvm.fmuladd.f32(float %59, float %59, float %62)
%64 = fcmp ugt float %63, %33
br i1 %64, label %66, label %65
65: ; preds = %53
store i32 %34, i32* %6
br label %66
66: ; preds = %53, %65
%67 = phi float [ %63, %65 ], [ %33, %53 ]
%68 = add nuw nsw i32 %34, 1
%69 = icmp eq i32 %68, 4
br i1 %69, label %70, label %32
70: ; preds = %66
ret float %67
}