#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 calc_science(int, int);
int /*<<< orphan*/ data_hasbuilt(int, int, int);
int science(int player) {
  if (!data_hasbuilt(player, 2, 25))
    return calc_science(player, -1);
  int max = 0;
  int i, m;
  for (i = 0; i < 3; i++) {
    m = calc_science(player, i);
    if (m > max)
      max = m;
  }
  return max;
}


x86 assembly (clang, -O0):
<science>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
mov    $0x19,%edx
call   1030 <data_hasbuilt@plt>
cmp    $0x0,%eax
jne    115b <science+0x3b>
mov    -0x8(%rbp),%edi
mov    $0xffffffff,%esi
call   1040 <calc_science@plt>
mov    %eax,-0x4(%rbp)
jmp    11ac <science+0x8c>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jge    11a6 <science+0x86>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <calc_science@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1193 <science+0x73>
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1198 <science+0x78>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1169 <science+0x49>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<science>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0x2,%esi
mov    $0x19,%edx
call   1030 <data_hasbuilt@plt>
test   %eax,%eax
je     1178 <science+0x58>
xor    %ebx,%ebx
mov    %r14d,%edi
xor    %esi,%esi
call   1040 <calc_science@plt>
mov    %eax,%ebp
test   %eax,%eax
cmovs  %ebx,%ebp
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <calc_science@plt>
mov    %eax,%ebx
cmp    %ebp,%eax
cmovle %ebp,%ebx
mov    %r14d,%edi
mov    $0x2,%esi
call   1040 <calc_science@plt>
cmp    %ebx,%eax
cmovle %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14d,%edi
mov    $0xffffffff,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <calc_science@plt>

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

LLVM IR (-O2):
define i32 @science(i32 %0) {
%2 = tail call i32 @data_hasbuilt(i32 %0, i32 2, i32 25)
%3 = icmp eq i32 %2, 0
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = tail call i32 @calc_science(i32 %0, i32 0)
%6 = icmp sgt i32 %5, 0
%7 = select i1 %6, i32 %5, i32 0
%8 = tail call i32 @calc_science(i32 %0, i32 1)
%9 = icmp sgt i32 %8, %7
%10 = select i1 %9, i32 %8, i32 %7
%11 = tail call i32 @calc_science(i32 %0, i32 2)
%12 = icmp sgt i32 %11, %10
%13 = select i1 %12, i32 %11, i32 %10
br label %16
14: ; preds = %1
%15 = tail call i32 @calc_science(i32 %0, i32 -1)
br label %16
16: ; preds = %4, %14
%17 = phi i32 [ %15, %14 ], [ %13, %4 ]
ret i32 %17
}