int endofgame(board)
int board[];
{
  int eval;
  int count;
  eval = stateval(board, 1);
  if (eval == 100) {
    printf("I have beaten you.\n");
    return (1);
  }
  if (eval == -100) {
    printf("Bus error (core dumped)\n");
    return (1);
  }
  count = 0;
  for (eval = 0; eval < 9; eval++)
    if (board[eval] != 0)
      count++;
  if (count == 9) {
    printf("A draw!\n");
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<endofgame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <stateval@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jne    1163 <endofgame+0x43>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f8 <endofgame+0xd8>
cmpl   $0xffffff9c,-0x14(%rbp)
jne    1187 <endofgame+0x67>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f8 <endofgame+0xd8>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x9,-0x14(%rbp)
jge    11cd <endofgame+0xad>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     11ba <endofgame+0x9a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bf <endofgame+0x9f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1195 <endofgame+0x75>
cmpl   $0x9,-0x18(%rbp)
jne    11f1 <endofgame+0xd1>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f8 <endofgame+0xd8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endofgame>:
push   %rbx
mov    %rdi,%rbx
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <stateval@plt>
cmp    $0xffffff9c,%eax
je     1143 <endofgame+0x23>
cmp    $0x64,%eax
jne    114c <endofgame+0x2c>
lea    0xedf(%rip),%rdi
jmp    11b0 <endofgame+0x90>
lea    0xebe(%rip),%rdi
jmp    11b0 <endofgame+0x90>
movdqu (%rbx),%xmm0
movdqu 0x10(%rbx),%xmm1
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm1
pcmpeqd %xmm3,%xmm3
pxor   %xmm3,%xmm1
pcmpeqd %xmm2,%xmm0
pxor   %xmm3,%xmm0
packssdw %xmm1,%xmm0
packsswb %xmm0,%xmm0
pmovmskb %xmm0,%eax
mov    %eax,%ecx
shr    %cl
and    $0x55,%cl
sub    %cl,%al
mov    %eax,%ecx
and    $0x33,%cl
shr    $0x2,%al
and    $0x33,%al
add    %cl,%al
mov    %eax,%ecx
shr    $0x4,%cl
add    %al,%cl
and    $0xf,%cl
movzbl %cl,%ecx
cmpl   $0x1,0x20(%rbx)
sbb    $0xffffffff,%ecx
xor    %eax,%eax
cmp    $0x9,%ecx
jne    11ba <endofgame+0x9a>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"I have beaten you.\0A\00"
@.str.1 = [25 x i8] c"Bus error (core dumped)\0A\00"
@.str.2 = [9 x i8] c"A draw!\0A\00"
define i32 @endofgame(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = call i32 (i32*, i32, ...) bitcast (i32 (...)* @stateval to i32 (i32*, i32, ...)*)(i32* %6, i32 1)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 100
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %41
12: ; preds = %1
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, -100
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %41
17: ; preds = %12
store i32 0, i32* %5
store i32 0, i32* %4
br label %18
18: ; preds = %32, %17
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 9
br i1 %20, label %21, label %35
21: ; preds = %18
%22 = load i32*, i32** %3
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %31
31: ; preds = %28, %21
br label %32
32: ; preds = %31
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %18
35: ; preds = %18
%36 = load i32, i32* %5
%37 = icmp eq i32 %36, 9
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %41
40: ; preds = %35
store i32 0, i32* %2
br label %41
41: ; preds = %40, %38, %15, %10
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@str = [8 x i8] c"A draw!\00"
@str.3 = [24 x i8] c"Bus error (core dumped)\00"
@str.4 = [19 x i8] c"I have beaten you.\00"
define i32 @endofgame(i32* %0) {
%2 = tail call i32 (i32*, i32, ...) bitcast (i32 (...)* @stateval to i32 (i32*, i32, ...)*)(i32* %0, i32 1)
switch i32 %2, label %3 [
i32 100, label %17
i32 -100, label %16
]
3: ; preds = %1
%4 = bitcast i32* %0 to <8 x i32>*
%5 = load <8 x i32>, <8 x i32>* %4
%6 = icmp ne <8 x i32> %5, zeroinitializer
%7 = getelementptr inbounds i32, i32* %0, i64 8
%8 = load i32, i32* %7
%9 = icmp ne i32 %8, 0
%10 = zext i1 %9 to i32
%11 = bitcast <8 x i1> %6 to i8
%12 = call i8 @llvm.ctpop.i8(i8 %11)
%13 = zext i8 %12 to i32
%14 = add nuw nsw i32 %13, %10
%15 = icmp eq i32 %14, 9
br i1 %15, label %17, label %20
16: ; preds = %1
br label %17
17: ; preds = %3, %1, %16
%18 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @str.3, i64 0, i64 0), %16 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0), %1 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0), %3 ]
%19 = tail call i32 @puts(i8* dereferenceable(1) %18)
br label %20
20: ; preds = %17, %3
%21 = phi i32 [ 0, %3 ], [ 1, %17 ]
ret i32 %21
}