#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 */
char const board_get_position(int, int);
char board_count_moves(const char player_id) {
  int count = 0;
  int i;
  int j;
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      if (board_get_position(i, j) == player_id) {
        count++;
      }
    }
  }
  if (player_id == 0) {
    return 9 - count;
  } else {
    return count;
  }
}


x86 assembly (clang, -O0):
<board_count_moves>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    1190 <board_count_moves+0x80>
movl   $0x0,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jge    117d <board_count_moves+0x6d>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <board_get_position@plt>
movsbl %al,%eax
movsbl -0x2(%rbp),%ecx
cmp    %ecx,%eax
jne    116a <board_count_moves+0x5a>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116f <board_count_moves+0x5f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113d <board_count_moves+0x2d>
jmp    1182 <board_count_moves+0x72>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112c <board_count_moves+0x1c>
movsbl -0x2(%rbp),%eax
cmp    $0x0,%eax
jne    11ad <board_count_moves+0x9d>
mov    $0x9,%eax
sub    -0x8(%rbp),%eax
mov    %al,-0x1(%rbp)
jmp    11b3 <board_count_moves+0xa3>
mov    -0x8(%rbp),%eax
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<board_count_moves>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
xor    %edi,%edi
xor    %esi,%esi
call   1030 <board_get_position@plt>
xor    %ebp,%ebp
cmp    %r14b,%al
sete   %bpl
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <board_get_position@plt>
xor    %ebx,%ebx
cmp    %r14b,%al
sete   %bl
add    %ebp,%ebx
xor    %edi,%edi
mov    $0x2,%esi
call   1030 <board_get_position@plt>
xor    %ebp,%ebp
cmp    %r14b,%al
sete   %bpl
add    %ebx,%ebp
mov    $0x1,%edi
xor    %esi,%esi
call   1030 <board_get_position@plt>
xor    %ebx,%ebx
cmp    %r14b,%al
sete   %bl
add    %ebp,%ebx
mov    $0x1,%edi
mov    $0x1,%esi
call   1030 <board_get_position@plt>
xor    %ebp,%ebp
cmp    %r14b,%al
sete   %bpl
add    %ebx,%ebp
mov    $0x1,%edi
mov    $0x2,%esi
call   1030 <board_get_position@plt>
xor    %ebx,%ebx
cmp    %r14b,%al
sete   %bl
add    %ebp,%ebx
mov    $0x2,%edi
xor    %esi,%esi
call   1030 <board_get_position@plt>
xor    %ebp,%ebp
cmp    %r14b,%al
sete   %bpl
add    %ebx,%ebp
mov    $0x2,%edi
mov    $0x1,%esi
call   1030 <board_get_position@plt>
xor    %ebx,%ebx
cmp    %r14b,%al
sete   %bl
add    %ebp,%ebx
mov    $0x2,%edi
mov    $0x2,%esi
call   1030 <board_get_position@plt>
xor    %ecx,%ecx
cmp    %r14b,%al
sete   %cl
add    %ebx,%ecx
mov    $0x9,%al
sub    %cl,%al
test   %r14b,%r14b
movzbl %al,%eax
cmovne %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @board_count_moves(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8 %0, i8* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %30, %1
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %33
10: ; preds = %7
store i32 0, i32* %6
br label %11
11: ; preds = %26, %10
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = call signext i8 @board_get_position(i32 %15, i32 %16)
%18 = sext i8 %17 to i32
%19 = load i8, i8* %3
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %18, %20
br i1 %21, label %22, label %25
22: ; preds = %14
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %25
25: ; preds = %22, %14
br label %26
26: ; preds = %25
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %11
29: ; preds = %11
br label %30
30: ; preds = %29
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %7
33: ; preds = %7
%34 = load i8, i8* %3
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i32, i32* %4
%39 = sub nsw i32 9, %38
%40 = trunc i32 %39 to i8
store i8 %40, i8* %2
br label %44
41: ; preds = %33
%42 = load i32, i32* %4
%43 = trunc i32 %42 to i8
store i8 %43, i8* %2
br label %44
44: ; preds = %41, %37
%45 = load i8, i8* %2
ret i8 %45
}

LLVM IR (-O2):
define signext i8 @board_count_moves(i8 signext %0) {
%2 = tail call signext i8 @board_get_position(i32 0, i32 0)
%3 = icmp eq i8 %2, %0
%4 = zext i1 %3 to i32
%5 = tail call signext i8 @board_get_position(i32 0, i32 1)
%6 = icmp eq i8 %5, %0
%7 = zext i1 %6 to i32
%8 = add nuw nsw i32 %4, %7
%9 = tail call signext i8 @board_get_position(i32 0, i32 2)
%10 = icmp eq i8 %9, %0
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %8, %11
%13 = tail call signext i8 @board_get_position(i32 1, i32 0)
%14 = icmp eq i8 %13, %0
%15 = zext i1 %14 to i32
%16 = add nuw nsw i32 %12, %15
%17 = tail call signext i8 @board_get_position(i32 1, i32 1)
%18 = icmp eq i8 %17, %0
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %16, %19
%21 = tail call signext i8 @board_get_position(i32 1, i32 2)
%22 = icmp eq i8 %21, %0
%23 = zext i1 %22 to i32
%24 = add nuw nsw i32 %20, %23
%25 = tail call signext i8 @board_get_position(i32 2, i32 0)
%26 = icmp eq i8 %25, %0
%27 = zext i1 %26 to i32
%28 = add nuw nsw i32 %24, %27
%29 = tail call signext i8 @board_get_position(i32 2, i32 1)
%30 = icmp eq i8 %29, %0
%31 = zext i1 %30 to i32
%32 = add nuw nsw i32 %28, %31
%33 = tail call signext i8 @board_get_position(i32 2, i32 2)
%34 = icmp eq i8 %33, %0
%35 = zext i1 %34 to i32
%36 = add nuw nsw i32 %32, %35
%37 = icmp eq i8 %0, 0
%38 = sub nuw nsw i32 9, %36
%39 = select i1 %37, i32 %38, i32 %36
%40 = trunc i32 %39 to i8
ret i8 %40
}