#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*/ accepttrade(int *, int, int, int *);
int /*<<< orphan*/ doTrade(int *, int, int);
int /*<<< orphan*/ map_setmessage(char *);
int selectTrade(int **, int);
int player_trade(int player, int *tr) {
  int accepted[4][6], i, j;
  accepted[player][5] = 3;
  for (i = 1; i < 4; i++) {
    int pointer[6];
    accepttrade(tr, (player + i) % 4, player, pointer);
    for (j = 0; j < 6; j++)
      accepted[(player + i) % 4][j] = pointer[j];
  }
  int selected = selectTrade(accepted, player);
  if (selected > -1 && accepted[selected][5] > 0)
    doTrade(accepted[selected], selected, player);
  else
    map_setmessage("Trade cancelled");
  return 1;
}


x86 assembly (clang, -O0):
<player_trade>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movslq -0x4(%rbp),%rcx
lea    -0x70(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movl   $0x3,0x14(%rax)
movl   $0x1,-0x74(%rbp)
cmpl   $0x4,-0x74(%rbp)
jge    120a <player_trade+0xca>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%eax
add    -0x74(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
mov    -0x4(%rbp),%edx
lea    -0x90(%rbp),%rcx
call   1040 <accepttrade@plt>
movl   $0x0,-0x78(%rbp)
cmpl   $0x6,-0x78(%rbp)
jge    11f7 <player_trade+0xb7>
movslq -0x78(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%eax
mov    %eax,-0x98(%rbp)
mov    -0x4(%rbp),%eax
add    -0x74(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    -0x98(%rbp),%edx
movslq %eax,%rcx
lea    -0x70(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x78(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    11a3 <player_trade+0x63>
jmp    11fc <player_trade+0xbc>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    116f <player_trade+0x2f>
lea    -0x70(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1060 <selectTrade@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0xffffffff,-0x94(%rbp)
jle    126a <player_trade+0x12a>
movslq -0x94(%rbp),%rcx
lea    -0x70(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
cmpl   $0x0,0x14(%rax)
jle    126a <player_trade+0x12a>
movslq -0x94(%rbp),%rax
lea    -0x70(%rbp),%rdi
imul   $0x18,%rax,%rax
add    %rax,%rdi
mov    -0x94(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1050 <doTrade@plt>
jmp    1276 <player_trade+0x136>
lea    0xd8f(%rip),%rdi
call   1030 <map_setmessage@plt>
mov    $0x1,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<player_trade>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%r12
mov    %edi,%r14d
movslq %edi,%rbx
lea    0x1(%rbx),%eax
lea    0x4(%rbx),%ecx
test   %eax,%eax
cmovns %eax,%ecx
lea    (%rbx,%rbx,2),%rax
movl   $0x3,0x34(%rsp,%rax,8)
and    $0xfffffffc,%ecx
neg    %ecx
lea    (%rbx,%rcx,1),%ebp
add    $0x1,%ebp
mov    %rsp,%r15
mov    %rsi,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15,%rcx
call   1040 <accepttrade@plt>
movslq %ebp,%rax
lea    (%rax,%rax,2),%rax
mov    0x10(%rsp),%rcx
mov    %rcx,0x30(%rsp,%rax,8)
lea    0x2(%rbx),%ecx
lea    0x5(%rbx),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
movaps (%rsp),%xmm0
movups %xmm0,0x20(%rsp,%rax,8)
and    $0xfffffffc,%edx
neg    %edx
lea    (%rbx,%rdx,1),%ebp
add    $0x2,%ebp
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15,%rcx
call   1040 <accepttrade@plt>
movslq %ebp,%rax
lea    (%rax,%rax,2),%rax
mov    0x10(%rsp),%rcx
mov    %rcx,0x30(%rsp,%rax,8)
lea    0x3(%rbx),%ecx
lea    0x6(%rbx),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
movaps (%rsp),%xmm0
movups %xmm0,0x20(%rsp,%rax,8)
and    $0xfffffffc,%edx
neg    %edx
lea    (%rbx,%rdx,1),%ebp
add    $0x3,%ebp
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15,%rcx
call   1040 <accepttrade@plt>
movslq %ebp,%rax
lea    (%rax,%rax,2),%rax
movaps (%rsp),%xmm0
movups %xmm0,0x20(%rsp,%rax,8)
mov    0x10(%rsp),%rcx
mov    %rcx,0x30(%rsp,%rax,8)
lea    0x20(%rsp),%rdi
mov    %ebx,%esi
call   1060 <selectTrade@plt>
test   %eax,%eax
js     1255 <player_trade+0x115>
mov    %eax,%ecx
lea    (%rcx,%rcx,2),%rcx
cmpl   $0x0,0x34(%rsp,%rcx,8)
jle    1255 <player_trade+0x115>
lea    (%rsp,%rcx,8),%rdi
add    $0x20,%rdi
mov    %eax,%esi
mov    %r14d,%edx
call   1050 <doTrade@plt>
jmp    1261 <player_trade+0x121>
lea    0xda4(%rip),%rdi
call   1030 <map_setmessage@plt>
mov    $0x1,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Trade cancelled\00"
define i32 @player_trade(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [4 x [6 x i32]]
%6 = alloca i32
%7 = alloca i32
%8 = alloca [6 x i32]
%9 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [4 x [6 x i32]], [4 x [6 x i32]]* %5, i64 0, i64 %11
%13 = getelementptr inbounds [6 x i32], [6 x i32]* %12, i64 0, i64 5
store i32 3, i32* %13
store i32 1, i32* %6
br label %14
14: ; preds = %47, %2
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 4
br i1 %16, label %17, label %50
17: ; preds = %14
%18 = load i32*, i32** %4
%19 = load i32, i32* %3
%20 = load i32, i32* %6
%21 = add nsw i32 %19, %20
%22 = srem i32 %21, 4
%23 = load i32, i32* %3
%24 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 0
%25 = call i32 @accepttrade(i32* %18, i32 %22, i32 %23, i32* %24)
store i32 0, i32* %7
br label %26
26: ; preds = %43, %17
%27 = load i32, i32* %7
%28 = icmp slt i32 %27, 6
br i1 %28, label %29, label %46
29: ; preds = %26
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = load i32, i32* %3
%35 = load i32, i32* %6
%36 = add nsw i32 %34, %35
%37 = srem i32 %36, 4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [4 x [6 x i32]], [4 x [6 x i32]]* %5, i64 0, i64 %38
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [6 x i32], [6 x i32]* %39, i64 0, i64 %41
store i32 %33, i32* %42
br label %43
43: ; preds = %29
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %26
46: ; preds = %26
br label %47
47: ; preds = %46
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %6
br label %14
50: ; preds = %14
%51 = getelementptr inbounds [4 x [6 x i32]], [4 x [6 x i32]]* %5, i64 0, i64 0
%52 = bitcast [6 x i32]* %51 to i32**
%53 = load i32, i32* %3
%54 = call i32 @selectTrade(i32** %52, i32 %53)
store i32 %54, i32* %9
%55 = load i32, i32* %9
%56 = icmp sgt i32 %55, -1
br i1 %56, label %57, label %72
57: ; preds = %50
%58 = load i32, i32* %9
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [4 x [6 x i32]], [4 x [6 x i32]]* %5, i64 0, i64 %59
%61 = getelementptr inbounds [6 x i32], [6 x i32]* %60, i64 0, i64 5
%62 = load i32, i32* %61
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %72
64: ; preds = %57
%65 = load i32, i32* %9
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [4 x [6 x i32]], [4 x [6 x i32]]* %5, i64 0, i64 %66
%68 = getelementptr inbounds [6 x i32], [6 x i32]* %67, i64 0, i64 0
%69 = load i32, i32* %9
%70 = load i32, i32* %3
%71 = call i32 @doTrade(i32* %68, i32 %69, i32 %70)
br label %74
72: ; preds = %57, %50
%73 = call i32 @map_setmessage(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %74
74: ; preds = %72, %64
ret i32 1
}

LLVM IR (-O2):
@.str = [16 x i8] c"Trade cancelled\00"
define i32 @player_trade(i32 %0, i32* %1) {
%3 = alloca [4 x [6 x i32]]
%4 = alloca [6 x i32]
%5 = bitcast [6 x i32]* %4 to i8*
%6 = bitcast [4 x [6 x i32]]* %3 to i8*
%7 = sext i32 %0 to i64
%8 = getelementptr inbounds [4 x [6 x i32]], [4 x [6 x i32]]* %3, i64 0, i64 %7, i64 5
store i32 3, i32* %8
%9 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 0
%10 = add nsw i32 %0, 1
%11 = srem i32 %10, 4
%12 = call i32 @accepttrade(i32* %1, i32 %11, i32 %0, i32* %9)
%13 = sext i32 %11 to i64
%14 = getelementptr [4 x [6 x i32]], [4 x [6 x i32]]* %3, i64 0, i64 %13, i64 0
%15 = bitcast i32* %14 to i8*
%16 = add nsw i32 %0, 2
%17 = srem i32 %16, 4
%18 = call i32 @accepttrade(i32* %1, i32 %17, i32 %0, i32* %9)
%19 = sext i32 %17 to i64
%20 = getelementptr [4 x [6 x i32]], [4 x [6 x i32]]* %3, i64 0, i64 %19, i64 0
%21 = bitcast i32* %20 to i8*
%22 = add nsw i32 %0, 3
%23 = srem i32 %22, 4
%24 = call i32 @accepttrade(i32* %1, i32 %23, i32 %0, i32* %9)
%25 = sext i32 %23 to i64
%26 = getelementptr [4 x [6 x i32]], [4 x [6 x i32]]* %3, i64 0, i64 %25, i64 0
%27 = bitcast i32* %26 to i8*
%28 = bitcast [4 x [6 x i32]]* %3 to i32**
%29 = call i32 @selectTrade(i32** %28, i32 %0)
%30 = icmp sgt i32 %29, -1
br i1 %30, label %31, label %39
31: ; preds = %2
%32 = zext i32 %29 to i64
%33 = getelementptr inbounds [4 x [6 x i32]], [4 x [6 x i32]]* %3, i64 0, i64 %32, i64 5
%34 = load i32, i32* %33
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = getelementptr inbounds [4 x [6 x i32]], [4 x [6 x i32]]* %3, i64 0, i64 %32, i64 0
%38 = call i32 @doTrade(i32* %37, i32 %29, i32 %0)
br label %41
39: ; preds = %31, %2
%40 = call i32 @map_setmessage(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %41
41: ; preds = %39, %36
ret i32 1
}