#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 */
scalar_t__ data_hasbuilt(int, int /*<<< orphan*/, int);
scalar_t__ data_haswonderstage(int, int, int);
int get_trade(int player, int type, int direction) {
  if (type <= 3) {
    if (data_haswonderstage(player, 7, 4))
      return 1;
    if (direction == 0) {
      if (data_hasbuilt(player, 0, 18))
        return 1;
    } else {
      if (data_hasbuilt(player, 0, 19))
        return 1;
    }
  } else {
    if (data_hasbuilt(player, 0, 20))
      return 1;
  }
  return 2;
}


x86 assembly (clang, -O0):
<get_trade>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x3,-0xc(%rbp)
jg     11c6 <get_trade+0xa6>
mov    -0x8(%rbp),%edi
mov    $0x7,%esi
mov    $0x4,%edx
call   1030 <data_haswonderstage@plt>
cmp    $0x0,%rax
je     1163 <get_trade+0x43>
movl   $0x1,-0x4(%rbp)
jmp    11f7 <get_trade+0xd7>
cmpl   $0x0,-0x10(%rbp)
jne    1197 <get_trade+0x77>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
mov    $0x12,%edx
call   1040 <data_hasbuilt@plt>
cmp    $0x0,%rax
je     1192 <get_trade+0x72>
movl   $0x1,-0x4(%rbp)
jmp    11f7 <get_trade+0xd7>
jmp    11c1 <get_trade+0xa1>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
mov    $0x13,%edx
call   1040 <data_hasbuilt@plt>
cmp    $0x0,%rax
je     11bc <get_trade+0x9c>
movl   $0x1,-0x4(%rbp)
jmp    11f7 <get_trade+0xd7>
jmp    11c1 <get_trade+0xa1>
jmp    11f0 <get_trade+0xd0>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <data_hasbuilt@plt>
cmp    $0x0,%rax
je     11eb <get_trade+0xcb>
movl   $0x1,-0x4(%rbp)
jmp    11f7 <get_trade+0xd7>
jmp    11f0 <get_trade+0xd0>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_trade>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
cmp    $0x3,%esi
jg     1159 <get_trade+0x39>
mov    %edx,%r14d
mov    %ebp,%edi
mov    $0x7,%esi
mov    $0x4,%edx
call   1030 <data_haswonderstage@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    1176 <get_trade+0x56>
mov    %ebp,%edi
xor    %esi,%esi
test   %r14d,%r14d
je     117d <get_trade+0x5d>
mov    $0x13,%edx
jmp    1182 <get_trade+0x62>
mov    %ebp,%edi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <data_hasbuilt@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    1176 <get_trade+0x56>
mov    $0x2,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x12,%edx
call   1040 <data_hasbuilt@plt>
test   %rax,%rax
jne    1176 <get_trade+0x56>
jmp    1171 <get_trade+0x51>

LLVM IR (-O0):
define i32 @get_trade(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %6
%9 = icmp sle i32 %8, 3
br i1 %9, label %10, label %31
10: ; preds = %3
%11 = load i32, i32* %5
%12 = call i64 @data_haswonderstage(i32 %11, i32 7, i32 4)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 1, i32* %4
br label %38
15: ; preds = %10
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i32, i32* %5
%20 = call i64 @data_hasbuilt(i32 %19, i32 0, i32 18)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 1, i32* %4
br label %38
23: ; preds = %18
br label %30
24: ; preds = %15
%25 = load i32, i32* %5
%26 = call i64 @data_hasbuilt(i32 %25, i32 0, i32 19)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 1, i32* %4
br label %38
29: ; preds = %24
br label %30
30: ; preds = %29, %23
br label %37
31: ; preds = %3
%32 = load i32, i32* %5
%33 = call i64 @data_hasbuilt(i32 %32, i32 0, i32 20)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 1, i32* %4
br label %38
36: ; preds = %31
br label %37
37: ; preds = %36, %30
store i32 2, i32* %4
br label %38
38: ; preds = %37, %35, %28, %22, %14
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
define i32 @get_trade(i32 %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, 4
br i1 %4, label %5, label %16
5: ; preds = %3
%6 = tail call i64 @data_haswonderstage(i32 %0, i32 7, i32 4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = icmp eq i32 %2, 0
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = tail call i64 @data_hasbuilt(i32 %0, i32 0, i32 18)
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %20
13: ; preds = %8
%14 = tail call i64 @data_hasbuilt(i32 %0, i32 0, i32 19)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %20
16: ; preds = %3
%17 = tail call i64 @data_hasbuilt(i32 %0, i32 0, i32 20)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16, %10, %13
br label %20
20: ; preds = %16, %13, %10, %5, %19
%21 = phi i32 [ 2, %19 ], [ 1, %5 ], [ 1, %10 ], [ 1, %13 ], [ 1, %16 ]
ret i32 %21
}