#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 */
char *cat(char *, char *);
int /*<<< orphan*/ data_addcards(int, int /*<<< orphan*/, int);
int data_getcards(int, int /*<<< orphan*/);
int /*<<< orphan*/ data_playknight(int);
char *itoa(int);
int /*<<< orphan*/ map_setmessage(char *);
int /*<<< orphan*/ robber_routine(int);
int devcards_knight(int player) {
  if (data_getcards(player, 0) >= 1) {
    map_setmessage(cat(cat("Player ", itoa(player + 1)), " played a knight"));
    data_addcards(player, 0, -1);
    data_playknight(player);
    robber_routine(player);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<devcards_knight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1050 <data_getcards@plt>
cmp    $0x1,%eax
jl     11ea <devcards_knight+0x7a>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
call   1080 <itoa@plt>
mov    %rax,%rsi
lea    0xe5d(%rip),%rdi
call   1090 <cat@plt>
mov    %rax,%rdi
lea    0xe56(%rip),%rsi
call   1090 <cat@plt>
mov    %rax,%rdi
call   1070 <map_setmessage@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
mov    $0xffffffff,%edx
call   1060 <data_addcards@plt>
mov    -0x8(%rbp),%edi
call   1030 <data_playknight@plt>
mov    -0x8(%rbp),%edi
call   1040 <robber_routine@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f1 <devcards_knight+0x81>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<devcards_knight>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %ebp,%ebp
xor    %esi,%esi
call   1050 <data_getcards@plt>
test   %eax,%eax
jle    11d1 <devcards_knight+0x61>
lea    0x1(%rbx),%edi
call   1080 <itoa@plt>
lea    0xe6f(%rip),%rdi
mov    %rax,%rsi
call   1090 <cat@plt>
lea    0xe68(%rip),%rsi
mov    %rax,%rdi
call   1090 <cat@plt>
mov    %rax,%rdi
call   1070 <map_setmessage@plt>
mov    %ebx,%edi
xor    %esi,%esi
mov    $0xffffffff,%edx
call   1060 <data_addcards@plt>
mov    %ebx,%edi
call   1030 <data_playknight@plt>
mov    %ebx,%edi
call   1040 <robber_routine@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"Player \00"
@.str.1 = [17 x i8] c" played a knight\00"
define i32 @devcards_knight(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = call i32 @data_getcards(i32 %4, i32 0)
%6 = icmp sge i32 %5, 1
br i1 %6, label %7, label %20
7: ; preds = %1
%8 = load i32, i32* %3
%9 = add nsw i32 %8, 1
%10 = call i8* @itoa(i32 %9)
%11 = call i8* @cat(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = call i8* @cat(i8* %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @map_setmessage(i8* %12)
%14 = load i32, i32* %3
%15 = call i32 @data_addcards(i32 %14, i32 0, i32 -1)
%16 = load i32, i32* %3
%17 = call i32 @data_playknight(i32 %16)
%18 = load i32, i32* %3
%19 = call i32 @robber_routine(i32 %18)
store i32 1, i32* %2
br label %21
20: ; preds = %1
store i32 0, i32* %2
br label %21
21: ; preds = %20, %7
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [8 x i8] c"Player \00"
@.str.1 = [17 x i8] c" played a knight\00"
define i32 @devcards_knight(i32 %0) {
%2 = tail call i32 @data_getcards(i32 %0, i32 0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %13
4: ; preds = %1
%5 = add nsw i32 %0, 1
%6 = tail call i8* @itoa(i32 %5)
%7 = tail call i8* @cat(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i8* @cat(i8* %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @map_setmessage(i8* %8)
%10 = tail call i32 @data_addcards(i32 %0, i32 0, i32 -1)
%11 = tail call i32 @data_playknight(i32 %0)
%12 = tail call i32 @robber_routine(i32 %0)
br label %13
13: ; preds = %1, %4
%14 = phi i32 [ 1, %4 ], [ 0, %1 ]
ret i32 %14
}