#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 */
int /*<<< orphan*/ encontrar_jugada_posible(char *, char, int *, int *,
                                            int /*<<< orphan*/);
scalar_t__ jugador_en_jaque(char *, char);
int es_mate(char *ptablero) {
  int a1 = 0, a2 = 0;
  if (jugador_en_jaque(ptablero, 'B')) {
    if (!encontrar_jugada_posible(ptablero, 'B', &a1, &a2, 0))
      return 2;
  }
  if (jugador_en_jaque(ptablero, 'N')) {
    if (!encontrar_jugada_posible(ptablero, 'N', &a1, &a2, 0))
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<es_mate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x42,%esi
call   1040 <jugador_en_jaque@plt>
cmp    $0x0,%rax
je     1185 <es_mate+0x65>
mov    -0x10(%rbp),%rdi
mov    $0x42,%esi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
xor    %r8d,%r8d
call   1030 <encontrar_jugada_posible@plt>
cmp    $0x0,%eax
jne    1180 <es_mate+0x60>
movl   $0x2,-0x4(%rbp)
jmp    11d7 <es_mate+0xb7>
jmp    1185 <es_mate+0x65>
mov    -0x10(%rbp),%rdi
mov    $0x4e,%esi
call   1040 <jugador_en_jaque@plt>
cmp    $0x0,%rax
je     11d0 <es_mate+0xb0>
mov    -0x10(%rbp),%rdi
mov    $0x4e,%esi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
xor    %r8d,%r8d
call   1030 <encontrar_jugada_posible@plt>
cmp    $0x0,%eax
jne    11cb <es_mate+0xab>
movl   $0x1,-0x4(%rbp)
jmp    11d7 <es_mate+0xb7>
jmp    11d0 <es_mate+0xb0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<es_mate>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    $0x42,%esi
call   1040 <jugador_en_jaque@plt>
test   %rax,%rax
je     1165 <es_mate+0x45>
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x42,%esi
xor    %r8d,%r8d
call   1030 <encontrar_jugada_posible@plt>
test   %eax,%eax
je     1199 <es_mate+0x79>
mov    %rbx,%rdi
mov    $0x4e,%esi
call   1040 <jugador_en_jaque@plt>
test   %rax,%rax
je     1195 <es_mate+0x75>
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x4e,%esi
xor    %r8d,%r8d
call   1030 <encontrar_jugada_posible@plt>
test   %eax,%eax
je     11a0 <es_mate+0x80>
xor    %eax,%eax
jmp    11a5 <es_mate+0x85>
mov    $0x2,%eax
jmp    11a5 <es_mate+0x85>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @es_mate(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = load i8*, i8** %3
%7 = call i64 @jugador_en_jaque(i8* %6, i8 signext 66)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @encontrar_jugada_posible(i8* %10, i8 signext 66, i32* %4, i32* %5, i32 0)
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %9
store i32 2, i32* %2
br label %26
14: ; preds = %9
br label %15
15: ; preds = %14, %1
%16 = load i8*, i8** %3
%17 = call i64 @jugador_en_jaque(i8* %16, i8 signext 78)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = call i32 @encontrar_jugada_posible(i8* %20, i8 signext 78, i32* %4, i32* %5, i32 0)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %19
store i32 1, i32* %2
br label %26
24: ; preds = %19
br label %25
25: ; preds = %24, %15
store i32 0, i32* %2
br label %26
26: ; preds = %25, %23, %13
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
define i32 @es_mate(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = tail call i64 @jugador_en_jaque(i8* %0, i8 signext 66)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = call i32 @encontrar_jugada_posible(i8* %0, i8 signext 66, i32* %2, i32* %3, i32 0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %8, %1
%12 = call i64 @jugador_en_jaque(i8* %0, i8 signext 78)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = call i32 @encontrar_jugada_posible(i8* %0, i8 signext 78, i32* %2, i32* %3, i32 0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %14, %11
br label %18
18: ; preds = %14, %8, %17
%19 = phi i32 [ 0, %17 ], [ 2, %8 ], [ 1, %14 ]
ret i32 %19
}