#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*/ Com_Printf(char *);
int CM_GridPlane(int gridPlanes[129][129][2], int i, int j, int tri) {
  int p;
  p = gridPlanes[i][j][tri];
  if (p != -1) {
    return p;
  }
  p = gridPlanes[i][j][!tri];
  if (p != -1) {
    return p;
  }
  Com_Printf("WARNING: CM_GridPlane unresolvable\n");
  return -1;
}


x86 assembly (clang, -O0):
<CM_GridPlane>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0x408,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
je     1161 <CM_GridPlane+0x51>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11bf <CM_GridPlane+0xaf>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0x408,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
cmpl   $0x0,-0x1c(%rbp)
setne  %cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
je     11ac <CM_GridPlane+0x9c>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11bf <CM_GridPlane+0xaf>
lea    0xe4d(%rip),%rdi
call   1030 <Com_Printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CM_GridPlane>:
push   %rax
movslq %esi,%rsi
movslq %edx,%rdx
movslq %ecx,%r8
mov    %rsi,%rax
shl    $0xa,%rax
lea    (%rax,%rsi,8),%rax
add    %rdi,%rax
lea    (%rax,%rdx,8),%rdx
mov    (%rdx,%r8,4),%eax
cmp    $0xffffffff,%eax
je     1137 <CM_GridPlane+0x27>
pop    %rcx
ret
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
mov    (%rdx,%rax,4),%eax
cmp    $0xffffffff,%eax
jne    1135 <CM_GridPlane+0x25>
lea    0xeb3(%rip),%rdi
call   1030 <Com_Printf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"WARNING: CM_GridPlane unresolvable\0A\00"
define i32 @CM_GridPlane([129 x [2 x i32]]* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca [129 x [2 x i32]]*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store [129 x [2 x i32]]* %0, [129 x [2 x i32]]** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load [129 x [2 x i32]]*, [129 x [2 x i32]]** %6
%12 = load i32, i32* %7
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [129 x [2 x i32]], [129 x [2 x i32]]* %11, i64 %13
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [129 x [2 x i32]], [129 x [2 x i32]]* %14, i64 0, i64 %16
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %17, i64 0, i64 %19
%21 = load i32, i32* %20
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %4
%25 = load i32, i32* %10
store i32 %25, i32* %5
br label %47
26: ; preds = %4
%27 = load [129 x [2 x i32]]*, [129 x [2 x i32]]** %6
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [129 x [2 x i32]], [129 x [2 x i32]]* %27, i64 %29
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [129 x [2 x i32]], [129 x [2 x i32]]* %30, i64 0, i64 %32
%34 = load i32, i32* %9
%35 = icmp ne i32 %34, 0
%36 = xor i1 %35, true
%37 = zext i1 %36 to i32
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %33, i64 0, i64 %38
%40 = load i32, i32* %39
store i32 %40, i32* %10
%41 = load i32, i32* %10
%42 = icmp ne i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %26
%44 = load i32, i32* %10
store i32 %44, i32* %5
br label %47
45: ; preds = %26
%46 = call i32 @Com_Printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %47
47: ; preds = %45, %43, %24
%48 = load i32, i32* %5
ret i32 %48
}

LLVM IR (-O2):
@.str = [36 x i8] c"WARNING: CM_GridPlane unresolvable\0A\00"
define i32 @CM_GridPlane([129 x [2 x i32]]* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = sext i32 %1 to i64
%6 = sext i32 %2 to i64
%7 = sext i32 %3 to i64
%8 = getelementptr inbounds [129 x [2 x i32]], [129 x [2 x i32]]* %0, i64 %5, i64 %6, i64 %7
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %19
11: ; preds = %4
%12 = icmp eq i32 %3, 0
%13 = zext i1 %12 to i64
%14 = getelementptr inbounds [129 x [2 x i32]], [129 x [2 x i32]]* %0, i64 %5, i64 %6, i64 %13
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = tail call i32 @Com_Printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %11, %4, %17
%20 = phi i32 [ -1, %17 ], [ %9, %4 ], [ %15, %11 ]
ret i32 %20
}