#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 no_legal_moves(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 move_count == 0;
}


x86 assembly (clang, -O0):
<no_legal_moves>:
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     1153 <no_legal_moves+0x33>
jmp    1142 <no_legal_moves+0x22>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     1168 <no_legal_moves+0x48>
jmp    1178 <no_legal_moves+0x58>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <generate_moves_white@plt>
mov    %eax,-0x10(%rbp)
jmp    1178 <no_legal_moves+0x58>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <generate_moves_black@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<no_legal_moves>:
push   %rax
cmp    $0x1,%esi
je     1133 <no_legal_moves+0x13>
test   %esi,%esi
jne    113a <no_legal_moves+0x1a>
xor    %esi,%esi
call   1030 <generate_moves_white@plt>
jmp    113a <no_legal_moves+0x1a>
xor    %esi,%esi
call   1040 <generate_moves_black@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.board_state = type { i32 }
define i32 @no_legal_moves(%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 i32, i32* %5
%15 = icmp eq i32 %14, 0
%16 = zext i1 %15 to i32
ret i32 %16
}

LLVM IR (-O2):
%struct.board_state = type { i32 }
define i32 @no_legal_moves(%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 = icmp eq i32 %8, 0
%10 = zext i1 %9 to i32
ret i32 %10
}