#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*/ exit(int);
int getTokensInRow(char **, char, int, int, char, char);
int /*<<< orphan*/ perror(char *);
signed char hasPlayerWon(char board[7][6], int x, int y, char xDir, char yDir) {
  char color = board[x][y];
  int tokensInRow = getTokensInRow(board, color, x, y, xDir, yDir) +
                    getTokensInRow(board, color, x, y, -xDir, -yDir) - 1;
  if (tokensInRow >= 4) {
    if (color == 'r') {
      return 1;
    } else if (color == 'b') {
      return -1;
    } else {
      perror("this color doesn't / shouldn't exist\n");
      exit(1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<hasPlayerWon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8b,%al
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %cl,-0x19(%rbp)
mov    %al,-0x1a(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0x6,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1b(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1b(%rbp),%sil
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x19(%rbp),%al
movsbl %sil,%esi
movsbl %al,%r8d
movsbl -0x1a(%rbp),%r9d
call   1030 <getTokensInRow@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1b(%rbp),%sil
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
movsbl -0x19(%rbp),%r8d
xor    %eax,%eax
sub    %r8d,%eax
mov    %al,%r8b
movsbl -0x1a(%rbp),%r9d
xor    %eax,%eax
sub    %r9d,%eax
movsbl %sil,%esi
movsbl %r8b,%r8d
movsbl %al,%r9d
call   1030 <getTokensInRow@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jl     1219 <hasPlayerWon+0xe9>
movsbl -0x1b(%rbp),%eax
cmp    $0x72,%eax
jne    11ed <hasPlayerWon+0xbd>
movb   $0x1,-0x1(%rbp)
jmp    121d <hasPlayerWon+0xed>
movsbl -0x1b(%rbp),%eax
cmp    $0x62,%eax
jne    1203 <hasPlayerWon+0xd3>
movb   $0xff,-0x1(%rbp)
jmp    121d <hasPlayerWon+0xed>
lea    0xdf6(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hasPlayerWon>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%ebx
mov    %ecx,%ebp
mov    %rdi,%r14
movslq %esi,%r15
movslq %edx,%r12
lea    (%r15,%r15,2),%rax
lea    (%rdi,%rax,2),%rax
mov    (%r12,%rax,1),%al
mov    %al,0x3(%rsp)
movsbl %al,%r13d
mov    %r13d,%esi
mov    %r15d,%edx
mov    %r12d,%ecx
mov    %ebp,%r8d
mov    %ebx,%r9d
call   1030 <getTokensInRow@plt>
mov    %eax,0x4(%rsp)
neg    %bpl
neg    %bl
movsbl %bpl,%r8d
movsbl %bl,%r9d
mov    %r14,%rdi
mov    %r13d,%esi
mov    %r15d,%edx
mov    %r12d,%ecx
call   1030 <getTokensInRow@plt>
add    0x4(%rsp),%eax
cmp    $0x5,%eax
jl     11b0 <hasPlayerWon+0x80>
mov    $0x1,%al
mov    0x3(%rsp),%cl
cmp    $0x72,%cl
je     11b2 <hasPlayerWon+0x82>
cmp    $0x62,%cl
jne    11c1 <hasPlayerWon+0x91>
mov    $0xff,%al
jmp    11b2 <hasPlayerWon+0x82>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe38(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"this color doesn't / shouldn't exist\0A\00"
define signext i8 @hasPlayerWon([6 x i8]* %0, i32 %1, i32 %2, i8 signext %3, i8 signext %4) {
%6 = alloca i8
%7 = alloca [6 x i8]*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8
%13 = alloca i32
store [6 x i8]* %0, [6 x i8]** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8 %3, i8* %10
store i8 %4, i8* %11
%14 = load [6 x i8]*, [6 x i8]** %7
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [6 x i8], [6 x i8]* %14, i64 %16
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %17, i64 0, i64 %19
%21 = load i8, i8* %20
store i8 %21, i8* %12
%22 = load [6 x i8]*, [6 x i8]** %7
%23 = bitcast [6 x i8]* %22 to i8**
%24 = load i8, i8* %12
%25 = load i32, i32* %8
%26 = load i32, i32* %9
%27 = load i8, i8* %10
%28 = load i8, i8* %11
%29 = call i32 @getTokensInRow(i8** %23, i8 signext %24, i32 %25, i32 %26, i8 signext %27, i8 signext %28)
%30 = load [6 x i8]*, [6 x i8]** %7
%31 = bitcast [6 x i8]* %30 to i8**
%32 = load i8, i8* %12
%33 = load i32, i32* %8
%34 = load i32, i32* %9
%35 = load i8, i8* %10
%36 = sext i8 %35 to i32
%37 = sub nsw i32 0, %36
%38 = trunc i32 %37 to i8
%39 = load i8, i8* %11
%40 = sext i8 %39 to i32
%41 = sub nsw i32 0, %40
%42 = trunc i32 %41 to i8
%43 = call i32 @getTokensInRow(i8** %31, i8 signext %32, i32 %33, i32 %34, i8 signext %38, i8 signext %42)
%44 = add nsw i32 %29, %43
%45 = sub nsw i32 %44, 1
store i32 %45, i32* %13
%46 = load i32, i32* %13
%47 = icmp sge i32 %46, 4
br i1 %47, label %48, label %61
48: ; preds = %5
%49 = load i8, i8* %12
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 114
br i1 %51, label %52, label %53
52: ; preds = %48
store i8 1, i8* %6
br label %62
53: ; preds = %48
%54 = load i8, i8* %12
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 98
br i1 %56, label %57, label %58
57: ; preds = %53
store i8 -1, i8* %6
br label %62
58: ; preds = %53
%59 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %5
store i8 0, i8* %6
br label %62
62: ; preds = %61, %57, %52
%63 = load i8, i8* %6
ret i8 %63
}

LLVM IR (-O2):
@.str = [38 x i8] c"this color doesn't / shouldn't exist\0A\00"
define signext i8 @hasPlayerWon([6 x i8]* %0, i32 %1, i32 %2, i8 signext %3, i8 signext %4) {
%6 = sext i32 %1 to i64
%7 = sext i32 %2 to i64
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %0, i64 %6, i64 %7
%9 = load i8, i8* %8
%10 = bitcast [6 x i8]* %0 to i8**
%11 = tail call i32 @getTokensInRow(i8** %10, i8 signext %9, i32 %1, i32 %2, i8 signext %3, i8 signext %4)
%12 = sub i8 0, %3
%13 = sub i8 0, %4
%14 = tail call i32 @getTokensInRow(i8** %10, i8 signext %9, i32 %1, i32 %2, i8 signext %12, i8 signext %13)
%15 = add nsw i32 %14, %11
%16 = icmp sgt i32 %15, 4
br i1 %16, label %17, label %22
17: ; preds = %5
switch i8 %9, label %19 [
i8 114, label %22
i8 98, label %18
]
18: ; preds = %17
br label %22
19: ; preds = %17
%20 = tail call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %5, %17, %18
%23 = phi i8 [ -1, %18 ], [ 1, %17 ], [ 0, %5 ]
ret i8 %23
}