#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 /*<<< orphan*/,
                                               int /*<<< orphan*/, float, float,
                                               float, float *, float *,
                                               float *);
int /*<<< orphan*/ vis5d_project(int, float *, float *, float *);
float distance_to_hclip(int index, int curx, int cury, int num, float level,
                        int *corner) {
  float cx, cy, px, py;
  float dist, neardist, p[3];
  float r, c;
  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, 0, 0, r, c, level, &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_hclip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
movss  %xmm0,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x54(%rbp),%rsi
lea    -0x58(%rbp),%rdx
lea    -0x5c(%rbp),%rcx
lea    -0x60(%rbp),%r8
lea    -0x68(%rbp),%r9
lea    -0x6c(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <vis5d_get_sizePRIME@plt>
movss  0xe84(%rip),%xmm0
movss  %xmm0,-0x38(%rbp)
cvtsi2ssl -0x8(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
cvtsi2ssl -0xc(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movl   $0x0,-0x50(%rbp)
cmpl   $0x4,-0x50(%rbp)
jge    12eb <distance_to_hclip+0x1bb>
mov    -0x50(%rbp),%eax
mov    %rax,-0x78(%rbp)
sub    $0x3,%rax
ja     1236 <distance_to_hclip+0x106>
mov    -0x78(%rbp),%rax
lea    0xe42(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xorps  %xmm0,%xmm0
movss  %xmm0,-0x48(%rbp)
mov    -0x58(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x4c(%rbp)
jmp    1236 <distance_to_hclip+0x106>
mov    -0x54(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x48(%rbp)
mov    -0x58(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x4c(%rbp)
jmp    1236 <distance_to_hclip+0x106>
mov    -0x54(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4c(%rbp)
jmp    1236 <distance_to_hclip+0x106>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4c(%rbp)
mov    -0x4(%rbp),%edi
movss  -0x48(%rbp),%xmm0
movss  -0x4c(%rbp),%xmm1
movss  -0x14(%rbp),%xmm2
lea    -0x44(%rbp),%rcx
lea    -0x44(%rbp),%r8
add    $0x4,%r8
lea    -0x44(%rbp),%r9
add    $0x8,%r9
xor    %edx,%edx
mov    %edx,%esi
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     12d8 <distance_to_hclip+0x1a8>
movss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
mov    -0x50(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    12dd <distance_to_hclip+0x1ad>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    119c <distance_to_hclip+0x6c>
movss  -0x38(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance_to_hclip>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r8,0x30(%rsp)
movss  %xmm0,0x24(%rsp)
mov    %edx,%r14d
mov    %esi,%ebx
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 %ebx,%xmm0
movss  %xmm0,0x20(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %r14d,%xmm0
movss  %xmm0,0x1c(%rsp)
xor    %r15d,%r15d
movss  0xe63(%rip),%xmm0
movss  %xmm0,0x10(%rsp)
lea    0x4c(%rsp),%rbx
lea    0x2c(%rsp),%r13
lea    0x28(%rsp),%r14
lea    0xe4b(%rip),%r12
jmp    11ce <distance_to_hclip+0x9e>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15d
cmp    $0x4,%r15d
je     12e2 <distance_to_hclip+0x1b2>
cmp    $0x3,%r15d
ja     1262 <distance_to_hclip+0x132>
mov    %r15d,%eax
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    0x14(%rsp),%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
jmp    1262 <distance_to_hclip+0x132>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
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
jmp    125c <distance_to_hclip+0x12c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x18(%rsp),%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
jmp    1253 <distance_to_hclip+0x123>
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
movss  0xc(%rsp),%xmm0
movss  0x8(%rsp),%xmm1
movss  0x24(%rsp),%xmm2
mov    %rbx,%rcx
lea    0x50(%rsp),%r8
lea    0x54(%rsp),%r9
call   1050 <vis5d_gridPRIME_to_xyzPRIME@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r14,%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_hclip+0x90>
mov    0x30(%rsp),%rax
mov    %r15d,(%rax)
movss  %xmm0,0x10(%rsp)
jmp    11c0 <distance_to_hclip+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_hclip(i32 %0, i32 %1, i32 %2, i32 %3, float %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca float
%12 = alloca i32*
%13 = alloca float
%14 = alloca float
%15 = alloca float
%16 = alloca float
%17 = alloca float
%18 = alloca float
%19 = alloca [3 x float]
%20 = alloca float
%21 = alloca float
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store float %4, float* %11
store i32* %5, i32** %12
%30 = load i32, i32* %7
%31 = call i32 @vis5d_get_sizePRIME(i32 %30, i32* %23, i32* %24, i32* %25, i32* %26, i32* %28, i32* %29)
store float 1.000000e+06, float* %18
%32 = load i32, i32* %8
%33 = sitofp i32 %32 to float
store float %33, float* %13
%34 = load i32, i32* %9
%35 = sitofp i32 %34 to float
store float %35, float* %14
store i32 0, i32* %22
br label %36
36: ; preds = %91, %6
%37 = load i32, i32* %22
%38 = icmp slt i32 %37, 4
br i1 %38, label %39, label %94
39: ; preds = %36
%40 = load i32, i32* %22
switch i32 %40, label %57 [
i32 0, label %41
i32 1, label %45
i32 2, label %52
i32 3, label %56
]
41: ; preds = %39
store float 0.000000e+00, float* %20
%42 = load i32, i32* %24
%43 = sub nsw i32 %42, 1
%44 = sitofp i32 %43 to float
store float %44, float* %21
br label %57
45: ; preds = %39
%46 = load i32, i32* %23
%47 = sub nsw i32 %46, 1
%48 = sitofp i32 %47 to float
store float %48, float* %20
%49 = load i32, i32* %24
%50 = sub nsw i32 %49, 1
%51 = sitofp i32 %50 to float
store float %51, float* %21
br label %57
52: ; preds = %39
%53 = load i32, i32* %23
%54 = sub nsw i32 %53, 1
%55 = sitofp i32 %54 to float
store float %55, float* %20
store float 0.000000e+00, float* %21
br label %57
56: ; preds = %39
store float 0.000000e+00, float* %20
store float 0.000000e+00, float* %21
br label %57
57: ; preds = %39, %56, %52, %45, %41
%58 = load i32, i32* %7
%59 = load float, float* %20
%60 = load float, float* %21
%61 = load float, float* %11
%62 = getelementptr inbounds [3 x float], [3 x float]* %19, i64 0, i64 0
%63 = getelementptr inbounds [3 x float], [3 x float]* %19, i64 0, i64 1
%64 = getelementptr inbounds [3 x float], [3 x float]* %19, i64 0, i64 2
%65 = call i32 @vis5d_gridPRIME_to_xyzPRIME(i32 %58, i32 0, i32 0, float %59, float %60, float %61, float* %62, float* %63, float* %64)
%66 = load i32, i32* %7
%67 = getelementptr inbounds [3 x float], [3 x float]* %19, i64 0, i64 0
%68 = call i32 @vis5d_project(i32 %66, float* %67, float* %15, float* %16)
%69 = load float, float* %15
%70 = load float, float* %13
%71 = fsub float %69, %70
%72 = load float, float* %15
%73 = load float, float* %13
%74 = fsub float %72, %73
%75 = load float, float* %16
%76 = load float, float* %14
%77 = fsub float %75, %76
%78 = load float, float* %16
%79 = load float, float* %14
%80 = fsub float %78, %79
%81 = fmul float %77, %80
%82 = call float @llvm.fmuladd.f32(float %71, float %74, float %81)
store float %82, float* %17
%83 = load float, float* %17
%84 = load float, float* %18
%85 = fcmp ole float %83, %84
br i1 %85, label %86, label %90
86: ; preds = %57
%87 = load float, float* %17
store float %87, float* %18
%88 = load i32, i32* %22
%89 = load i32*, i32** %12
store i32 %88, i32* %89
br label %90
90: ; preds = %86, %57
br label %91
91: ; preds = %90
%92 = load i32, i32* %22
%93 = add nsw i32 %92, 1
store i32 %93, i32* %22
br label %36
94: ; preds = %36
%95 = load float, float* %18
ret float %95
}

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