#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 /*<<< orphan*/ scanf(char *, char *);
void rock_paper_scissors() {
  printf("Scissors cuts Paper\n");
  printf("Paper covers Rock\n");
  printf("(and as it always has) Rock crushes Scissors\n");
  printf("\n");
  printf("S. Scissors\n");
  printf("P. Paper\n");
  printf("R. Rock\n");
  char player1;
  char player2;
  printf("Player 1? ");
  scanf(" %c", &player1);
  while (player1 != 'S' && player1 != 'P' && player1 != 'R') {
    printf("INVALID ENTRY\n");
    printf("Player 1? ");
    scanf(" %c", &player1);
  }
  printf("Player 2? ");
  scanf(" %c", &player2);
  switch (player1) {
  case 'S':
    if (player2 == 'P') {
      printf("Player 1 wins.\n");
    }
    if (player2 == 'R') {
      printf("Player 2 wins.\n");
    }
    break;
  case 'P':
    if (player2 == 'R') {
      printf("Player 1 wins.\n");
    }
    if (player2 == 'S') {
      printf("Player 2 wins.\n");
    }
    break;
  case 'R':
    if (player2 == 'S') {
      printf("Player 1 wins.\n");
    }
    if (player2 == 'P') {
      printf("Player 2 wins.\n");
    }
    break;
  default:
    break;
  }
}


x86 assembly (clang, -O0):
<rock_paper_scissors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
call   1030 <printf@plt>
lea    0xeda(%rip),%rdi
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
call   1030 <printf@plt>
lea    0xf5a(%rip),%rdi
call   1030 <printf@plt>
lea    0xef7(%rip),%rdi
call   1030 <printf@plt>
lea    0xef8(%rip),%rdi
call   1030 <printf@plt>
lea    0xef6(%rip),%rdi
call   1030 <printf@plt>
lea    0xef3(%rip),%rdi
call   1030 <printf@plt>
lea    0xef2(%rip),%rdi
lea    -0x1(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0x1(%rbp),%ecx
xor    %eax,%eax
cmp    $0x53,%ecx
mov    %al,-0x3(%rbp)
je     11c9 <rock_paper_scissors+0xa9>
movsbl -0x1(%rbp),%ecx
xor    %eax,%eax
cmp    $0x50,%ecx
mov    %al,-0x3(%rbp)
je     11c9 <rock_paper_scissors+0xa9>
movsbl -0x1(%rbp),%eax
cmp    $0x52,%eax
setne  %al
mov    %al,-0x3(%rbp)
mov    -0x3(%rbp),%al
test   $0x1,%al
jne    11d9 <rock_paper_scissors+0xb9>
jmp    1206 <rock_paper_scissors+0xe6>
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
lea    0xe89(%rip),%rdi
lea    -0x1(%rbp),%rsi
call   1040 <scanf@plt>
jmp    1198 <rock_paper_scissors+0x78>
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
lea    0xe68(%rip),%rdi
lea    -0x2(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0x1(%rbp),%eax
mov    %eax,-0x8(%rbp)
sub    $0x50,%eax
je     1290 <rock_paper_scissors+0x170>
jmp    1237 <rock_paper_scissors+0x117>
mov    -0x8(%rbp),%eax
sub    $0x52,%eax
je     12c7 <rock_paper_scissors+0x1a7>
jmp    1248 <rock_paper_scissors+0x128>
mov    -0x8(%rbp),%eax
sub    $0x53,%eax
jne    12fe <rock_paper_scissors+0x1de>
jmp    1259 <rock_paper_scissors+0x139>
movsbl -0x2(%rbp),%eax
cmp    $0x50,%eax
jne    1272 <rock_paper_scissors+0x152>
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
movsbl -0x2(%rbp),%eax
cmp    $0x52,%eax
jne    128b <rock_paper_scissors+0x16b>
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
jmp    1303 <rock_paper_scissors+0x1e3>
movsbl -0x2(%rbp),%eax
cmp    $0x52,%eax
jne    12a9 <rock_paper_scissors+0x189>
lea    0xdfb(%rip),%rdi
call   1030 <printf@plt>
movsbl -0x2(%rbp),%eax
cmp    $0x53,%eax
jne    12c2 <rock_paper_scissors+0x1a2>
lea    0xdf2(%rip),%rdi
call   1030 <printf@plt>
jmp    1303 <rock_paper_scissors+0x1e3>
movsbl -0x2(%rbp),%eax
cmp    $0x53,%eax
jne    12e0 <rock_paper_scissors+0x1c0>
lea    0xdc4(%rip),%rdi
call   1030 <printf@plt>
movsbl -0x2(%rbp),%eax
cmp    $0x50,%eax
jne    12f9 <rock_paper_scissors+0x1d9>
lea    0xdbb(%rip),%rdi
call   1030 <printf@plt>
jmp    1303 <rock_paper_scissors+0x1e3>
jmp    1303 <rock_paper_scissors+0x1e3>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rock_paper_scissors>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xecb(%rip),%rdi
call   1040 <puts@plt>
lea    0xed3(%rip),%rdi
call   1040 <puts@plt>
lea    0xed9(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xef0(%rip),%rdi
call   1040 <puts@plt>
lea    0xef0(%rip),%rdi
call   1040 <puts@plt>
lea    0xeed(%rip),%rdi
call   1040 <puts@plt>
lea    0xe5f(%rip),%r14
mov    %r14,%rdi
call   1050 <printf@plt>
lea    0xe5b(%rip),%r15
lea    0x7(%rsp),%rbx
lea    0xeec(%rip),%r12
jmp    11d0 <rock_paper_scissors+0x90>
xchg   %ax,%ax
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
movzbl 0x7(%rsp),%eax
add    $0xb0,%al
cmp    $0x3,%al
ja     11c0 <rock_paper_scissors+0x80>
cmp    $0x1,%al
je     11c0 <rock_paper_scissors+0x80>
lea    0xe1e(%rip),%rdi
call   1050 <printf@plt>
lea    0xe0e(%rip),%rdi
lea    0x6(%rsp),%rsi
call   1060 <scanf@plt>
movsbl 0x7(%rsp),%eax
cmp    $0x50,%eax
je     1239 <rock_paper_scissors+0xf9>
cmp    $0x52,%eax
je     1257 <rock_paper_scissors+0x117>
cmp    $0x53,%eax
jne    127f <rock_paper_scissors+0x13f>
mov    0x6(%rsp),%al
cmp    $0x50,%al
jne    1233 <rock_paper_scissors+0xf3>
lea    0xe6f(%rip),%rdi
call   1040 <puts@plt>
mov    0x6(%rsp),%al
cmp    $0x52,%al
je     1273 <rock_paper_scissors+0x133>
jmp    127f <rock_paper_scissors+0x13f>
mov    0x6(%rsp),%al
cmp    $0x52,%al
jne    1251 <rock_paper_scissors+0x111>
lea    0xe51(%rip),%rdi
call   1040 <puts@plt>
mov    0x6(%rsp),%al
cmp    $0x53,%al
je     1273 <rock_paper_scissors+0x133>
jmp    127f <rock_paper_scissors+0x13f>
mov    0x6(%rsp),%al
cmp    $0x53,%al
jne    126f <rock_paper_scissors+0x12f>
lea    0xe33(%rip),%rdi
call   1040 <puts@plt>
mov    0x6(%rsp),%al
cmp    $0x50,%al
jne    127f <rock_paper_scissors+0x13f>
lea    0xe10(%rip),%rdi
call   1040 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Scissors cuts Paper\0A\00"
@.str.1 = [19 x i8] c"Paper covers Rock\0A\00"
@.str.2 = [46 x i8] c"(and as it always has) Rock crushes Scissors\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [13 x i8] c"S. Scissors\0A\00"
@.str.5 = [10 x i8] c"P. Paper\0A\00"
@.str.6 = [9 x i8] c"R. Rock\0A\00"
@.str.7 = [11 x i8] c"Player 1? \00"
@.str.8 = [4 x i8] c" %c\00"
@.str.9 = [15 x i8] c"INVALID ENTRY\0A\00"
@.str.10 = [11 x i8] c"Player 2? \00"
@.str.11 = [16 x i8] c"Player 1 wins.\0A\00"
@.str.12 = [16 x i8] c"Player 2 wins.\0A\00"
define void @rock_paper_scissors() {
%1 = alloca i8
%2 = alloca i8
%3 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %1)
br label %12
12: ; preds = %26, %0
%13 = load i8, i8* %1
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 83
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i8, i8* %1
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 80
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i8, i8* %1
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 82
br label %24
24: ; preds = %20, %16, %12
%25 = phi i1 [ false, %16 ], [ false, %12 ], [ %23, %20 ]
br i1 %25, label %26, label %30
26: ; preds = %24
%27 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%28 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%29 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %1)
br label %12
30: ; preds = %24
%31 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
%32 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %2)
%33 = load i8, i8* %1
%34 = sext i8 %33 to i32
switch i32 %34, label %74 [
i32 83, label %35
i32 80, label %48
i32 82, label %61
]
35: ; preds = %30
%36 = load i8, i8* %2
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 80
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
br label %41
41: ; preds = %39, %35
%42 = load i8, i8* %2
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 82
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.12, i64 0, i64 0))
br label %47
47: ; preds = %45, %41
br label %75
48: ; preds = %30
%49 = load i8, i8* %2
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 82
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
br label %54
54: ; preds = %52, %48
%55 = load i8, i8* %2
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 83
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.12, i64 0, i64 0))
br label %60
60: ; preds = %58, %54
br label %75
61: ; preds = %30
%62 = load i8, i8* %2
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 83
br i1 %64, label %65, label %67
65: ; preds = %61
%66 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
br label %67
67: ; preds = %65, %61
%68 = load i8, i8* %2
%69 = sext i8 %68 to i32
%70 = icmp eq i32 %69, 80
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.12, i64 0, i64 0))
br label %73
73: ; preds = %71, %67
br label %75
74: ; preds = %30
br label %75
75: ; preds = %74, %73, %60, %47
ret void
}

LLVM IR (-O2):
@.str.7 = [11 x i8] c"Player 1? \00"
@.str.8 = [4 x i8] c" %c\00"
@.str.10 = [11 x i8] c"Player 2? \00"
@str = [20 x i8] c"Scissors cuts Paper\00"
@str.13 = [18 x i8] c"Paper covers Rock\00"
@str.14 = [45 x i8] c"(and as it always has) Rock crushes Scissors\00"
@str.15 = [12 x i8] c"S. Scissors\00"
@str.16 = [9 x i8] c"P. Paper\00"
@str.17 = [8 x i8] c"R. Rock\00"
@str.22 = [15 x i8] c"Player 2 wins.\00"
@str.23 = [15 x i8] c"Player 1 wins.\00"
@str.24 = [14 x i8] c"INVALID ENTRY\00"
define void @rock_paper_scissors() {
%1 = alloca i8
%2 = alloca i8
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.13, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.14, i64 0, i64 0))
%6 = tail call i32 @putchar(i32 10)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.15, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.16, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.17, i64 0, i64 0))
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %11
11: ; preds = %14, %0
%12 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %1)
%13 = load i8, i8* %1
switch i8 %13, label %14 [
i8 83, label %17
i8 82, label %17
i8 80, label %17
]
14: ; preds = %11
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.24, i64 0, i64 0))
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %11
17: ; preds = %11, %11, %11
%18 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %2)
%20 = load i8, i8* %1
%21 = sext i8 %20 to i32
switch i32 %21, label %52 [
i32 83, label %22
i32 80, label %31
i32 82, label %40
]
22: ; preds = %17
%23 = load i8, i8* %2
%24 = icmp eq i8 %23, 80
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.23, i64 0, i64 0))
%27 = load i8, i8* %2
br label %28
28: ; preds = %25, %22
%29 = phi i8 [ %27, %25 ], [ %23, %22 ]
%30 = icmp eq i8 %29, 82
br i1 %30, label %49, label %52
31: ; preds = %17
%32 = load i8, i8* %2
%33 = icmp eq i8 %32, 82
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.23, i64 0, i64 0))
%36 = load i8, i8* %2
br label %37
37: ; preds = %34, %31
%38 = phi i8 [ %36, %34 ], [ %32, %31 ]
%39 = icmp eq i8 %38, 83
br i1 %39, label %49, label %52
40: ; preds = %17
%41 = load i8, i8* %2
%42 = icmp eq i8 %41, 83
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.23, i64 0, i64 0))
%45 = load i8, i8* %2
br label %46
46: ; preds = %43, %40
%47 = phi i8 [ %45, %43 ], [ %41, %40 ]
%48 = icmp eq i8 %47, 80
br i1 %48, label %49, label %52
49: ; preds = %46, %37, %28
%50 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.22, i64 0, i64 0), %28 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.22, i64 0, i64 0), %37 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.22, i64 0, i64 0), %46 ]
%51 = call i32 @puts(i8* dereferenceable(1) %50)
br label %52
52: ; preds = %49, %17, %46, %37, %28
ret void
}