#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*/ clean_buffer_keyboard();
int get_game_counter();
int /*<<< orphan*/ loadLogs(int);
int /*<<< orphan*/ print_game_information(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ readchar();
int scanf(char *, int *);
void replay_menu() {
  int gameCounter = get_game_counter();
  int control;
  int i;
  int option;
  if (gameCounter == 0) {
    printf("There are no games available.\n");
    printf("Press any key to go back to main menu...");
    readchar();
  } else {
    do {
      printf("\nGames available to replay:\n\n");
      for (i = 1; i <= gameCounter; i++) {
        print_game_information(i);
      }
      printf("\n(Choose an option and press enter).\nInsert 0 to return to "
             "main menu: ");
      control = scanf("%d", &option);
      clean_buffer_keyboard();
    } while (control == 0 || option < 0 || option > gameCounter);
    if (option != 0) {
      loadLogs(option);
    }
  }
}


x86 assembly (clang, -O0):
<replay_menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1090 <get_game_counter@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11b0 <replay_menu+0x40>
lea    0xe6d(%rip),%rdi
call   1050 <printf@plt>
lea    0xe80(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <readchar@plt>
jmp    125c <replay_menu+0xec>
jmp    11b5 <replay_menu+0x45>
lea    0xe8c(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11ea <replay_menu+0x7a>
mov    -0xc(%rbp),%edi
call   1080 <print_game_information@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c8 <replay_menu+0x58>
lea    0xe75(%rip),%rdi
call   1050 <printf@plt>
lea    0xeb0(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <scanf@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <clean_buffer_keyboard@plt>
mov    $0x1,%al
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x11(%rbp)
je     123a <replay_menu+0xca>
mov    $0x1,%al
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jl     123a <replay_menu+0xca>
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
setg   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11b5 <replay_menu+0x45>
cmpl   $0x0,-0x10(%rbp)
je     1257 <replay_menu+0xe7>
mov    -0x10(%rbp),%edi
call   1070 <loadLogs@plt>
jmp    125c <replay_menu+0xec>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replay_menu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   10a0 <get_game_counter@plt>
test   %eax,%eax
je     123e <replay_menu+0xbe>
mov    %eax,%ebx
mov    %eax,%r14d
neg    %r14d
lea    0xe80(%rip),%r15
lea    0xec0(%rip),%r12
lea    0x4(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xeac(%rip),%rdi
call   1040 <puts@plt>
test   %ebx,%ebx
jle    11fa <replay_menu+0x7a>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
call   1090 <print_game_information@plt>
lea    (%r14,%rbp,1),%eax
add    $0x1,%eax
mov    %ebp,%ecx
add    $0x1,%ecx
mov    %ecx,%ebp
cmp    $0x1,%eax
jne    11e0 <replay_menu+0x60>
mov    %r15,%rdi
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1070 <scanf@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <clean_buffer_keyboard@plt>
test   %ebp,%ebp
je     11c0 <replay_menu+0x40>
mov    0x4(%rsp),%edi
test   %edi,%edi
js     11c0 <replay_menu+0x40>
cmp    %ebx,%edi
jg     11c0 <replay_menu+0x40>
test   %edi,%edi
je     122f <replay_menu+0xaf>
call   1080 <loadLogs@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe4b(%rip),%rdi
call   1040 <puts@plt>
lea    0xdaf(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <readchar@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"There are no games available.\0A\00"
@.str.1 = [41 x i8] c"Press any key to go back to main menu...\00"
@.str.2 = [30 x i8] c"\0AGames available to replay:\0A\0A\00"
@.str.3 = [71 x i8] c"\0A(Choose an option and press enter).\0AInsert 0 to return to main menu: \00"
@.str.4 = [3 x i8] c"%d\00"
define void @replay_menu() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (...) @get_game_counter()
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (...) @readchar()
br label %48
12: ; preds = %0
br label %13
13: ; preds = %39, %12
%14 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %15
15: ; preds = %22, %13
%16 = load i32, i32* %3
%17 = load i32, i32* %1
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i32, i32* %3
%21 = call i32 @print_game_information(i32 %20)
br label %22
22: ; preds = %19
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %15
25: ; preds = %15
%26 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
store i32 %27, i32* %2
%28 = call i32 (...) @clean_buffer_keyboard()
br label %29
29: ; preds = %25
%30 = load i32, i32* %2
%31 = icmp eq i32 %30, 0
br i1 %31, label %39, label %32
32: ; preds = %29
%33 = load i32, i32* %4
%34 = icmp slt i32 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %32
%36 = load i32, i32* %4
%37 = load i32, i32* %1
%38 = icmp sgt i32 %36, %37
br label %39
39: ; preds = %35, %32, %29
%40 = phi i1 [ true, %32 ], [ true, %29 ], [ %38, %35 ]
br i1 %40, label %13, label %41
41: ; preds = %39
%42 = load i32, i32* %4
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i32, i32* %4
%46 = call i32 @loadLogs(i32 %45)
br label %47
47: ; preds = %44, %41
br label %48
48: ; preds = %47, %8
ret void
}

LLVM IR (-O2):
@.str.1 = [41 x i8] c"Press any key to go back to main menu...\00"
@.str.3 = [71 x i8] c"\0A(Choose an option and press enter).\0AInsert 0 to return to main menu: \00"
@.str.4 = [3 x i8] c"%d\00"
@str = [29 x i8] c"\0AGames available to replay:\0A\00"
@str.5 = [30 x i8] c"There are no games available.\00"
define void @replay_menu() {
%1 = alloca i32
%2 = tail call i32 (...) @get_game_counter()
%3 = bitcast i32* %1 to i8*
%4 = icmp eq i32 %2, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = icmp slt i32 %2, 1
br label %11
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.5, i64 0, i64 0))
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 (...) @readchar()
br label %32
11: ; preds = %5, %18
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br i1 %6, label %18, label %13
13: ; preds = %11, %13
%14 = phi i32 [ %16, %13 ], [ 1, %11 ]
%15 = call i32 @print_game_information(i32 %14)
%16 = add nuw i32 %14, 1
%17 = icmp eq i32 %14, %2
br i1 %17, label %18, label %13
18: ; preds = %13, %11
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%21 = call i32 (...) @clean_buffer_keyboard()
%22 = icmp eq i32 %20, 0
%23 = load i32, i32* %1
%24 = icmp slt i32 %23, 0
%25 = select i1 %22, i1 true, i1 %24
%26 = icmp sgt i32 %23, %2
%27 = select i1 %25, i1 true, i1 %26
br i1 %27, label %11, label %28
28: ; preds = %18
%29 = icmp eq i32 %23, 0
br i1 %29, label %32, label %30
30: ; preds = %28
%31 = call i32 @loadLogs(i32 %23)
br label %32
32: ; preds = %28, %30, %7
ret void
}