#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_trade(int, int /*<<< orphan*/, int /*<<< orphan*/, int *);
int data_canafford(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ data_getnextwonderstage(int);
int /*<<< orphan*/ data_getwonder(int);
int data_getwonderstages(int);
int *weight_buildwonder(int player, int ret[4]) {
  int trade[3];
  ret[0] = (data_getwonderstages(player) + 2) * 2;
  ret[1] = ret[2] = ret[3] = 0;
  if (data_canafford(player, data_getwonder(player),
                     data_getnextwonderstage(player)) != 1) {
    ai_trade(player, data_getwonder(player), data_getnextwonderstage(player),
             trade);
    if (trade[2])
      ret[0] -= trade[2] / 3;
    else
      ret[0] = 0;
    ret[1] = trade[0];
    ret[2] = trade[1];
    ret[3] = trade[2];
  }
  return ret;
}


x86 assembly (clang, -O0):
<weight_buildwonder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <data_getwonderstages@plt>
mov    %eax,%ecx
add    $0x2,%ecx
shl    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0xc(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <data_getwonder@plt>
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <data_getnextwonderstage@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    %eax,%edx
call   1060 <data_canafford@plt>
cmp    $0x1,%eax
je     123d <weight_buildwonder+0xed>
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <data_getwonder@plt>
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <data_getnextwonderstage@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    %eax,%edx
lea    -0x1c(%rbp),%rcx
call   1070 <ai_trade@plt>
cmpl   $0x0,-0x14(%rbp)
je     1215 <weight_buildwonder+0xc5>
mov    -0x14(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
jmp    121f <weight_buildwonder+0xcf>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<weight_buildwonder>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
call   1030 <data_getwonderstages@plt>
add    %eax,%eax
add    $0x4,%eax
mov    %eax,(%rbx)
movl   $0x0,0xc(%rbx)
movq   $0x0,0x4(%rbx)
mov    %ebp,%edi
call   1040 <data_getwonder@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1050 <data_getnextwonderstage@plt>
mov    %ebp,%edi
mov    %r14d,%esi
mov    %eax,%edx
call   1060 <data_canafford@plt>
cmp    $0x1,%eax
je     11f6 <weight_buildwonder+0xa6>
mov    %ebp,%edi
call   1040 <data_getwonder@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1050 <data_getnextwonderstage@plt>
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    %r14d,%esi
mov    %eax,%edx
call   1070 <ai_trade@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     11e1 <weight_buildwonder+0x91>
movslq %eax,%rcx
imul   $0x55555555,%rcx,%rcx
shr    $0x20,%rcx
sub    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    %ecx
add    %edx,%ecx
add    (%rbx),%ecx
jmp    11e3 <weight_buildwonder+0x93>
xor    %ecx,%ecx
mov    %ecx,(%rbx)
mov    0x4(%rsp),%ecx
mov    %ecx,0x4(%rbx)
mov    0x8(%rsp),%ecx
mov    %ecx,0x8(%rbx)
mov    %eax,0xc(%rbx)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32* @weight_buildwonder(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [3 x i32]
store i32 %0, i32* %3
store i32* %1, i32** %4
%6 = load i32, i32* %3
%7 = call i32 @data_getwonderstages(i32 %6)
%8 = add nsw i32 %7, 2
%9 = mul nsw i32 %8, 2
%10 = load i32*, i32** %4
%11 = getelementptr inbounds i32, i32* %10, i64 0
store i32 %9, i32* %11
%12 = load i32*, i32** %4
%13 = getelementptr inbounds i32, i32* %12, i64 3
store i32 0, i32* %13
%14 = load i32*, i32** %4
%15 = getelementptr inbounds i32, i32* %14, i64 2
store i32 0, i32* %15
%16 = load i32*, i32** %4
%17 = getelementptr inbounds i32, i32* %16, i64 1
store i32 0, i32* %17
%18 = load i32, i32* %3
%19 = load i32, i32* %3
%20 = call i32 @data_getwonder(i32 %19)
%21 = load i32, i32* %3
%22 = call i32 @data_getnextwonderstage(i32 %21)
%23 = call i32 @data_canafford(i32 %18, i32 %20, i32 %22)
%24 = icmp ne i32 %23, 1
br i1 %24, label %25, label %60
25: ; preds = %2
%26 = load i32, i32* %3
%27 = load i32, i32* %3
%28 = call i32 @data_getwonder(i32 %27)
%29 = load i32, i32* %3
%30 = call i32 @data_getnextwonderstage(i32 %29)
%31 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%32 = call i32 @ai_trade(i32 %26, i32 %28, i32 %30, i32* %31)
%33 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 2
%34 = load i32, i32* %33
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %44
36: ; preds = %25
%37 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 2
%38 = load i32, i32* %37
%39 = sdiv i32 %38, 3
%40 = load i32*, i32** %4
%41 = getelementptr inbounds i32, i32* %40, i64 0
%42 = load i32, i32* %41
%43 = sub nsw i32 %42, %39
store i32 %43, i32* %41
br label %47
44: ; preds = %25
%45 = load i32*, i32** %4
%46 = getelementptr inbounds i32, i32* %45, i64 0
store i32 0, i32* %46
br label %47
47: ; preds = %44, %36
%48 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 0
%49 = load i32, i32* %48
%50 = load i32*, i32** %4
%51 = getelementptr inbounds i32, i32* %50, i64 1
store i32 %49, i32* %51
%52 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 1
%53 = load i32, i32* %52
%54 = load i32*, i32** %4
%55 = getelementptr inbounds i32, i32* %54, i64 2
store i32 %53, i32* %55
%56 = getelementptr inbounds [3 x i32], [3 x i32]* %5, i64 0, i64 2
%57 = load i32, i32* %56
%58 = load i32*, i32** %4
%59 = getelementptr inbounds i32, i32* %58, i64 3
store i32 %57, i32* %59
br label %60
60: ; preds = %47, %2
%61 = load i32*, i32** %4
ret i32* %61
}

LLVM IR (-O2):
define i32* @weight_buildwonder(i32 %0, i32* returned %1) {
%3 = alloca [3 x i32]
%4 = bitcast [3 x i32]* %3 to i8*
%5 = tail call i32 @data_getwonderstages(i32 %0)
%6 = shl i32 %5, 1
%7 = add i32 %6, 4
store i32 %7, i32* %1
%8 = getelementptr inbounds i32, i32* %1, i64 3
store i32 0, i32* %8
%9 = getelementptr inbounds i32, i32* %1, i64 2
store i32 0, i32* %9
%10 = getelementptr inbounds i32, i32* %1, i64 1
store i32 0, i32* %10
%11 = tail call i32 @data_getwonder(i32 %0)
%12 = tail call i32 @data_getnextwonderstage(i32 %0)
%13 = tail call i32 @data_canafford(i32 %0, i32 %11, i32 %12)
%14 = icmp eq i32 %13, 1
br i1 %14, label %32, label %15
15: ; preds = %2
%16 = tail call i32 @data_getwonder(i32 %0)
%17 = tail call i32 @data_getnextwonderstage(i32 %0)
%18 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%19 = call i32 @ai_trade(i32 %0, i32 %16, i32 %17, i32* %18)
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 2
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %15
%24 = sdiv i32 %21, -3
%25 = load i32, i32* %1
%26 = add i32 %25, %24
br label %27
27: ; preds = %15, %23
%28 = phi i32 [ %26, %23 ], [ 0, %15 ]
store i32 %28, i32* %1
%29 = load i32, i32* %18
store i32 %29, i32* %10
%30 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 1
%31 = load i32, i32* %30
store i32 %31, i32* %9
store i32 %21, i32* %8
br label %32
32: ; preds = %27, %2
ret i32* %1
}