#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*/ addch(char);
int /*<<< orphan*/ anykey(int, int);
int /*<<< orphan*/ curs_set(int);
int /*<<< orphan*/ displayMenu();
char getch();
int iscorrect(int, int);
scalar_t__ isdigit(char);
int /*<<< orphan*/ mvprintw(int, int, char *, ...);
int getNumPlayers() {
  char c;
  int num, setBreak = 0;
  for (;;) {
    displayMenu();
    curs_set(1);
    mvprintw(10, 2, "Enter the number of players (1-5): ");
    c = getch();
    if (c == '\n')
      mvprintw(12, 2, "Invalid input: No input given.");
    else
      addch(c);
    if (isdigit(c)) {
      num = c - 48;
      if (num > 5)
        mvprintw(12, 2, "Invalid input: Too many players.");
      else if (num == 0)
        mvprintw(12, 2, "Invalid input: No players.");
      else {
        mvprintw(12, 2, "You have selected %d player(s).", num);
        setBreak = iscorrect(14, 2);
      }
    } else if (c != '\n')
      mvprintw(12, 2, "Invalid input: Not a number.");
    anykey(18, 2);
    if (setBreak)
      return num;
  }
}


x86 assembly (clang, -O0):
<getNumPlayers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <displayMenu@plt>
mov    $0x1,%edi
call   1090 <curs_set@plt>
mov    $0xa,%edi
mov    $0x2,%esi
lea    0xe4f(%rip),%rdx
mov    $0x0,%al
call   10a0 <mvprintw@plt>
mov    $0x0,%al
call   1070 <getch@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0xa,%eax
jne    11ec <getNumPlayers+0x6c>
mov    $0xc,%edi
mov    $0x2,%esi
lea    0xe44(%rip),%rdx
mov    $0x0,%al
call   10a0 <mvprintw@plt>
jmp    11f5 <getNumPlayers+0x75>
movsbl -0x1(%rbp),%edi
call   1060 <addch@plt>
movsbl -0x1(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1297 <getNumPlayers+0x117>
movsbl -0x1(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jle    1239 <getNumPlayers+0xb9>
mov    $0xc,%edi
mov    $0x2,%esi
lea    0xe16(%rip),%rdx
mov    $0x0,%al
call   10a0 <mvprintw@plt>
jmp    1292 <getNumPlayers+0x112>
cmpl   $0x0,-0x8(%rbp)
jne    1260 <getNumPlayers+0xe0>
mov    $0xc,%edi
mov    $0x2,%esi
lea    0xe10(%rip),%rdx
mov    $0x0,%al
call   10a0 <mvprintw@plt>
jmp    128d <getNumPlayers+0x10d>
mov    -0x8(%rbp),%ecx
mov    $0xc,%edi
mov    $0x2,%esi
lea    0xe0b(%rip),%rdx
mov    $0x0,%al
call   10a0 <mvprintw@plt>
mov    $0xe,%edi
mov    $0x2,%esi
call   1080 <iscorrect@plt>
mov    %eax,-0xc(%rbp)
jmp    1292 <getNumPlayers+0x112>
jmp    12c1 <getNumPlayers+0x141>
movsbl -0x1(%rbp),%eax
cmp    $0xa,%eax
je     12bc <getNumPlayers+0x13c>
mov    $0xc,%edi
mov    $0x2,%esi
lea    0xdea(%rip),%rdx
mov    $0x0,%al
call   10a0 <mvprintw@plt>
jmp    12c1 <getNumPlayers+0x141>
mov    $0x12,%edi
mov    $0x2,%esi
call   1050 <anykey@plt>
cmpl   $0x0,-0xc(%rbp)
je     12e3 <getNumPlayers+0x163>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret
jmp    118f <getNumPlayers+0xf>

x86 assembly (clang, -O2):
<getNumPlayers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe6e(%rip),%r15
lea    0xe8b(%rip),%r14
jmp    11d8 <getNumPlayers+0x58>
xor    %r12d,%r12d
mov    $0xc,%edi
mov    $0x2,%esi
lea    0xef0(%rip),%rdx
xor    %eax,%eax
call   10a0 <mvprintw@plt>
cs nopw 0x0(%rax,%rax,1)
mov    $0x12,%edi
mov    $0x2,%esi
call   1050 <anykey@plt>
test   %r12d,%r12d
jne    12e2 <getNumPlayers+0x162>
xor    %eax,%eax
call   1040 <displayMenu@plt>
mov    $0x1,%edi
call   1090 <curs_set@plt>
mov    $0xa,%edi
mov    $0x2,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   10a0 <mvprintw@plt>
xor    %eax,%eax
call   1070 <getch@plt>
cmp    $0xa,%al
jne    1240 <getNumPlayers+0xc0>
xor    %r12d,%r12d
mov    $0xc,%edi
mov    $0x2,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <mvprintw@plt>
mov    $0xa,%edi
call   1030 <isdigit@plt>
mov    $0xffffffda,%ebp
test   %rax,%rax
jne    128b <getNumPlayers+0x10b>
jmp    11c0 <getNumPlayers+0x40>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%ebx
movsbl %al,%ebp
mov    %ebp,%edi
call   1060 <addch@plt>
mov    %ebp,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     119b <getNumPlayers+0x1b>
add    $0xffffffd0,%ebp
cmp    $0x36,%bl
jl     1287 <getNumPlayers+0x107>
xor    %r12d,%r12d
mov    $0xc,%edi
mov    $0x2,%esi
lea    0xdcb(%rip),%rdx
xor    %eax,%eax
call   10a0 <mvprintw@plt>
mov    %ebp,%r13d
jmp    11c0 <getNumPlayers+0x40>
test   %ebp,%ebp
je     12bf <getNumPlayers+0x13f>
mov    $0xc,%edi
mov    $0x2,%esi
lea    0xde3(%rip),%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   10a0 <mvprintw@plt>
mov    $0xe,%edi
mov    $0x2,%esi
call   1080 <iscorrect@plt>
mov    %eax,%r12d
mov    %ebp,%r13d
jmp    11c0 <getNumPlayers+0x40>
xor    %r13d,%r13d
mov    $0xc,%edi
mov    $0x2,%esi
lea    0xd91(%rip),%rdx
xor    %eax,%eax
call   10a0 <mvprintw@plt>
xor    %r12d,%r12d
jmp    11c0 <getNumPlayers+0x40>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Enter the number of players (1-5): \00"
@.str.1 = [31 x i8] c"Invalid input: No input given.\00"
@.str.2 = [33 x i8] c"Invalid input: Too many players.\00"
@.str.3 = [27 x i8] c"Invalid input: No players.\00"
@.str.4 = [32 x i8] c"You have selected %d player(s).\00"
@.str.5 = [29 x i8] c"Invalid input: Not a number.\00"
define i32 @getNumPlayers() {
%1 = alloca i8
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
br label %4
4: ; preds = %53, %0
%5 = call i32 (...) @displayMenu()
%6 = call i32 @curs_set(i32 1)
%7 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 10, i32 2, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%8 = call signext i8 (...) @getch()
store i8 %8, i8* %1
%9 = load i8, i8* %1
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 10
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 12, i32 2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %17
14: ; preds = %4
%15 = load i8, i8* %1
%16 = call i32 @addch(i8 signext %15)
br label %17
17: ; preds = %14, %12
%18 = load i8, i8* %1
%19 = call i64 @isdigit(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %40
21: ; preds = %17
%22 = load i8, i8* %1
%23 = sext i8 %22 to i32
%24 = sub nsw i32 %23, 48
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = icmp sgt i32 %25, 5
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 12, i32 2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %39
29: ; preds = %21
%30 = load i32, i32* %2
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 12, i32 2, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %38
34: ; preds = %29
%35 = load i32, i32* %2
%36 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 12, i32 2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = call i32 @iscorrect(i32 14, i32 2)
store i32 %37, i32* %3
br label %38
38: ; preds = %34, %32
br label %39
39: ; preds = %38, %27
br label %47
40: ; preds = %17
%41 = load i8, i8* %1
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 10
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 12, i32 2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %44, %40
br label %47
47: ; preds = %46, %39
%48 = call i32 @anykey(i32 18, i32 2)
%49 = load i32, i32* %3
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = load i32, i32* %2
ret i32 %52
53: ; preds = %47
br label %4
}

LLVM IR (-O2):
@.str = [36 x i8] c"Enter the number of players (1-5): \00"
@.str.1 = [31 x i8] c"Invalid input: No input given.\00"
@.str.2 = [33 x i8] c"Invalid input: Too many players.\00"
@.str.3 = [27 x i8] c"Invalid input: No players.\00"
@.str.4 = [32 x i8] c"You have selected %d player(s).\00"
@.str.5 = [29 x i8] c"Invalid input: Not a number.\00"
define i32 @getNumPlayers() {
br label %1
1: ; preds = %32, %0
%2 = phi i32 [ undef, %0 ], [ %33, %32 ]
%3 = tail call i32 (...) @displayMenu()
%4 = tail call i32 @curs_set(i32 1)
%5 = tail call i32 (i32, i32, i8*, ...) @mvprintw(i32 10, i32 2, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%6 = tail call signext i8 (...) @getch()
%7 = sext i8 %6 to i32
%8 = icmp eq i8 %6, 10
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = tail call i32 (i32, i32, i8*, ...) @mvprintw(i32 12, i32 2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i64 @isdigit(i8 signext 10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %32, label %26
13: ; preds = %1
%14 = tail call i32 @addch(i8 signext %6)
%15 = tail call i64 @isdigit(i8 signext %6)
%16 = icmp eq i64 %15, 0
br i1 %16, label %30, label %17
17: ; preds = %13
%18 = add nsw i32 %7, -48
%19 = icmp sgt i8 %6, 53
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 (i32, i32, i8*, ...) @mvprintw(i32 12, i32 2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %32
22: ; preds = %17
%23 = icmp eq i32 %18, 0
br i1 %23, label %24, label %26
24: ; preds = %22
%25 = tail call i32 (i32, i32, i8*, ...) @mvprintw(i32 12, i32 2, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %32
26: ; preds = %9, %22
%27 = phi i32 [ %18, %22 ], [ -38, %9 ]
%28 = tail call i32 (i32, i32, i8*, ...) @mvprintw(i32 12, i32 2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = tail call i32 @iscorrect(i32 14, i32 2)
br label %32
30: ; preds = %13
%31 = tail call i32 (i32, i32, i8*, ...) @mvprintw(i32 12, i32 2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %32
32: ; preds = %9, %30, %20, %26, %24
%33 = phi i32 [ %18, %20 ], [ 0, %24 ], [ %27, %26 ], [ %2, %30 ], [ %2, %9 ]
%34 = phi i32 [ 0, %20 ], [ 0, %24 ], [ %29, %26 ], [ 0, %30 ], [ 0, %9 ]
%35 = tail call i32 @anykey(i32 18, i32 2)
%36 = icmp eq i32 %34, 0
br i1 %36, label %1, label %37
37: ; preds = %32
ret i32 %33
}