#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_getwonder(int);
int data_getwonderside(int);
int data_getwonderstages(int);
int data_haswonderstage(int p, int wonder, int stage) {
  if (data_getwonder(p) != wonder)
    return 0;
  if (data_getwonderside(p) * 3 + 1 > stage)
    return 0;
  if (data_getwonderstages(p) + data_getwonderside(p) * 3 + 1 > stage)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<data_haswonderstage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <data_getwonder@plt>
cmp    -0xc(%rbp),%eax
je     115e <data_haswonderstage+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    11bd <data_haswonderstage+0x8d>
mov    -0x8(%rbp),%edi
call   1040 <data_getwonderside@plt>
imul   $0x3,%eax,%eax
add    $0x1,%eax
cmp    -0x10(%rbp),%eax
jle    1181 <data_haswonderstage+0x51>
movl   $0x0,-0x4(%rbp)
jmp    11bd <data_haswonderstage+0x8d>
mov    -0x8(%rbp),%edi
call   1030 <data_getwonderstages@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <data_getwonderside@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
imul   $0x3,%ecx,%ecx
add    %ecx,%eax
add    $0x1,%eax
cmp    -0x10(%rbp),%eax
jle    11b6 <data_haswonderstage+0x86>
movl   $0x1,-0x4(%rbp)
jmp    11bd <data_haswonderstage+0x8d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<data_haswonderstage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebx
mov    %edi,%ebp
call   1050 <data_getwonder@plt>
xor    %r15d,%r15d
cmp    %ebx,%eax
jne    1178 <data_haswonderstage+0x48>
mov    %ebp,%edi
call   1040 <data_getwonderside@plt>
lea    (%rax,%rax,2),%eax
cmp    %r14d,%eax
jge    1178 <data_haswonderstage+0x48>
mov    %ebp,%edi
call   1030 <data_getwonderstages@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <data_getwonderside@plt>
lea    (%rax,%rax,2),%eax
add    %ebx,%eax
xor    %r15d,%r15d
cmp    %r14d,%eax
setge  %r15b
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @data_haswonderstage(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @data_getwonder(i32 %0)
%5 = icmp eq i32 %4, %1
br i1 %5, label %6, label %17
6: ; preds = %3
%7 = tail call i32 @data_getwonderside(i32 %0)
%8 = mul nsw i32 %7, 3
%9 = icmp slt i32 %8, %2
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = tail call i32 @data_getwonderstages(i32 %0)
%12 = tail call i32 @data_getwonderside(i32 %0)
%13 = mul nsw i32 %12, 3
%14 = add nsw i32 %13, %11
%15 = icmp sge i32 %14, %2
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %10, %6, %3
%18 = phi i32 [ 0, %3 ], [ 0, %6 ], [ %16, %10 ]
ret i32 %18
}