int endofgame(board)
int board[];
{
  int eval;
  int count;
  eval = stateval(board, 1);
  move(20, 25);
  if (eval == 100) {
    printw("I have beaten you.\n");
    return (1);
  }
  if (eval == -100) {
    printw("Bus error (core dumped)\n");
    return (1);
  }
  count = 0;
  for (eval = 0; eval < 9; eval++)
    if (board[eval] != 0)
      count++;
  if (count == 9) {
    printw("A draw!\n");
    return (1);
  }
  refresh();
  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   1050 <stateval@plt>
mov    %eax,-0x14(%rbp)
mov    $0x14,%edi
mov    $0x19,%esi
mov    $0x0,%al
call   1060 <move@plt>
cmpl   $0x64,-0x14(%rbp)
jne    1194 <endofgame+0x54>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printw@plt>
movl   $0x1,-0x4(%rbp)
jmp    1230 <endofgame+0xf0>
cmpl   $0xffffff9c,-0x14(%rbp)
jne    11b8 <endofgame+0x78>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printw@plt>
movl   $0x1,-0x4(%rbp)
jmp    1230 <endofgame+0xf0>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x9,-0x14(%rbp)
jge    11fe <endofgame+0xbe>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     11eb <endofgame+0xab>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11f0 <endofgame+0xb0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c6 <endofgame+0x86>
cmpl   $0x9,-0x18(%rbp)
jne    1222 <endofgame+0xe2>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printw@plt>
movl   $0x1,-0x4(%rbp)
jmp    1230 <endofgame+0xf0>
mov    $0x0,%al
call   1040 <refresh@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endofgame>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x1,%ebp
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <stateval@plt>
mov    %eax,%ebx
mov    $0x14,%edi
mov    $0x19,%esi
xor    %eax,%eax
call   1060 <move@plt>
cmp    $0xffffff9c,%ebx
je     117e <endofgame+0x3e>
cmp    $0x64,%ebx
jne    118e <endofgame+0x4e>
lea    0xe84(%rip),%rdi
jmp    11f3 <endofgame+0xb3>
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1030 <printw@plt>
jmp    120a <endofgame+0xca>
movdqu (%r14),%xmm0
movdqu 0x10(%r14),%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
cmpl   $0x1,0x20(%r14)
movzbl %cl,%eax
sbb    $0xffffffff,%eax
cmp    $0x9,%eax
jne    1201 <endofgame+0xc1>
lea    0xe3a(%rip),%rdi
xor    %eax,%eax
call   1030 <printw@plt>
mov    $0x1,%ebp
jmp    120a <endofgame+0xca>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <refresh@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
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 = call i32 (i32, i32, ...) bitcast (i32 (...)* @move to i32 (i32, i32, ...)*)(i32 20, i32 25)
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 100
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 (i8*, ...) bitcast (i32 (...)* @printw to i32 (i8*, ...)*)(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %43
13: ; preds = %1
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, -100
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (i8*, ...) bitcast (i32 (...)* @printw to i32 (i8*, ...)*)(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %43
18: ; preds = %13
store i32 0, i32* %5
store i32 0, i32* %4
br label %19
19: ; preds = %33, %18
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 9
br i1 %21, label %22, label %36
22: ; preds = %19
%23 = load i32*, i32** %3
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %32
32: ; preds = %29, %22
br label %33
33: ; preds = %32
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %19
36: ; preds = %19
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, 9
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 (i8*, ...) bitcast (i32 (...)* @printw to i32 (i8*, ...)*)(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %43
41: ; preds = %36
%42 = call i32 (...) @refresh()
store i32 0, i32* %2
br label %43
43: ; preds = %41, %39, %16, %11
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
@.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 = tail call i32 (i32*, i32, ...) bitcast (i32 (...)* @stateval to i32 (i32*, i32, ...)*)(i32* %0, i32 1)
%3 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @move to i32 (i32, i32, ...)*)(i32 20, i32 25)
switch i32 %2, label %4 [
i32 100, label %17
i32 -100, label %19
]
4: ; preds = %1
%5 = bitcast i32* %0 to <8 x i32>*
%6 = load <8 x i32>, <8 x i32>* %5
%7 = icmp ne <8 x i32> %6, zeroinitializer
%8 = getelementptr inbounds i32, i32* %0, i64 8
%9 = load i32, i32* %8
%10 = icmp ne i32 %9, 0
%11 = zext i1 %10 to i32
%12 = bitcast <8 x i1> %7 to i8
%13 = call i8 @llvm.ctpop.i8(i8 %12)
%14 = zext i8 %13 to i32
%15 = add nuw nsw i32 %14, %11
%16 = icmp eq i32 %15, 9
br i1 %16, label %21, label %23
17: ; preds = %1
%18 = tail call i32 (i8*, ...) bitcast (i32 (...)* @printw to i32 (i8*, ...)*)(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %25
19: ; preds = %1
%20 = tail call i32 (i8*, ...) bitcast (i32 (...)* @printw to i32 (i8*, ...)*)(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %25
21: ; preds = %4
%22 = tail call i32 (i8*, ...) bitcast (i32 (...)* @printw to i32 (i8*, ...)*)(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %25
23: ; preds = %4
%24 = tail call i32 (...) @refresh()
br label %25
25: ; preds = %23, %21, %19, %17
%26 = phi i32 [ 1, %17 ], [ 1, %19 ], [ 1, %21 ], [ 0, %23 ]
ret i32 %26
}