#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 */
float distance_to_hclip(int, int, int, int, float, int *);
float distance_to_vclip(int, int, int, int, float, float, float, float, int *);
int /*<<< orphan*/ vis5d_get_clip_mode(int, int, int *);
int /*<<< orphan*/ vis5d_get_hclip(int, int, float *);
int /*<<< orphan*/ vis5d_get_vclip(int, int, float *, float *, float *,
                                   float *);
int find_nearest_clip_slice(int index, int curx, int cury, int *planetype,
                            int *planenum, int *corner) {
  float dist, neardist;
  int i, corn, current;
  float level, r1, c1, r2, c2;
  neardist = 15.0 * 15.0;
  *planetype = *planenum = *corner = -1;
  for (i = 0; i < 2; i++) {
    vis5d_get_hclip(index, i, &level);
    vis5d_get_clip_mode(index, i, &current);
    if (current == 1) {
      dist = distance_to_hclip(index, curx, cury, i, level, &corn);
      if (dist < neardist) {
        neardist = dist;
        *planetype = 0;
        *planenum = i;
        *corner = corn;
      }
    }
  }
  for (i = 0; i < 4; i++) {
    vis5d_get_vclip(index, i, &r1, &c1, &r2, &c2);
    vis5d_get_clip_mode(index, i + 2, &current);
    if (current == 1) {
      dist = distance_to_vclip(index, curx, cury, i, r1, c1, r2, c2, &corn);
      if (dist < neardist) {
        neardist = dist;
        *planetype = 1;
        *planenum = i;
        *corner = corn;
      }
    }
  }
  if (*planetype != -1) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<find_nearest_clip_slice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movss  0xe8b(%rip),%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x20(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0x0,-0x34(%rbp)
cmpl   $0x2,-0x34(%rbp)
jge    1241 <find_nearest_clip_slice+0xf1>
mov    -0x8(%rbp),%edi
mov    -0x34(%rbp),%esi
lea    -0x40(%rbp),%rdx
call   1060 <vis5d_get_hclip@plt>
mov    -0x8(%rbp),%edi
mov    -0x34(%rbp),%esi
lea    -0x3c(%rbp),%rdx
call   1040 <vis5d_get_clip_mode@plt>
cmpl   $0x1,-0x3c(%rbp)
jne    122e <find_nearest_clip_slice+0xde>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x34(%rbp),%ecx
movss  -0x40(%rbp),%xmm0
lea    -0x38(%rbp),%r8
call   1030 <distance_to_hclip@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm1
movss  -0x30(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1229 <find_nearest_clip_slice+0xd9>
movss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x34(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    122e <find_nearest_clip_slice+0xde>
jmp    1233 <find_nearest_clip_slice+0xe3>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    119f <find_nearest_clip_slice+0x4f>
movl   $0x0,-0x34(%rbp)
cmpl   $0x4,-0x34(%rbp)
jge    1308 <find_nearest_clip_slice+0x1b8>
mov    -0x8(%rbp),%edi
mov    -0x34(%rbp),%esi
lea    -0x44(%rbp),%rdx
lea    -0x48(%rbp),%rcx
lea    -0x4c(%rbp),%r8
lea    -0x50(%rbp),%r9
call   1070 <vis5d_get_vclip@plt>
mov    -0x8(%rbp),%edi
mov    -0x34(%rbp),%esi
add    $0x2,%esi
lea    -0x3c(%rbp),%rdx
call   1040 <vis5d_get_clip_mode@plt>
cmpl   $0x1,-0x3c(%rbp)
jne    12f5 <find_nearest_clip_slice+0x1a5>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x34(%rbp),%ecx
movss  -0x44(%rbp),%xmm0
movss  -0x48(%rbp),%xmm1
movss  -0x4c(%rbp),%xmm2
movss  -0x50(%rbp),%xmm3
lea    -0x38(%rbp),%r8
call   1050 <distance_to_vclip@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm1
movss  -0x30(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    12f0 <find_nearest_clip_slice+0x1a0>
movss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x34(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    12f5 <find_nearest_clip_slice+0x1a5>
jmp    12fa <find_nearest_clip_slice+0x1aa>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1248 <find_nearest_clip_slice+0xf8>
mov    -0x18(%rbp),%rax
cmpl   $0xffffffff,(%rax)
je     1321 <find_nearest_clip_slice+0x1d1>
movl   $0x1,-0x4(%rbp)
jmp    1328 <find_nearest_clip_slice+0x1d8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_nearest_clip_slice>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
mov    %r9,0x28(%rsp)
movl   $0xffffffff,(%r9)
mov    %r8,0x20(%rsp)
movl   $0xffffffff,(%r8)
mov    %rcx,0x18(%rsp)
movl   $0xffffffff,(%rcx)
lea    0x14(%rsp),%rdx
xor    %esi,%esi
call   1060 <vis5d_get_hclip@plt>
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <vis5d_get_clip_mode@plt>
cmpl   $0x1,0xc(%rsp)
jne    11f8 <find_nearest_clip_slice+0xa8>
movss  0x14(%rsp),%xmm0
lea    0x10(%rsp),%r8
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1030 <distance_to_hclip@plt>
movss  0xe36(%rip),%xmm1
movss  %xmm1,0x8(%rsp)
ucomiss %xmm0,%xmm1
jbe    1206 <find_nearest_clip_slice+0xb6>
mov    0x18(%rsp),%rax
movl   $0x0,(%rax)
mov    0x20(%rsp),%rax
movl   $0x0,(%rax)
mov    0x10(%rsp),%eax
mov    0x28(%rsp),%rcx
mov    %eax,(%rcx)
jmp    1200 <find_nearest_clip_slice+0xb0>
movss  0xe00(%rip),%xmm0
movss  %xmm0,0x8(%rsp)
lea    0x14(%rsp),%rdx
mov    %ebp,%edi
mov    $0x1,%esi
call   1060 <vis5d_get_hclip@plt>
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
mov    $0x1,%esi
call   1040 <vis5d_get_clip_mode@plt>
cmpl   $0x1,0xc(%rsp)
mov    %r14d,0x34(%rsp)
mov    %ebx,0x30(%rsp)
jne    1286 <find_nearest_clip_slice+0x136>
movss  0x14(%rsp),%xmm0
lea    0x10(%rsp),%r8
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14d,%edx
mov    $0x1,%ecx
call   1030 <distance_to_hclip@plt>
movss  0x8(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jbe    1286 <find_nearest_clip_slice+0x136>
mov    0x18(%rsp),%rax
movl   $0x0,(%rax)
mov    0x20(%rsp),%rax
movl   $0x1,(%rax)
mov    0x10(%rsp),%eax
mov    0x28(%rsp),%rcx
mov    %eax,(%rcx)
movss  %xmm0,0x8(%rsp)
xor    %r14d,%r14d
lea    0x40(%rsp),%r12
lea    0x3c(%rsp),%r13
lea    0x38(%rsp),%rbx
lea    0xc(%rsp),%r15
jmp    12ae <find_nearest_clip_slice+0x15e>
nop
add    $0x1,%r14d
cmp    $0x4,%r14d
je     133e <find_nearest_clip_slice+0x1ee>
mov    %ebp,%edi
mov    %r14d,%esi
lea    0x44(%rsp),%rdx
mov    %r12,%rcx
mov    %r13,%r8
mov    %rbx,%r9
call   1070 <vis5d_get_vclip@plt>
lea    0x2(%r14),%esi
mov    %ebp,%edi
mov    %r15,%rdx
call   1040 <vis5d_get_clip_mode@plt>
cmpl   $0x1,0xc(%rsp)
jne    12a0 <find_nearest_clip_slice+0x150>
movss  0x44(%rsp),%xmm0
movss  0x40(%rsp),%xmm1
movss  0x3c(%rsp),%xmm2
movss  0x38(%rsp),%xmm3
mov    %ebp,%edi
mov    0x30(%rsp),%esi
mov    0x34(%rsp),%edx
mov    %r14d,%ecx
lea    0x10(%rsp),%r8
call   1050 <distance_to_vclip@plt>
movss  0x8(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jbe    12a0 <find_nearest_clip_slice+0x150>
mov    0x18(%rsp),%rax
movl   $0x1,(%rax)
mov    0x20(%rsp),%rax
mov    %r14d,(%rax)
mov    0x10(%rsp),%eax
mov    0x28(%rsp),%rcx
mov    %eax,(%rcx)
movss  %xmm0,0x8(%rsp)
jmp    12a0 <find_nearest_clip_slice+0x150>
xor    %eax,%eax
mov    0x18(%rsp),%rcx
cmpl   $0xffffffff,(%rcx)
setne  %al
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @find_nearest_clip_slice(i32 %0, i32 %1, i32 %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca float
%15 = alloca float
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca float
%20 = alloca float
%21 = alloca float
%22 = alloca float
%23 = alloca float
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 i32* %5, i32** %13
store float 2.250000e+02, float* %15
%24 = load i32*, i32** %13
store i32 -1, i32* %24
%25 = load i32*, i32** %12
store i32 -1, i32* %25
%26 = load i32*, i32** %11
store i32 -1, i32* %26
store i32 0, i32* %16
br label %27
27: ; preds = %58, %6
%28 = load i32, i32* %16
%29 = icmp slt i32 %28, 2
br i1 %29, label %30, label %61
30: ; preds = %27
%31 = load i32, i32* %8
%32 = load i32, i32* %16
%33 = call i32 @vis5d_get_hclip(i32 %31, i32 %32, float* %19)
%34 = load i32, i32* %8
%35 = load i32, i32* %16
%36 = call i32 @vis5d_get_clip_mode(i32 %34, i32 %35, i32* %18)
%37 = load i32, i32* %18
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %57
39: ; preds = %30
%40 = load i32, i32* %8
%41 = load i32, i32* %9
%42 = load i32, i32* %10
%43 = load i32, i32* %16
%44 = load float, float* %19
%45 = call float @distance_to_hclip(i32 %40, i32 %41, i32 %42, i32 %43, float %44, i32* %17)
store float %45, float* %14
%46 = load float, float* %14
%47 = load float, float* %15
%48 = fcmp olt float %46, %47
br i1 %48, label %49, label %56
49: ; preds = %39
%50 = load float, float* %14
store float %50, float* %15
%51 = load i32*, i32** %11
store i32 0, i32* %51
%52 = load i32, i32* %16
%53 = load i32*, i32** %12
store i32 %52, i32* %53
%54 = load i32, i32* %17
%55 = load i32*, i32** %13
store i32 %54, i32* %55
br label %56
56: ; preds = %49, %39
br label %57
57: ; preds = %56, %30
br label %58
58: ; preds = %57
%59 = load i32, i32* %16
%60 = add nsw i32 %59, 1
store i32 %60, i32* %16
br label %27
61: ; preds = %27
store i32 0, i32* %16
br label %62
62: ; preds = %97, %61
%63 = load i32, i32* %16
%64 = icmp slt i32 %63, 4
br i1 %64, label %65, label %100
65: ; preds = %62
%66 = load i32, i32* %8
%67 = load i32, i32* %16
%68 = call i32 @vis5d_get_vclip(i32 %66, i32 %67, float* %20, float* %21, float* %22, float* %23)
%69 = load i32, i32* %8
%70 = load i32, i32* %16
%71 = add nsw i32 %70, 2
%72 = call i32 @vis5d_get_clip_mode(i32 %69, i32 %71, i32* %18)
%73 = load i32, i32* %18
%74 = icmp eq i32 %73, 1
br i1 %74, label %75, label %96
75: ; preds = %65
%76 = load i32, i32* %8
%77 = load i32, i32* %9
%78 = load i32, i32* %10
%79 = load i32, i32* %16
%80 = load float, float* %20
%81 = load float, float* %21
%82 = load float, float* %22
%83 = load float, float* %23
%84 = call float @distance_to_vclip(i32 %76, i32 %77, i32 %78, i32 %79, float %80, float %81, float %82, float %83, i32* %17)
store float %84, float* %14
%85 = load float, float* %14
%86 = load float, float* %15
%87 = fcmp olt float %85, %86
br i1 %87, label %88, label %95
88: ; preds = %75
%89 = load float, float* %14
store float %89, float* %15
%90 = load i32*, i32** %11
store i32 1, i32* %90
%91 = load i32, i32* %16
%92 = load i32*, i32** %12
store i32 %91, i32* %92
%93 = load i32, i32* %17
%94 = load i32*, i32** %13
store i32 %93, i32* %94
br label %95
95: ; preds = %88, %75
br label %96
96: ; preds = %95, %65
br label %97
97: ; preds = %96
%98 = load i32, i32* %16
%99 = add nsw i32 %98, 1
store i32 %99, i32* %16
br label %62
100: ; preds = %62
%101 = load i32*, i32** %11
%102 = load i32, i32* %101
%103 = icmp ne i32 %102, -1
br i1 %103, label %104, label %105
104: ; preds = %100
store i32 1, i32* %7
br label %106
105: ; preds = %100
store i32 0, i32* %7
br label %106
106: ; preds = %105, %104
%107 = load i32, i32* %7
ret i32 %107
}

LLVM IR (-O2):
define i32 @find_nearest_clip_slice(i32 %0, i32 %1, i32 %2, i32* nocapture %3, i32* nocapture writeonly %4, i32* nocapture writeonly %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
%14 = bitcast i32* %7 to i8*
%15 = bitcast i32* %8 to i8*
%16 = bitcast float* %9 to i8*
%17 = bitcast float* %10 to i8*
%18 = bitcast float* %11 to i8*
%19 = bitcast float* %12 to i8*
%20 = bitcast float* %13 to i8*
store i32 -1, i32* %5
store i32 -1, i32* %4
store i32 -1, i32* %3
%21 = call i32 @vis5d_get_hclip(i32 %0, i32 0, float* %9)
%22 = call i32 @vis5d_get_clip_mode(i32 %0, i32 0, i32* %8)
%23 = load i32, i32* %8
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %31
25: ; preds = %6
%26 = load float, float* %9
%27 = call float @distance_to_hclip(i32 %0, i32 %1, i32 %2, i32 0, float %26, i32* %7)
%28 = fcmp olt float %27, 2.250000e+02
br i1 %28, label %29, label %31
29: ; preds = %25
store i32 0, i32* %3
store i32 0, i32* %4
%30 = load i32, i32* %7
store i32 %30, i32* %5
br label %31
31: ; preds = %6, %29, %25
%32 = phi float [ %27, %29 ], [ 2.250000e+02, %25 ], [ 2.250000e+02, %6 ]
%33 = call i32 @vis5d_get_hclip(i32 %0, i32 1, float* %9)
%34 = call i32 @vis5d_get_clip_mode(i32 %0, i32 1, i32* %8)
%35 = load i32, i32* %8
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %43
37: ; preds = %31
%38 = load float, float* %9
%39 = call float @distance_to_hclip(i32 %0, i32 %1, i32 %2, i32 1, float %38, i32* %7)
%40 = fcmp olt float %39, %32
br i1 %40, label %41, label %43
41: ; preds = %37
store i32 0, i32* %3
store i32 1, i32* %4
%42 = load i32, i32* %7
store i32 %42, i32* %5
br label %43
43: ; preds = %41, %37, %31
%44 = phi float [ %32, %31 ], [ %32, %37 ], [ %39, %41 ]
br label %45
45: ; preds = %43, %62
%46 = phi i32 [ %64, %62 ], [ 0, %43 ]
%47 = phi float [ %63, %62 ], [ %44, %43 ]
%48 = call i32 @vis5d_get_vclip(i32 %0, i32 %46, float* %10, float* %11, float* %12, float* %13)
%49 = add nuw nsw i32 %46, 2
%50 = call i32 @vis5d_get_clip_mode(i32 %0, i32 %49, i32* %8)
%51 = load i32, i32* %8
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %62
53: ; preds = %45
%54 = load float, float* %10
%55 = load float, float* %11
%56 = load float, float* %12
%57 = load float, float* %13
%58 = call float @distance_to_vclip(i32 %0, i32 %1, i32 %2, i32 %46, float %54, float %55, float %56, float %57, i32* %7)
%59 = fcmp olt float %58, %47
br i1 %59, label %60, label %62
60: ; preds = %53
store i32 1, i32* %3
store i32 %46, i32* %4
%61 = load i32, i32* %7
store i32 %61, i32* %5
br label %62
62: ; preds = %45, %60, %53
%63 = phi float [ %58, %60 ], [ %47, %53 ], [ %47, %45 ]
%64 = add nuw nsw i32 %46, 1
%65 = icmp eq i32 %64, 4
br i1 %65, label %66, label %45
66: ; preds = %62
%67 = load i32, i32* %3
%68 = icmp ne i32 %67, -1
%69 = zext i1 %68 to i32
ret i32 %69
}