#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*/ data_addresource(int, int, int);
int data_getresource(int, int);
void devcards_domonopoly(int player, int res) {
  int tot = 0;
  int i;
  for (i = 1; i < 4; i++) {
    tot += data_getresource((player + i) % 4, res);
    data_addresource((player + i) % 4, res,
                     data_getresource((player + i) % 4, res) * -1);
  }
  data_addresource(player, res, tot);
}


x86 assembly (clang, -O0):
<devcards_domonopoly>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    11af <devcards_domonopoly+0x8f>
mov    -0x4(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x8(%rbp),%esi
call   1040 <data_getresource@plt>
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x8(%rbp),%esi
call   1040 <data_getresource@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
imul   $0xffffffff,%eax,%edx
call   1030 <data_addresource@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113c <devcards_domonopoly+0x1c>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <data_addresource@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<devcards_domonopoly>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
lea    0x1(%r15),%eax
lea    0x4(%r15),%ecx
test   %eax,%eax
cmovns %eax,%ecx
mov    %esi,%ebp
and    $0xfffffffc,%ecx
neg    %ecx
lea    (%r15,%rcx,1),%ebx
add    $0x1,%ebx
mov    %ebx,%edi
call   1040 <data_getresource@plt>
mov    %eax,%r14d
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <data_getresource@plt>
neg    %eax
mov    %ebx,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   1030 <data_addresource@plt>
lea    0x2(%r15),%eax
lea    0x5(%r15),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
neg    %ecx
lea    (%r15,%rcx,1),%ebx
add    $0x2,%ebx
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <data_getresource@plt>
add    %eax,%r14d
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <data_getresource@plt>
neg    %eax
mov    %ebx,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   1030 <data_addresource@plt>
lea    0x3(%r15),%eax
lea    0x6(%r15),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
neg    %ecx
lea    (%r15,%rcx,1),%ebx
add    $0x3,%ebx
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <data_getresource@plt>
add    %eax,%r14d
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <data_getresource@plt>
neg    %eax
mov    %ebx,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   1030 <data_addresource@plt>
mov    %r15d,%edi
mov    %ebp,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <data_addresource@plt>

LLVM IR (-O0):
define void @devcards_domonopoly(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 1, i32* %6
br label %7
7: ; preds = %32, %2
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %35
10: ; preds = %7
%11 = load i32, i32* %3
%12 = load i32, i32* %6
%13 = add nsw i32 %11, %12
%14 = srem i32 %13, 4
%15 = load i32, i32* %4
%16 = call i32 @data_getresource(i32 %14, i32 %15)
%17 = load i32, i32* %5
%18 = add nsw i32 %17, %16
store i32 %18, i32* %5
%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* %4
%24 = load i32, i32* %3
%25 = load i32, i32* %6
%26 = add nsw i32 %24, %25
%27 = srem i32 %26, 4
%28 = load i32, i32* %4
%29 = call i32 @data_getresource(i32 %27, i32 %28)
%30 = mul nsw i32 %29, -1
%31 = call i32 @data_addresource(i32 %22, i32 %23, i32 %30)
br label %32
32: ; preds = %10
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %7
35: ; preds = %7
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = load i32, i32* %5
%39 = call i32 @data_addresource(i32 %36, i32 %37, i32 %38)
ret void
}

LLVM IR (-O2):
define void @devcards_domonopoly(i32 %0, i32 %1) {
%3 = add nsw i32 %0, 1
%4 = srem i32 %3, 4
%5 = tail call i32 @data_getresource(i32 %4, i32 %1)
%6 = tail call i32 @data_getresource(i32 %4, i32 %1)
%7 = sub nsw i32 0, %6
%8 = tail call i32 @data_addresource(i32 %4, i32 %1, i32 %7)
%9 = add nsw i32 %0, 2
%10 = srem i32 %9, 4
%11 = tail call i32 @data_getresource(i32 %10, i32 %1)
%12 = add nsw i32 %11, %5
%13 = tail call i32 @data_getresource(i32 %10, i32 %1)
%14 = sub nsw i32 0, %13
%15 = tail call i32 @data_addresource(i32 %10, i32 %1, i32 %14)
%16 = add nsw i32 %0, 3
%17 = srem i32 %16, 4
%18 = tail call i32 @data_getresource(i32 %17, i32 %1)
%19 = add nsw i32 %18, %12
%20 = tail call i32 @data_getresource(i32 %17, i32 %1)
%21 = sub nsw i32 0, %20
%22 = tail call i32 @data_addresource(i32 %17, i32 %1, i32 %21)
%23 = tail call i32 @data_addresource(i32 %0, i32 %1, i32 %19)
ret void
}