#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 */
unsigned int genOddNum(int);
int getAnswer();
unsigned int isComp(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int primeGame(int lives) {
  printf("\nPrime game by %s %s\nCompiled on %s %s\n", "mewrox99",
         "https://github.com/mewrox99", "11:30:24", "Mar 18 2022");
  int correctAnswers = 0;
  lives = lives > 1 ? lives : 5;
  while (lives > 0) {
    unsigned int num = genOddNum(500);
    unsigned int factors = isComp(num);
    printf("\nIs %u prime? Enter y for yes, or any key for no >", num);
    int answer = getAnswer();
    if (factors && answer) {
      printf("Wrong - %u is not prime - it is a factor of %u\nYou have %d "
             "lives remaining\n",
             num, factors, --lives);
    } else if (!factors && !answer) {
      printf("Wrong %u is prime\nYou have %d lives remaining\n", num, --lives);
    } else {
      printf("Correct %u %s prime\n", num, (factors ? "isn't" : "is"));
      ++correctAnswers;
    }
  }
  return correctAnswers;
}


x86 assembly (clang, -O0):
<primeGame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0xeae(%rip),%rdi
lea    0xee2(%rip),%rsi
lea    0xec8(%rip),%rdx
lea    0xedd(%rip),%rcx
lea    0xedf(%rip),%r8
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x1,-0x4(%rbp)
jle    1191 <primeGame+0x51>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    119e <primeGame+0x5e>
mov    $0x5,%eax
mov    %eax,-0x18(%rbp)
jmp    119e <primeGame+0x5e>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1286 <primeGame+0x146>
mov    $0x1f4,%edi
call   1030 <genOddNum@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <isComp@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getAnswer@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1217 <primeGame+0xd7>
cmpl   $0x0,-0x14(%rbp)
je     1217 <primeGame+0xd7>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x4(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1281 <primeGame+0x141>
cmpl   $0x0,-0x10(%rbp)
jne    124a <primeGame+0x10a>
cmpl   $0x0,-0x14(%rbp)
jne    124a <primeGame+0x10a>
mov    -0xc(%rbp),%esi
mov    -0x4(%rbp),%edx
add    $0xffffffff,%edx
mov    %edx,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    127c <primeGame+0x13c>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%ecx
lea    0xecb(%rip),%rdx
lea    0xebe(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1281 <primeGame+0x141>
jmp    11a4 <primeGame+0x64>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<primeGame>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0xeac(%rip),%rdi
lea    0xee0(%rip),%rsi
lea    0xec6(%rip),%rdx
lea    0xedb(%rip),%rcx
lea    0xedd(%rip),%r8
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%ebp
mov    $0x5,%ebx
cmovge %ebp,%ebx
lea    0xed0(%rip),%r14
lea    0xefc(%rip),%r15
xor    %ebp,%ebp
jmp    11cd <primeGame+0x8d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %r13d,%r13d
lea    0xf78(%rip),%rdx
lea    0xf6b(%rip),%rax
cmovne %rax,%rdx
lea    0xf4b(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
test   %ebx,%ebx
jle    1241 <primeGame+0x101>
mov    $0x1f4,%edi
call   1030 <genOddNum@plt>
mov    %eax,%r12d
mov    %eax,%edi
call   1050 <isComp@plt>
mov    %eax,%r13d
mov    %r14,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getAnswer@plt>
test   %r13d,%r13d
je     1220 <primeGame+0xe0>
test   %eax,%eax
je     1220 <primeGame+0xe0>
add    $0xffffffff,%ebx
mov    %r15,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c9 <primeGame+0x89>
nopl   0x0(%rax,%rax,1)
or     %r13d,%eax
jne    11a0 <primeGame+0x60>
add    $0xffffffff,%ebx
lea    0xea5(%rip),%rdi
mov    %r12d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c9 <primeGame+0x89>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"\0APrime game by %s %s\0ACompiled on %s %s\0A\00"
@.str.1 = [9 x i8] c"mewrox99\00"
@.str.2 = [28 x i8] c"https://github.com/mewrox99\00"
@.str.3 = [9 x i8] c"11:30:24\00"
@.str.4 = [12 x i8] c"Mar 18 2022\00"
@.str.5 = [51 x i8] c"\0AIs %u prime? Enter y for yes, or any key for no >\00"
@.str.6 = [76 x i8] c"Wrong - %u is not prime - it is a factor of %u\0AYou have %d lives remaining\0A\00"
@.str.7 = [47 x i8] c"Wrong %u is prime\0AYou have %d lives remaining\0A\00"
@.str.8 = [21 x i8] c"Correct %u %s prime\0A\00"
@.str.9 = [6 x i8] c"isn't\00"
@.str.10 = [3 x i8] c"is\00"
define i32 @primeGame(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
%8 = load i32, i32* %2
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %2
br label %13
12: ; preds = %1
br label %13
13: ; preds = %12, %10
%14 = phi i32 [ %11, %10 ], [ 5, %12 ]
store i32 %14, i32* %2
br label %15
15: ; preds = %57, %13
%16 = load i32, i32* %2
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %58
18: ; preds = %15
%19 = call i32 @genOddNum(i32 500)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = call i32 @isComp(i32 %20)
store i32 %21, i32* %5
%22 = load i32, i32* %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0), i32 %22)
%24 = call i32 (...) @getAnswer()
store i32 %24, i32* %6
%25 = load i32, i32* %5
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %18
%28 = load i32, i32* %6
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i32, i32* %4
%32 = load i32, i32* %5
%33 = load i32, i32* %2
%34 = add nsw i32 %33, -1
store i32 %34, i32* %2
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.6, i64 0, i64 0), i32 %31, i32 %32, i32 %34)
br label %57
36: ; preds = %27, %18
%37 = load i32, i32* %5
%38 = icmp ne i32 %37, 0
br i1 %38, label %47, label %39
39: ; preds = %36
%40 = load i32, i32* %6
%41 = icmp ne i32 %40, 0
br i1 %41, label %47, label %42
42: ; preds = %39
%43 = load i32, i32* %4
%44 = load i32, i32* %2
%45 = add nsw i32 %44, -1
store i32 %45, i32* %2
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i32 %43, i32 %45)
br label %56
47: ; preds = %39, %36
%48 = load i32, i32* %4
%49 = load i32, i32* %5
%50 = icmp ne i32 %49, 0
%51 = zext i1 %50 to i64
%52 = select i1 %50, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 %48, i8* %52)
%54 = load i32, i32* %3
%55 = add nsw i32 %54, 1
store i32 %55, i32* %3
br label %56
56: ; preds = %47, %42
br label %57
57: ; preds = %56, %30
br label %15
58: ; preds = %15
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [40 x i8] c"\0APrime game by %s %s\0ACompiled on %s %s\0A\00"
@.str.1 = [9 x i8] c"mewrox99\00"
@.str.2 = [28 x i8] c"https://github.com/mewrox99\00"
@.str.3 = [9 x i8] c"11:30:24\00"
@.str.4 = [12 x i8] c"Mar 18 2022\00"
@.str.5 = [51 x i8] c"\0AIs %u prime? Enter y for yes, or any key for no >\00"
@.str.6 = [76 x i8] c"Wrong - %u is not prime - it is a factor of %u\0AYou have %d lives remaining\0A\00"
@.str.7 = [47 x i8] c"Wrong %u is prime\0AYou have %d lives remaining\0A\00"
@.str.8 = [21 x i8] c"Correct %u %s prime\0A\00"
@.str.9 = [6 x i8] c"isn't\00"
@.str.10 = [3 x i8] c"is\00"
define i32 @primeGame(i32 %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%3 = icmp sgt i32 %0, 1
%4 = select i1 %3, i32 %0, i32 5
br label %5
5: ; preds = %1, %27
%6 = phi i32 [ %29, %27 ], [ %4, %1 ]
%7 = phi i32 [ %28, %27 ], [ 0, %1 ]
%8 = tail call i32 @genOddNum(i32 500)
%9 = tail call i32 @isComp(i32 %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0), i32 %8)
%11 = tail call i32 (...) @getAnswer()
%12 = icmp ne i32 %9, 0
%13 = icmp ne i32 %11, 0
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %15, label %18
15: ; preds = %5
%16 = add nsw i32 %6, -1
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @.str.6, i64 0, i64 0), i32 %8, i32 %9, i32 %16)
br label %27
18: ; preds = %5
%19 = select i1 %12, i1 true, i1 %13
br i1 %19, label %23, label %20
20: ; preds = %18
%21 = add nsw i32 %6, -1
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i32 %8, i32 %21)
br label %27
23: ; preds = %18
%24 = select i1 %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 %8, i8* %24)
%26 = add nsw i32 %7, 1
br label %27
27: ; preds = %20, %23, %15
%28 = phi i32 [ %7, %15 ], [ %26, %23 ], [ %7, %20 ]
%29 = phi i32 [ %16, %15 ], [ %6, %23 ], [ %21, %20 ]
%30 = icmp sgt i32 %29, 0
br i1 %30, label %5, label %31
31: ; preds = %27
ret i32 %28
}