#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 */
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int strtol(char *, int /*<<< orphan*/ *, int);
int select_mode(void) {
  char buff[5];
  printf("\n\n---- Welcome to TicTacToe ----\n");
  do {
    printf("\nChoose your game mode:\n");
    printf("(1) Single player     (2) 2 player\n");
    printf("Choose: ");
    if (fgets(buff, sizeof(buff), stdin) != NULL) {
      switch (strtol(buff, NULL, 10)) {
      case 1:
        return 1;
      case 2:
        return 2;
      default:
        printf("Invalid choice (no match), try again\n");
      }
    }
  } while (1);
}


x86 assembly (clang, -O0):
<select_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
lea    0xed7(%rip),%rdi
call   1030 <printf@plt>
lea    0xee4(%rip),%rdi
call   1030 <printf@plt>
lea    0xefc(%rip),%rdi
call   1030 <printf@plt>
lea    -0x9(%rbp),%rdi
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11e8 <select_mode+0xb8>
xor    %eax,%eax
mov    %eax,%esi
lea    -0x9(%rbp),%rdi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
sub    $0x1,%eax
je     11bf <select_mode+0x8f>
jmp    11ae <select_mode+0x7e>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     11cb <select_mode+0x9b>
jmp    11d7 <select_mode+0xa7>
movl   $0x1,-0x4(%rbp)
jmp    11fc <select_mode+0xcc>
movl   $0x2,-0x4(%rbp)
jmp    11fc <select_mode+0xcc>
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
jmp    11e8 <select_mode+0xb8>
jmp    11ed <select_mode+0xbd>
mov    $0x1,%al
test   $0x1,%al
jne    1144 <select_mode+0x14>
jmp    11fc <select_mode+0xcc>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<select_mode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
lea    0xecc(%rip),%r14
lea    0xedd(%rip),%r15
lea    0xe94(%rip),%r12
mov    0x2e75(%rip),%rbp
lea    0x3(%rsp),%rbx
lea    0xee6(%rip),%r13
nop
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1040 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     1180 <select_mode+0x40>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
lea    -0x1(%rax),%ecx
cmp    $0x2,%ecx
jb     11ce <select_mode+0x8e>
mov    %r13,%rdi
call   1030 <puts@plt>
jmp    1180 <select_mode+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"\0A\0A---- Welcome to TicTacToe ----\0A\00"
@.str.1 = [25 x i8] c"\0AChoose your game mode:\0A\00"
@.str.2 = [36 x i8] c"(1) Single player (2) 2 player\0A\00"
@.str.3 = [9 x i8] c"Choose: \00"
@stdin = global i32 0
@.str.4 = [38 x i8] c"Invalid choice (no match), try again\0A\00"
define i32 @select_mode() {
%1 = alloca i32
%2 = alloca [5 x i8]
%3 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %21, %0
%5 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32* @fgets(i8* %8, i32 5, i32 %9)
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %20
12: ; preds = %4
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%14 = call i32 @strtol(i8* %13, i32* null, i32 10)
switch i32 %14, label %17 [
i32 1, label %15
i32 2, label %16
]
15: ; preds = %12
store i32 1, i32* %1
br label %22
16: ; preds = %12
store i32 2, i32* %1
br label %22
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
br label %19
19: ; preds = %17
br label %20
20: ; preds = %19, %4
br label %21
21: ; preds = %20
br i1 true, label %4, label %22
22: ; preds = %15, %16, %21
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str.3 = [9 x i8] c"Choose: \00"
@stdin = global i32 0
@str = [33 x i8] c"\0A\0A---- Welcome to TicTacToe ----\00"
@str.5 = [24 x i8] c"\0AChoose your game mode:\00"
@str.6 = [35 x i8] c"(1) Single player (2) 2 player\00"
@str.7 = [37 x i8] c"Invalid choice (no match), try again\00"
define i32 @select_mode() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %11, %0
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.5, i64 0, i64 0))
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.6, i64 0, i64 0))
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%8 = load i32, i32* @stdin
%9 = call i32* @fgets(i8* %2, i32 5, i32 %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %4, %16
br label %4
12: ; preds = %4
%13 = call i32 @strtol(i8* nocapture %2, i32* null, i32 10)
%14 = add i32 %13, -1
%15 = icmp ult i32 %14, 2
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.7, i64 0, i64 0))
br label %11
18: ; preds = %12
ret i32 %13
}