#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*/ printf(char *);
int rand();
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(void) {
  char userInput = '.';
  int randomRPS = 0;
  srand((unsigned)time(NULL));
  randomRPS = ((rand() % 3) + 1);
  printf("Rock, paper, or scissors? ");
  scanf("%c", &userInput);
  if (userInput == 'r') {
    if (randomRPS == 1) {
      printf("I rolled rock. ");
      printf("We tie!");
    } else if (randomRPS == 2) {
      printf("I rolled paper. ");
      printf("You lose!");
    } else {
      printf("I rolled scissor. ");
      printf("You win!");
    }
  } else if (userInput == 'p') {
    if (randomRPS == 1) {
      printf("I rolled rock. ");
      printf("You win!");
    } else if (randomRPS == 2) {
      printf("I rolled paper. ");
      printf("We tie!");
    } else {
      printf("I rolled scissor. ");
      printf("You lose!");
    }
  } else if (userInput == 's') {
    if (randomRPS == 1) {
      printf("I rolled rock. ");
      printf("You lose!");
    } else if (randomRPS == 2) {
      printf("I rolled paper. ");
      printf("You win! ");
    } else {
      printf("I rolled scissor. ");
      printf("We tie!");
    }
  } else {
    printf("Error: you did not enter 'r', 'p', or 's'!");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x2e,-0x5(%rbp)
movl   $0x0,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
lea    0xe79(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1060 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x72,%eax
jne    1228 <main+0xd8>
cmpl   $0x1,-0xc(%rbp)
jne    11df <main+0x8f>
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
jmp    1223 <main+0xd3>
cmpl   $0x2,-0xc(%rbp)
jne    1206 <main+0xb6>
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
jmp    121e <main+0xce>
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
jmp    1223 <main+0xd3>
jmp    1338 <main+0x1e8>
movsbl -0x5(%rbp),%eax
cmp    $0x70,%eax
jne    12a5 <main+0x155>
cmpl   $0x1,-0xc(%rbp)
jne    125c <main+0x10c>
lea    0xdd8(%rip),%rdi
call   1030 <printf@plt>
lea    0xe12(%rip),%rdi
call   1030 <printf@plt>
jmp    12a0 <main+0x150>
cmpl   $0x2,-0xc(%rbp)
jne    1283 <main+0x133>
lea    0xdc9(%rip),%rdi
call   1030 <printf@plt>
lea    0xdb5(%rip),%rdi
call   1030 <printf@plt>
jmp    129b <main+0x14b>
lea    0xdc7(%rip),%rdi
call   1030 <printf@plt>
lea    0xdb1(%rip),%rdi
call   1030 <printf@plt>
jmp    12a0 <main+0x150>
jmp    1333 <main+0x1e3>
movsbl -0x5(%rbp),%eax
cmp    $0x73,%eax
jne    1322 <main+0x1d2>
cmpl   $0x1,-0xc(%rbp)
jne    12d9 <main+0x189>
lea    0xd5b(%rip),%rdi
call   1030 <printf@plt>
lea    0xd78(%rip),%rdi
call   1030 <printf@plt>
jmp    131d <main+0x1cd>
cmpl   $0x2,-0xc(%rbp)
jne    1300 <main+0x1b0>
lea    0xd4c(%rip),%rdi
call   1030 <printf@plt>
lea    0xd77(%rip),%rdi
call   1030 <printf@plt>
jmp    1318 <main+0x1c8>
lea    0xd4a(%rip),%rdi
call   1030 <printf@plt>
lea    0xd1b(%rip),%rdi
call   1030 <printf@plt>
jmp    131d <main+0x1cd>
jmp    132e <main+0x1de>
lea    0xd4e(%rip),%rdi
call   1030 <printf@plt>
jmp    1333 <main+0x1e3>
jmp    1338 <main+0x1e8>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
movb   $0x2e,0x7(%rsp)
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
mov    %eax,%ebp
sub    %ecx,%ebp
neg    %ecx
lea    (%rax,%rcx,1),%ebx
add    $0x1,%ebx
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
lea    0xe76(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x7(%rsp),%al
cmp    $0x70,%al
je     11f0 <main+0xa0>
cmp    $0x73,%al
je     1219 <main+0xc9>
cmp    $0x72,%al
jne    124b <main+0xfb>
test   %ebp,%ebp
je     1263 <main+0x113>
cmp    $0x2,%ebx
lea    0xe61(%rip),%rax
lea    0xe75(%rip),%rdi
cmove  %rax,%rdi
lea    0xe60(%rip),%rax
lea    0xe76(%rip),%rbx
jmp    1240 <main+0xf0>
test   %ebp,%ebp
je     1273 <main+0x123>
cmp    $0x2,%ebx
lea    0xe38(%rip),%rax
lea    0xe4c(%rip),%rdi
cmove  %rax,%rdi
lea    0xe1e(%rip),%rax
lea    0xe30(%rip),%rbx
jmp    1240 <main+0xf0>
test   %ebp,%ebp
je     1283 <main+0x133>
cmp    $0x2,%ebx
lea    0xe0f(%rip),%rax
lea    0xe23(%rip),%rdi
cmove  %rax,%rdi
lea    0xe34(%rip),%rax
lea    0xdee(%rip),%rbx
cmove  %rax,%rbx
call   1030 <printf@plt>
jmp    1252 <main+0x102>
lea    0xe25(%rip),%rbx
mov    %rbx,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdc4(%rip),%rbx
lea    0xdad(%rip),%rdi
jmp    1244 <main+0xf4>
lea    0xdea(%rip),%rbx
lea    0xd9d(%rip),%rdi
jmp    1244 <main+0xf4>
lea    0xdbd(%rip),%rbx
lea    0xd8d(%rip),%rdi
jmp    1244 <main+0xf4>

LLVM IR (-O0):
@.str = [27 x i8] c"Rock, paper, or scissors? \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [16 x i8] c"I rolled rock. \00"
@.str.3 = [8 x i8] c"We tie!\00"
@.str.4 = [17 x i8] c"I rolled paper. \00"
@.str.5 = [10 x i8] c"You lose!\00"
@.str.6 = [19 x i8] c"I rolled scissor. \00"
@.str.7 = [9 x i8] c"You win!\00"
@.str.8 = [10 x i8] c"You win! \00"
@.str.9 = [43 x i8] c"Error: you did not enter 'r', 'p', or 's'!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
store i32 0, i32* %1
store i8 46, i8* %2
store i32 0, i32* %3
%4 = call i64 @time(i32* null)
%5 = trunc i64 %4 to i32
%6 = call i32 @srand(i32 %5)
%7 = call i32 (...) @rand()
%8 = srem i32 %7, 3
%9 = add nsw i32 %8, 1
store i32 %9, i32* %3
%10 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 114
br i1 %14, label %15, label %32
15: ; preds = %0
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %31
21: ; preds = %15
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %30
27: ; preds = %21
%28 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%29 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %30
30: ; preds = %27, %24
br label %31
31: ; preds = %30, %18
br label %78
32: ; preds = %0
%33 = load i8, i8* %2
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 112
br i1 %35, label %36, label %53
36: ; preds = %32
%37 = load i32, i32* %3
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %52
42: ; preds = %36
%43 = load i32, i32* %3
%44 = icmp eq i32 %43, 2
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %51
48: ; preds = %42
%49 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%50 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %51
51: ; preds = %48, %45
br label %52
52: ; preds = %51, %39
br label %77
53: ; preds = %32
%54 = load i8, i8* %2
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 115
br i1 %56, label %57, label %74
57: ; preds = %53
%58 = load i32, i32* %3
%59 = icmp eq i32 %58, 1
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%62 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %73
63: ; preds = %57
%64 = load i32, i32* %3
%65 = icmp eq i32 %64, 2
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%68 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
br label %72
69: ; preds = %63
%70 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%71 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %72
72: ; preds = %69, %66
br label %73
73: ; preds = %72, %60
br label %76
74: ; preds = %53
%75 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0))
br label %76
76: ; preds = %74, %73
br label %77
77: ; preds = %76, %52
br label %78
78: ; preds = %77, %31
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Rock, paper, or scissors? \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [16 x i8] c"I rolled rock. \00"
@.str.3 = [8 x i8] c"We tie!\00"
@.str.4 = [17 x i8] c"I rolled paper. \00"
@.str.5 = [10 x i8] c"You lose!\00"
@.str.6 = [19 x i8] c"I rolled scissor. \00"
@.str.7 = [9 x i8] c"You win!\00"
@.str.8 = [10 x i8] c"You win! \00"
@.str.9 = [43 x i8] c"Error: you did not enter 'r', 'p', or 's'!\00"
define i32 @main() {
%1 = alloca i8
store i8 46, i8* %1
%2 = tail call i64 @time(i32* null)
%3 = trunc i64 %2 to i32
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 3
%7 = add nsw i32 %6, 1
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%10 = load i8, i8* %1
switch i8 %10, label %33 [
i8 114, label %11
i8 112, label %17
i8 115, label %23
]
11: ; preds = %0
%12 = icmp eq i32 %6, 0
br i1 %12, label %29, label %13
13: ; preds = %11
%14 = icmp eq i32 %7, 2
%15 = select i1 %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0)
%16 = select i1 %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0)
br label %29
17: ; preds = %0
%18 = icmp eq i32 %6, 0
br i1 %18, label %29, label %19
19: ; preds = %17
%20 = icmp eq i32 %7, 2
%21 = select i1 %20, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0)
%22 = select i1 %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0)
br label %29
23: ; preds = %0
%24 = icmp eq i32 %6, 0
br i1 %24, label %29, label %25
25: ; preds = %23
%26 = icmp eq i32 %7, 2
%27 = select i1 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0)
%28 = select i1 %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0)
br label %29
29: ; preds = %25, %23, %19, %17, %13, %11
%30 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), %11 ], [ %15, %13 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), %17 ], [ %21, %19 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), %23 ], [ %27, %25 ]
%31 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %11 ], [ %16, %13 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), %17 ], [ %22, %19 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), %23 ], [ %28, %25 ]
%32 = call i32 @printf(i8* dereferenceable(1) %30)
br label %33
33: ; preds = %29, %0
%34 = phi i8* [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0), %0 ], [ %31, %29 ]
%35 = call i32 @printf(i8* dereferenceable(1) %34)
ret i32 0
}