#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 rand();
int computer_choice(int pile) {
  int r = (rand() % 3) + 1;
  if (pile <= 4) {
    if (pile == 4) {
      return 3;
    }
    if (pile == 3) {
      return 2;
    }
    if (pile == 2) {
      return 1;
    }
  } else {
    return r;
  }
}


x86 assembly (clang, -O0):
<computer_choice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
cmpl   $0x4,-0x8(%rbp)
jg     1181 <computer_choice+0x71>
cmpl   $0x4,-0x8(%rbp)
jne    1150 <computer_choice+0x40>
movl   $0x3,-0x4(%rbp)
jmp    1187 <computer_choice+0x77>
cmpl   $0x3,-0x8(%rbp)
jne    1166 <computer_choice+0x56>
movl   $0x2,-0x4(%rbp)
jmp    1187 <computer_choice+0x77>
cmpl   $0x2,-0x8(%rbp)
jne    117c <computer_choice+0x6c>
movl   $0x1,-0x4(%rbp)
jmp    1187 <computer_choice+0x77>
jmp    1187 <computer_choice+0x77>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<computer_choice>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <rand@plt>
cmp    $0x4,%ebx
jg     1137 <computer_choice+0x27>
xor    %ecx,%ecx
cmp    $0x3,%ebx
sete   %cl
xor    $0x3,%ecx
cmp    $0x2,%ebx
mov    $0x1,%eax
cmovne %ecx,%eax
pop    %rbx
ret
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @computer_choice(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = call i32 (...) @rand()
%6 = srem i32 %5, 3
%7 = add nsw i32 %6, 1
store i32 %7, i32* %4
%8 = load i32, i32* %3
%9 = icmp sle i32 %8, 4
br i1 %9, label %10, label %23
10: ; preds = %1
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 4
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 3, i32* %2
br label %25
14: ; preds = %10
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 3
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 2, i32* %2
br label %25
18: ; preds = %14
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 1, i32* %2
br label %25
22: ; preds = %18
br label %25
23: ; preds = %1
%24 = load i32, i32* %4
store i32 %24, i32* %2
br label %25
25: ; preds = %13, %17, %21, %23, %22
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @computer_choice(i32 %0) {
%2 = tail call i32 (...) @rand()
%3 = icmp slt i32 %0, 5
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = icmp eq i32 %0, 3
%6 = select i1 %5, i32 2, i32 3
%7 = icmp eq i32 %0, 2
%8 = select i1 %7, i32 1, i32 %6
br label %12
9: ; preds = %1
%10 = srem i32 %2, 3
%11 = add nsw i32 %10, 1
br label %12
12: ; preds = %4, %9
%13 = phi i32 [ %11, %9 ], [ %8, %4 ]
ret i32 %13
}