#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 ai_playknight(int);
scalar_t__ data_getcards(int, int /*<<< orphan*/);
scalar_t__ data_isai(int);
int /*<<< orphan*/ devcards_knight(int);
int io_getkey();
int /*<<< orphan*/ io_printgeneric(char *);
int devcards_knightoption(int player) {
  if (data_getcards(player, 0) == 0)
    return 0;
  if (data_isai(player)) {
    return ai_playknight(player);
  }
  io_printgeneric("Play knight card?\n      (y/n)");
  while (1) {
    switch (io_getkey()) {
    case 'y':
      devcards_knight(player);
      return 1;
    case 'n':
      return 0;
    default:
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<devcards_knightoption>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1040 <data_getcards@plt>
cmp    $0x0,%rax
jne    118b <devcards_knightoption+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    120e <devcards_knightoption+0xae>
mov    -0x8(%rbp),%edi
call   1030 <data_isai@plt>
cmp    $0x0,%rax
je     11ad <devcards_knightoption+0x4d>
mov    -0x8(%rbp),%edi
call   1050 <ai_playknight@plt>
mov    %eax,-0x4(%rbp)
jmp    120e <devcards_knightoption+0xae>
lea    0xe4c(%rip),%rdi
call   1070 <io_printgeneric@plt>
xor    %eax,%eax
call   1060 <io_getkey@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
sub    $0x6e,%eax
je     11f8 <devcards_knightoption+0x98>
jmp    11d3 <devcards_knightoption+0x73>
mov    -0xc(%rbp),%eax
sub    $0x79,%eax
jne    1204 <devcards_knightoption+0xa4>
jmp    11e4 <devcards_knightoption+0x84>
mov    -0x8(%rbp),%edi
call   1080 <devcards_knight@plt>
movl   $0x1,-0x4(%rbp)
jmp    120e <devcards_knightoption+0xae>
movl   $0x0,-0x4(%rbp)
jmp    120e <devcards_knightoption+0xae>
jmp    1209 <devcards_knightoption+0xa9>
jmp    11b9 <devcards_knightoption+0x59>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<devcards_knightoption>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %ebp,%ebp
xor    %esi,%esi
call   1040 <data_getcards@plt>
test   %rax,%rax
je     11c1 <devcards_knightoption+0x61>
mov    %ebx,%edi
call   1030 <data_isai@plt>
test   %rax,%rax
je     118c <devcards_knightoption+0x2c>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <ai_playknight@plt>
lea    0xe6d(%rip),%rdi
call   1070 <io_printgeneric@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <io_getkey@plt>
cmp    $0x6e,%eax
je     11bf <devcards_knightoption+0x5f>
cmp    $0x79,%eax
jne    11a0 <devcards_knightoption+0x40>
mov    %ebx,%edi
call   1080 <devcards_knight@plt>
mov    $0x1,%ebp
jmp    11c1 <devcards_knightoption+0x61>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Play knight card?\0A (y/n)\00"
define i32 @devcards_knightoption(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = call i64 @data_getcards(i32 %4, i32 0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 0, i32* %2
br label %25
8: ; preds = %1
%9 = load i32, i32* %3
%10 = call i64 @data_isai(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %3
%14 = call i32 @ai_playknight(i32 %13)
store i32 %14, i32* %2
br label %25
15: ; preds = %8
%16 = call i32 @io_printgeneric(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %24
%18 = call i32 (...) @io_getkey()
switch i32 %18, label %23 [
i32 121, label %19
i32 110, label %22
]
19: ; preds = %17
%20 = load i32, i32* %3
%21 = call i32 @devcards_knight(i32 %20)
store i32 1, i32* %2
br label %25
22: ; preds = %17
store i32 0, i32* %2
br label %25
23: ; preds = %17
br label %24
24: ; preds = %23
br label %17
25: ; preds = %22, %19, %12, %7
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [30 x i8] c"Play knight card?\0A (y/n)\00"
define i32 @devcards_knightoption(i32 %0) {
%2 = tail call i64 @data_getcards(i32 %0, i32 0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = tail call i64 @data_isai(i32 %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @ai_playknight(i32 %0)
br label %15
9: ; preds = %4
%10 = tail call i32 @io_printgeneric(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %11, %9
%12 = tail call i32 (...) @io_getkey()
switch i32 %12, label %11 [
i32 121, label %13
i32 110, label %15
]
13: ; preds = %11
%14 = tail call i32 @devcards_knight(i32 %0)
br label %15
15: ; preds = %11, %1, %13, %7
%16 = phi i32 [ %8, %7 ], [ 1, %13 ], [ 0, %1 ], [ 0, %11 ]
ret i32 %16
}