#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 board_state {
  int dummy;
};

/* Variables and functions */
int generate_moves_black(struct board_state *, int /*<<< orphan*/ *);
int generate_moves_white(struct board_state *, int /*<<< orphan*/ *);
int /*<<< orphan*/ in_check(struct board_state *, int);
int in_stalemate(struct board_state *board, int color) {
  int move_count;
  switch (color) {
  case 0:
    move_count = generate_moves_white(board, NULL);
    break;
  case 1:
    move_count = generate_moves_black(board, NULL);
    break;
  }
  return !in_check(board, color) && move_count == 0;
}


x86 assembly (clang, -O0):
<in_stalemate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     1163 <in_stalemate+0x33>
jmp    1152 <in_stalemate+0x22>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     1178 <in_stalemate+0x48>
jmp    1188 <in_stalemate+0x58>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <generate_moves_white@plt>
mov    %eax,-0x10(%rbp)
jmp    1188 <in_stalemate+0x58>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <generate_moves_black@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <in_check@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
jne    11ae <in_stalemate+0x7e>
cmpl   $0x0,-0x10(%rbp)
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<in_stalemate>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
cmp    $0x1,%esi
je     114e <in_stalemate+0x1e>
test   %ebx,%ebx
jne    115a <in_stalemate+0x2a>
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <generate_moves_white@plt>
jmp    1158 <in_stalemate+0x28>
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <generate_moves_black@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <in_check@plt>
xor    %ecx,%ecx
or     %ebp,%eax
sete   %cl
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.board_state = type { i32 }
define i32 @in_stalemate(%struct.board_state* %0, i32 %1) {
%3 = alloca %struct.board_state*
%4 = alloca i32
%5 = alloca i32
store %struct.board_state* %0, %struct.board_state** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
switch i32 %6, label %13 [
i32 0, label %7
i32 1, label %10
]
7: ; preds = %2
%8 = load %struct.board_state*, %struct.board_state** %3
%9 = call i32 @generate_moves_white(%struct.board_state* %8, i32* null)
store i32 %9, i32* %5
br label %13
10: ; preds = %2
%11 = load %struct.board_state*, %struct.board_state** %3
%12 = call i32 @generate_moves_black(%struct.board_state* %11, i32* null)
store i32 %12, i32* %5
br label %13
13: ; preds = %2, %10, %7
%14 = load %struct.board_state*, %struct.board_state** %3
%15 = load i32, i32* %4
%16 = call i32 @in_check(%struct.board_state* %14, i32 %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, 0
br label %21
21: ; preds = %18, %13
%22 = phi i1 [ false, %13 ], [ %20, %18 ]
%23 = zext i1 %22 to i32
ret i32 %23
}

LLVM IR (-O2):
%struct.board_state = type { i32 }
define i32 @in_stalemate(%struct.board_state* %0, i32 %1) {
switch i32 %1, label %7 [
i32 0, label %3
i32 1, label %5
]
3: ; preds = %2
%4 = tail call i32 @generate_moves_white(%struct.board_state* %0, i32* null)
br label %7
5: ; preds = %2
%6 = tail call i32 @generate_moves_black(%struct.board_state* %0, i32* null)
br label %7
7: ; preds = %2, %5, %3
%8 = phi i32 [ undef, %2 ], [ %6, %5 ], [ %4, %3 ]
%9 = tail call i32 @in_check(%struct.board_state* %0, i32 %1)
%10 = icmp eq i32 %9, 0
%11 = icmp eq i32 %8, 0
%12 = select i1 %10, i1 %11, i1 false
%13 = zext i1 %12 to i32
ret i32 %13
}