#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_marketplace(int player) {
  int weight = 0;
  int i, j;
  int prod[7 + 1];
  data_gettradables(player, prod);
  int trade[7 + 1];
  for (i = 0; i < 2; i++) {
    data_gettradables(data_getdir(i, player), trade);
    for (j = 4; j <= 6; j++) {
      if (trade[j] && !prod[j])
        weight++;
    }
  }
  return weight;
}


x86 assembly (clang, -O0):
<weight_marketplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1030 <data_gettradables@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    11c3 <weight_marketplace+0xa3>
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1040 <data_getdir@plt>
mov    %eax,%edi
lea    -0x50(%rbp),%rsi
call   1030 <data_gettradables@plt>
movl   $0x4,-0x10(%rbp)
cmpl   $0x6,-0x10(%rbp)
jg     11b0 <weight_marketplace+0x90>
movslq -0x10(%rbp),%rax
cmpl   $0x0,-0x50(%rbp,%rax,4)
je     119d <weight_marketplace+0x7d>
movslq -0x10(%rbp),%rax
cmpl   $0x0,-0x30(%rbp,%rax,4)
jne    119d <weight_marketplace+0x7d>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a2 <weight_marketplace+0x82>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116c <weight_marketplace+0x4c>
jmp    11b5 <weight_marketplace+0x95>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1145 <weight_marketplace+0x25>
mov    -0x8(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<weight_marketplace>:
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %edi,%ebx
lea    0x20(%rsp),%rsi
call   1030 <data_gettradables@plt>
xor    %edi,%edi
mov    %ebx,%esi
call   1040 <data_getdir@plt>
mov    %rsp,%r14
mov    %eax,%edi
mov    %r14,%rsi
call   1030 <data_gettradables@plt>
movsd  0x14(%rsp),%xmm1
movaps %xmm1,0x40(%rsp)
movsd  0x34(%rsp),%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm1,%xmm2
unpcklps 0x10(%rsp),%xmm2
movaps %xmm2,0x50(%rsp)
unpcklps 0x30(%rsp),%xmm0
movaps %xmm0,0x70(%rsp)
mov    $0x1,%edi
mov    %ebx,%esi
call   1040 <data_getdir@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1030 <data_gettradables@plt>
movss  0x10(%rsp),%xmm0
shufps $0xd4,0x40(%rsp),%xmm0
movaps 0x50(%rsp),%xmm1
shufps $0x21,%xmm0,%xmm1
xorps  %xmm0,%xmm0
pcmpeqd %xmm0,%xmm1
movdqa %xmm1,%xmm2
movss  0x30(%rsp),%xmm1
cmpl   $0x0,0x14(%rsp)
shufps $0xd4,0x60(%rsp),%xmm1
setne  %al
cmpl   $0x0,0x34(%rsp)
sete   %cl
and    %al,%cl
cmpl   $0x0,0x18(%rsp)
movaps 0x70(%rsp),%xmm3
shufps $0x21,%xmm1,%xmm3
setne  %al
cmpl   $0x0,0x38(%rsp)
movzbl %cl,%ecx
sete   %dl
and    %al,%dl
movzbl %dl,%edx
pcmpeqd %xmm0,%xmm3
pandn  %xmm3,%xmm2
movmskps %xmm2,%eax
mov    %eax,%ebx
shr    %bl
and    $0x5,%bl
sub    %bl,%al
mov    %eax,%ebx
and    $0x33,%bl
shr    $0x2,%al
and    $0x33,%al
add    %bl,%al
mov    %eax,%ebx
shr    $0x4,%bl
add    %al,%bl
and    $0xf,%bl
movzbl %bl,%eax
add    %ecx,%eax
add    %edx,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @weight_marketplace(i32 %0) {
%2 = alloca [8 x i32]
%3 = alloca [8 x i32]
%4 = bitcast [8 x i32]* %2 to i8*
%5 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%6 = call i32 @data_gettradables(i32 %0, i32* %5)
%7 = bitcast [8 x i32]* %3 to i8*
%8 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%9 = call i32 @data_getdir(i32 0, i32 %0)
%10 = call i32 @data_gettradables(i32 %9, i32* %8)
%11 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 4
%12 = bitcast i32* %11 to <4 x i32>*
%13 = load <4 x i32>, <4 x i32>* %12
%14 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 4
%15 = bitcast i32* %14 to <4 x i32>*
%16 = load <4 x i32>, <4 x i32>* %15
%17 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 5
%18 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 5
%19 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 6
%20 = bitcast i32* %17 to <2 x i32>*
%21 = load <2 x i32>, <2 x i32>* %20
%22 = bitcast i32* %18 to <2 x i32>*
%23 = load <2 x i32>, <2 x i32>* %22
%24 = call i32 @data_getdir(i32 1, i32 %0)
%25 = call i32 @data_gettradables(i32 %24, i32* %8)
%26 = load i32, i32* %11
%27 = shufflevector <2 x i32> %21, <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
%28 = shufflevector <4 x i32> %13, <4 x i32> %27, <4 x i32> <i32 0, i32 4, i32 5, i32 undef>
%29 = insertelement <4 x i32> %28, i32 %26, i64 3
%30 = icmp ne <4 x i32> %29, zeroinitializer
%31 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 4
%32 = load i32, i32* %31
%33 = shufflevector <2 x i32> %23, <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
%34 = shufflevector <4 x i32> %16, <4 x i32> %33, <4 x i32> <i32 0, i32 4, i32 5, i32 undef>
%35 = insertelement <4 x i32> %34, i32 %32, i64 3
%36 = icmp eq <4 x i32> %35, zeroinitializer
%37 = select <4 x i1> %30, <4 x i1> %36, <4 x i1> zeroinitializer
%38 = load i32, i32* %17
%39 = icmp ne i32 %38, 0
%40 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 5
%41 = load i32, i32* %40
%42 = icmp eq i32 %41, 0
%43 = select i1 %39, i1 %42, i1 false
%44 = zext i1 %43 to i32
%45 = load i32, i32* %19
%46 = icmp ne i32 %45, 0
%47 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 6
%48 = load i32, i32* %47
%49 = icmp eq i32 %48, 0
%50 = select i1 %46, i1 %49, i1 false
%51 = zext i1 %50 to i32
%52 = bitcast <4 x i1> %37 to i4
%53 = call i4 @llvm.ctpop.i4(i4 %52)
%54 = zext i4 %53 to i32
%55 = add nuw nsw i32 %54, %44
%56 = add nuw nsw i32 %55, %51
ret i32 %56
}