#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 data_getdir(int, int);
int /*<<< orphan*/ data_gettradables(int, int *);
int weight_tradingpost(int dir, int player) {
  int weight = 0;
  int trade[7 + 1];
  data_gettradables(data_getdir(dir, player), trade);
  int prod[7 + 1];
  data_gettradables(player, prod);
  int i;
  for (i = 0; i < 4; i++) {
    if (trade[i] && !prod[i])
      weight++;
  }
  return weight;
}


x86 assembly (clang, -O0):
<weight_tradingpost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <data_getdir@plt>
mov    %eax,%edi
lea    -0x30(%rbp),%rsi
call   1030 <data_gettradables@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1030 <data_gettradables@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0x4,-0x54(%rbp)
jge    11a2 <weight_tradingpost+0x82>
movslq -0x54(%rbp),%rax
cmpl   $0x0,-0x30(%rbp,%rax,4)
je     118f <weight_tradingpost+0x6f>
movslq -0x54(%rbp),%rax
cmpl   $0x0,-0x50(%rbp,%rax,4)
jne    118f <weight_tradingpost+0x6f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1194 <weight_tradingpost+0x74>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    115e <weight_tradingpost+0x3e>
mov    -0xc(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<weight_tradingpost>:
push   %rbx
sub    $0x40,%rsp
mov    %esi,%ebx
call   1040 <data_getdir@plt>
lea    0x20(%rsp),%rsi
mov    %eax,%edi
call   1030 <data_gettradables@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
call   1030 <data_gettradables@plt>
pxor   %xmm0,%xmm0
movdqa 0x20(%rsp),%xmm1
pcmpeqd %xmm0,%xmm1
pcmpeqd (%rsp),%xmm0
pandn  %xmm0,%xmm1
movmskps %xmm1,%eax
mov    %eax,%ecx
shr    %cl
and    $0x5,%cl
sub    %cl,%al
mov    %eax,%ecx
and    $0x33,%cl
shr    $0x2,%al
and    $0x33,%al
add    %cl,%al
mov    %eax,%ecx
shr    $0x4,%cl
add    %al,%cl
and    $0xf,%cl
movzbl %cl,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @weight_tradingpost(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [8 x i32]
%7 = alloca [8 x i32]
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = call i32 @data_getdir(i32 %9, i32 %10)
%12 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 0
%13 = call i32 @data_gettradables(i32 %11, i32* %12)
%14 = load i32, i32* %4
%15 = getelementptr inbounds [8 x i32], [8 x i32]* %7, i64 0, i64 0
%16 = call i32 @data_gettradables(i32 %14, i32* %15)
store i32 0, i32* %8
br label %17
17: ; preds = %36, %2
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 4
br i1 %19, label %20, label %39
20: ; preds = %17
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [8 x i32], [8 x i32]* %6, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %20
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [8 x i32], [8 x i32]* %7, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = icmp ne i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %26
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %35
35: ; preds = %32, %26, %20
br label %36
36: ; preds = %35
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %17
39: ; preds = %17
%40 = load i32, i32* %5
ret i32 %40
}

LLVM IR (-O2):
define i32 @weight_tradingpost(i32 %0, i32 %1) {
%3 = alloca [8 x i32]
%4 = alloca [8 x i32]
%5 = bitcast [8 x i32]* %3 to i8*
%6 = tail call i32 @data_getdir(i32 %0, i32 %1)
%7 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%8 = call i32 @data_gettradables(i32 %6, i32* %7)
%9 = bitcast [8 x i32]* %4 to i8*
%10 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 0
%11 = call i32 @data_gettradables(i32 %1, i32* %10)
%12 = bitcast [8 x i32]* %3 to <4 x i32>*
%13 = load <4 x i32>, <4 x i32>* %12
%14 = icmp ne <4 x i32> %13, zeroinitializer
%15 = bitcast [8 x i32]* %4 to <4 x i32>*
%16 = load <4 x i32>, <4 x i32>* %15
%17 = icmp eq <4 x i32> %16, zeroinitializer
%18 = select <4 x i1> %14, <4 x i1> %17, <4 x i1> zeroinitializer
%19 = bitcast <4 x i1> %18 to i4
%20 = call i4 @llvm.ctpop.i4(i4 %19)
%21 = zext i4 %20 to i32
ret i32 %21
}