#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*/ *);
scalar_t__ in_check(struct board_state *, int);
int in_checkmate(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_checkmate>:
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_checkmate+0x33>
jmp    1152 <in_checkmate+0x22>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     1178 <in_checkmate+0x48>
jmp    1188 <in_checkmate+0x58>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <generate_moves_white@plt>
mov    %eax,-0x10(%rbp)
jmp    1188 <in_checkmate+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    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x15(%rbp)
je     11b0 <in_checkmate+0x80>
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_checkmate>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
cmp    $0x1,%esi
je     114e <in_checkmate+0x1e>
test   %ebx,%ebx
jne    115a <in_checkmate+0x2a>
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <generate_moves_white@plt>
jmp    1158 <in_checkmate+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>
test   %rax,%rax
setne  %al
test   %ebp,%ebp
sete   %cl
and    %al,%cl
movzbl %cl,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.board_state = type { i32 }
define i32 @in_checkmate(%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 i64 @in_check(%struct.board_state* %14, i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
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_checkmate(%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 i64 @in_check(%struct.board_state* %0, i32 %1)
%10 = icmp ne i64 %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
}