#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*/ data_getdir(int, int);
scalar_t__ data_gettotvps(int /*<<< orphan*/);
scalar_t__ get_trade(int, int, int);
int bestNeighbor(int player, int res) {
  int best = 0;
  if (get_trade(player, res, 0) != get_trade(player, res, 1)) {
    best = (get_trade(player, res, 0) < get_trade(player, res, 1)) ? 0 : 1;
  } else if (data_gettotvps(data_getdir(0, player)) >
             data_gettotvps(data_getdir(1, player)))
    best = 0;
  else
    best = 1;
  return best;
}


x86 assembly (clang, -O0):
<bestNeighbor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
xor    %edx,%edx
call   1050 <get_trade@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0x1,%edx
call   1050 <get_trade@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
cmp    %rcx,%rax
je     11b3 <bestNeighbor+0x83>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
xor    %edx,%edx
call   1050 <get_trade@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0x1,%edx
call   1050 <get_trade@plt>
mov    -0x20(%rbp),%rdx
mov    %rax,%rsi
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    %rsi,%rdx
cmovl  %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    1204 <bestNeighbor+0xd4>
mov    -0x4(%rbp),%esi
xor    %edi,%edi
call   1030 <data_getdir@plt>
mov    %eax,%edi
call   1040 <data_gettotvps@plt>
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%esi
mov    $0x1,%edi
call   1030 <data_getdir@plt>
mov    %eax,%edi
call   1040 <data_gettotvps@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jle    11f8 <bestNeighbor+0xc8>
movl   $0x0,-0xc(%rbp)
jmp    11ff <bestNeighbor+0xcf>
movl   $0x1,-0xc(%rbp)
jmp    1204 <bestNeighbor+0xd4>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bestNeighbor>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %edi,%ebx
xor    %edx,%edx
call   1050 <get_trade@plt>
mov    %rax,%r14
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x1,%edx
call   1050 <get_trade@plt>
cmp    %rax,%r14
jne    1183 <bestNeighbor+0x53>
xor    %edi,%edi
mov    %ebx,%esi
call   1030 <data_getdir@plt>
mov    %eax,%edi
call   1040 <data_gettotvps@plt>
mov    %rax,%rbp
mov    $0x1,%edi
mov    %ebx,%esi
call   1030 <data_getdir@plt>
mov    %eax,%edi
call   1040 <data_gettotvps@plt>
cmp    %rax,%rbp
setle  %al
jmp    11a5 <bestNeighbor+0x75>
mov    %ebx,%edi
mov    %ebp,%esi
xor    %edx,%edx
call   1050 <get_trade@plt>
mov    %rax,%r14
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x1,%edx
call   1050 <get_trade@plt>
cmp    %rax,%r14
setge  %al
movzbl %al,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bestNeighbor(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 0, i32* %5
%6 = load i32, i32* %3
%7 = load i32, i32* %4
%8 = call i64 @get_trade(i32 %6, i32 %7, i32 0)
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = call i64 @get_trade(i32 %9, i32 %10, i32 1)
%12 = icmp ne i64 %8, %11
br i1 %12, label %13, label %23
13: ; preds = %2
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = call i64 @get_trade(i32 %14, i32 %15, i32 0)
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = call i64 @get_trade(i32 %17, i32 %18, i32 1)
%20 = icmp slt i64 %16, %19
%21 = zext i1 %20 to i64
%22 = select i1 %20, i32 0, i32 1
store i32 %22, i32* %5
br label %34
23: ; preds = %2
%24 = load i32, i32* %3
%25 = call i32 @data_getdir(i32 0, i32 %24)
%26 = call i64 @data_gettotvps(i32 %25)
%27 = load i32, i32* %3
%28 = call i32 @data_getdir(i32 1, i32 %27)
%29 = call i64 @data_gettotvps(i32 %28)
%30 = icmp sgt i64 %26, %29
br i1 %30, label %31, label %32
31: ; preds = %23
store i32 0, i32* %5
br label %33
32: ; preds = %23
store i32 1, i32* %5
br label %33
33: ; preds = %32, %31
br label %34
34: ; preds = %33, %13
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
define i32 @bestNeighbor(i32 %0, i32 %1) {
%3 = tail call i64 @get_trade(i32 %0, i32 %1, i32 0)
%4 = tail call i64 @get_trade(i32 %0, i32 %1, i32 1)
%5 = icmp eq i64 %3, %4
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i64 @get_trade(i32 %0, i32 %1, i32 0)
%8 = tail call i64 @get_trade(i32 %0, i32 %1, i32 1)
%9 = icmp sge i64 %7, %8
br label %16
10: ; preds = %2
%11 = tail call i32 @data_getdir(i32 0, i32 %0)
%12 = tail call i64 @data_gettotvps(i32 %11)
%13 = tail call i32 @data_getdir(i32 1, i32 %0)
%14 = tail call i64 @data_gettotvps(i32 %13)
%15 = icmp sle i64 %12, %14
br label %16
16: ; preds = %10, %6
%17 = phi i1 [ %9, %6 ], [ %15, %10 ]
%18 = zext i1 %17 to i32
ret i32 %18
}