#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*/ ai_card(int);
scalar_t__ ai_city(int);
int ai_playcard(int);
scalar_t__ ai_road(int, int /*<<< orphan*/);
scalar_t__ ai_settle(int);
int /*<<< orphan*/ ai_trade(int);
int /*<<< orphan*/ data_sleep();
int /*<<< orphan*/ io_printmap(int /*<<< orphan*/);
void ai_routine(int player, int hascarded) {
  int didsomething = 1;
  if (!hascarded)
    hascarded = ai_playcard(player);
  while (didsomething) {
    io_printmap(0);
    data_sleep();
    if (ai_settle(player) || ai_city(player) || ai_road(player, 0))
      didsomething = 1;
    else if (!ai_card(player) && !ai_trade(player))
      didsomething = 0;
  }
}


x86 assembly (clang, -O0):
<ai_routine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11aa <ai_routine+0x2a>
mov    -0x4(%rbp),%edi
call   1060 <ai_playcard@plt>
mov    %eax,-0x8(%rbp)
jmp    11af <ai_routine+0x2f>
cmpl   $0x0,-0xc(%rbp)
je     123e <ai_routine+0xbe>
xor    %edi,%edi
call   1090 <io_printmap@plt>
mov    $0x0,%al
call   1070 <data_sleep@plt>
mov    -0x4(%rbp),%edi
call   1030 <ai_settle@plt>
cmp    $0x0,%rax
jne    11ff <ai_routine+0x7f>
mov    -0x4(%rbp),%edi
call   1040 <ai_city@plt>
cmp    $0x0,%rax
jne    11ff <ai_routine+0x7f>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1080 <ai_road@plt>
cmp    $0x0,%rax
je     120b <ai_routine+0x8b>
movl   $0x1,-0xc(%rbp)
jmp    1239 <ai_routine+0xb9>
mov    -0x4(%rbp),%edi
call   1050 <ai_card@plt>
cmp    $0x0,%eax
jne    1234 <ai_routine+0xb4>
mov    -0x4(%rbp),%edi
call   10a0 <ai_trade@plt>
cmp    $0x0,%eax
jne    1234 <ai_routine+0xb4>
movl   $0x0,-0xc(%rbp)
jmp    1239 <ai_routine+0xb9>
jmp    11af <ai_routine+0x2f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ai_routine>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
test   %esi,%esi
jne    11a4 <ai_routine+0x24>
mov    %ebx,%edi
call   1060 <ai_playcard@plt>
jmp    11a4 <ai_routine+0x24>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %ebp,%ebp
je     11f9 <ai_routine+0x79>
xor    %edi,%edi
call   1090 <io_printmap@plt>
xor    %eax,%eax
call   1070 <data_sleep@plt>
mov    %ebx,%edi
call   1030 <ai_settle@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    11a0 <ai_routine+0x20>
mov    %ebx,%edi
call   1040 <ai_city@plt>
test   %rax,%rax
jne    11a0 <ai_routine+0x20>
mov    %ebx,%edi
xor    %esi,%esi
call   1080 <ai_road@plt>
test   %rax,%rax
jne    11a0 <ai_routine+0x20>
mov    %ebx,%edi
call   1050 <ai_card@plt>
test   %eax,%eax
jne    11a0 <ai_routine+0x20>
mov    %ebx,%edi
call   10a0 <ai_trade@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
jmp    11a0 <ai_routine+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @ai_routine(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 1, i32* %5
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* %3
%10 = call i32 @ai_playcard(i32 %9)
store i32 %10, i32* %4
br label %11
11: ; preds = %8, %2
br label %12
12: ; preds = %40, %11
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %41
15: ; preds = %12
%16 = call i32 @io_printmap(i32 0)
%17 = call i32 (...) @data_sleep()
%18 = load i32, i32* %3
%19 = call i64 @ai_settle(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %15
%22 = load i32, i32* %3
%23 = call i64 @ai_city(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i32, i32* %3
%27 = call i64 @ai_road(i32 %26, i32 0)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25, %21, %15
store i32 1, i32* %5
br label %40
30: ; preds = %25
%31 = load i32, i32* %3
%32 = call i32 @ai_card(i32 %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %30
%35 = load i32, i32* %3
%36 = call i32 @ai_trade(i32 %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %34
store i32 0, i32* %5
br label %39
39: ; preds = %38, %34, %30
br label %40
40: ; preds = %39, %29
br label %12
41: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @ai_routine(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @ai_playcard(i32 %0)
br label %6
6: ; preds = %4, %2
br label %7
7: ; preds = %6, %25
%8 = tail call i32 @io_printmap(i32 0)
%9 = tail call i32 (...) @data_sleep()
%10 = tail call i64 @ai_settle(i32 %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %7
%13 = tail call i64 @ai_city(i32 %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = tail call i64 @ai_road(i32 %0, i32 0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = tail call i32 @ai_card(i32 %0)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = tail call i32 @ai_trade(i32 %0)
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i32
br label %25
25: ; preds = %21, %7, %12, %15, %18
%26 = phi i32 [ 1, %18 ], [ 1, %15 ], [ 1, %12 ], [ 1, %7 ], [ %24, %21 ]
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %7
28: ; preds = %25
ret void
}