#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_atvertex(int, int);
int data_rank(int);
int ai_playerweight(int player, int p, int vert) {
  if (p == -1)
    return 0;
  int num = 1;
  if (p == player)
    num *= -1;
  num *= data_atvertex(p, vert);
  if (data_rank(p) == 1)
    num *= 3;
  return num;
}


x86 assembly (clang, -O0):
<ai_playerweight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1147 <ai_playerweight+0x27>
movl   $0x0,-0x4(%rbp)
jmp    1191 <ai_playerweight+0x71>
movl   $0x1,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    1161 <ai_playerweight+0x41>
imul   $0xffffffff,-0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <data_atvertex@plt>
imul   -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <data_rank@plt>
cmp    $0x1,%eax
jne    118b <ai_playerweight+0x6b>
imul   $0x3,-0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ai_playerweight>:
cmp    $0xffffffff,%esi
je     1157 <ai_playerweight+0x37>
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%r14d
mov    %esi,%edi
mov    %edx,%esi
call   1040 <data_atvertex@plt>
mov    %eax,%ebp
neg    %ebp
cmp    %r14d,%ebx
cmovne %eax,%ebp
mov    %ebx,%edi
call   1030 <data_rank@plt>
cmp    $0x1,%eax
lea    0x0(%rbp,%rbp,2),%eax
cmovne %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @ai_playerweight(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 0, i32* %4
br label %33
12: ; preds = %3
store i32 1, i32* %8
%13 = load i32, i32* %6
%14 = load i32, i32* %5
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %8
%18 = mul nsw i32 %17, -1
store i32 %18, i32* %8
br label %19
19: ; preds = %16, %12
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = call i32 @data_atvertex(i32 %20, i32 %21)
%23 = load i32, i32* %8
%24 = mul nsw i32 %23, %22
store i32 %24, i32* %8
%25 = load i32, i32* %6
%26 = call i32 @data_rank(i32 %25)
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %31
28: ; preds = %19
%29 = load i32, i32* %8
%30 = mul nsw i32 %29, 3
store i32 %30, i32* %8
br label %31
31: ; preds = %28, %19
%32 = load i32, i32* %8
store i32 %32, i32* %4
br label %33
33: ; preds = %31, %11
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
define i32 @ai_playerweight(i32 %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, -1
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = icmp eq i32 %1, %0
%7 = tail call i32 @data_atvertex(i32 %1, i32 %2)
%8 = sub nsw i32 0, %7
%9 = select i1 %6, i32 %8, i32 %7
%10 = tail call i32 @data_rank(i32 %1)
%11 = icmp eq i32 %10, 1
%12 = mul nsw i32 %9, 3
%13 = select i1 %11, i32 %12, i32 %9
br label %14
14: ; preds = %3, %5
%15 = phi i32 [ %13, %5 ], [ 0, %3 ]
ret i32 %15
}