#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 */
struct connect4 {
  int dummy;
};

/* Variables and functions */
int g3_countOutwards(struct connect4 const *, int, int, int const, int const,
                     char);
int g3_is3WinDirection(const struct connect4 *game, int row, int col, int dir,
                       char piece) {
  const int DX[] = {-1, -1, -1, 0, 0, 1, 1, 1};
  const int DY[] = {-1, 1, 0, -1, 1, 0, -1, 1};
  int check3 = g3_countOutwards(game, row, col, DX[dir], DY[dir], piece) +
               g3_countOutwards(game, row, col, -DX[dir], -DY[dir], piece);
  return check3 >= 3;
}


x86 assembly (clang, -O0):
<g3_is3WinDirection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %r8b,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %al,-0x15(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xecb(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xec8(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xec5(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xec2(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xebf(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xebc(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xeb9(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
movslq -0x14(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%ecx
movslq -0x14(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%r8d
movsbl -0x15(%rbp),%r9d
call   1030 <g3_countOutwards@plt>
mov    %eax,-0x68(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
movslq -0x14(%rbp),%rax
xor    %ecx,%ecx
sub    -0x40(%rbp,%rax,4),%ecx
movslq -0x14(%rbp),%rax
xor    %r8d,%r8d
sub    -0x60(%rbp,%rax,4),%r8d
movsbl -0x15(%rbp),%r9d
call   1030 <g3_countOutwards@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x64(%rbp)
cmpl   $0x3,-0x64(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<g3_is3WinDirection>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%r13
movslq %ecx,%rax
lea    0xecf(%rip),%rcx
mov    (%rcx,%rax,4),%ebx
lea    0xee5(%rip),%rcx
mov    (%rcx,%rax,4),%ebp
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %r14d,%r9d
call   1030 <g3_countOutwards@plt>
mov    %eax,0x4(%rsp)
neg    %ebx
neg    %ebp
mov    %r13,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %r14d,%r9d
call   1030 <g3_countOutwards@plt>
add    0x4(%rsp),%eax
xor    %ecx,%ecx
cmp    $0x3,%eax
setge  %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.connect4 = type { i32 }
@__const.g3_is3WinDirection.DX = [8 x i32] [i32 -1, i32 -1, i32 -1, i32 0, i32 0, i32 1, i32 1, i32 1]
@__const.g3_is3WinDirection.DY = [8 x i32] [i32 -1, i32 1, i32 0, i32 -1, i32 1, i32 0, i32 -1, i32 1]
define i32 @g3_is3WinDirection(%struct.connect4* %0, i32 %1, i32 %2, i32 %3, i8 signext %4) {
%6 = alloca %struct.connect4*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca [8 x i32]
%12 = alloca [8 x i32]
%13 = alloca i32
store %struct.connect4* %0, %struct.connect4** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8 %4, i8* %10
%14 = bitcast [8 x i32]* %11 to i8*
%15 = bitcast [8 x i32]* %12 to i8*
%16 = load %struct.connect4*, %struct.connect4** %6
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [8 x i32], [8 x i32]* %11, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [8 x i32], [8 x i32]* %12, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = load i8, i8* %10
%28 = call i32 @g3_countOutwards(%struct.connect4* %16, i32 %17, i32 %18, i32 %22, i32 %26, i8 signext %27)
%29 = load %struct.connect4*, %struct.connect4** %6
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [8 x i32], [8 x i32]* %11, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = sub nsw i32 0, %35
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [8 x i32], [8 x i32]* %12, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = sub nsw i32 0, %40
%42 = load i8, i8* %10
%43 = call i32 @g3_countOutwards(%struct.connect4* %29, i32 %30, i32 %31, i32 %36, i32 %41, i8 signext %42)
%44 = add nsw i32 %28, %43
store i32 %44, i32* %13
%45 = load i32, i32* %13
%46 = icmp sge i32 %45, 3
%47 = zext i1 %46 to i32
ret i32 %47
}

LLVM IR (-O2):
%struct.connect4 = type { i32 }
@__const.g3_is3WinDirection.DX = [8 x i32] [i32 -1, i32 -1, i32 -1, i32 0, i32 0, i32 1, i32 1, i32 1]
@__const.g3_is3WinDirection.DY = [8 x i32] [i32 -1, i32 1, i32 0, i32 -1, i32 1, i32 0, i32 -1, i32 1]
define i32 @g3_is3WinDirection(%struct.connect4* %0, i32 %1, i32 %2, i32 %3, i8 signext %4) {
%6 = sext i32 %3 to i64
%7 = getelementptr inbounds [8 x i32], [8 x i32]* @__const.g3_is3WinDirection.DX, i64 0, i64 %6
%8 = load i32, i32* %7
%9 = getelementptr inbounds [8 x i32], [8 x i32]* @__const.g3_is3WinDirection.DY, i64 0, i64 %6
%10 = load i32, i32* %9
%11 = tail call i32 @g3_countOutwards(%struct.connect4* %0, i32 %1, i32 %2, i32 %8, i32 %10, i8 signext %4)
%12 = sub nsw i32 0, %8
%13 = sub nsw i32 0, %10
%14 = tail call i32 @g3_countOutwards(%struct.connect4* %0, i32 %1, i32 %2, i32 %12, i32 %13, i8 signext %4)
%15 = add nsw i32 %14, %11
%16 = icmp sgt i32 %15, 2
%17 = zext i1 %16 to i32
ret i32 %17
}