#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 data_numplayers();
int endgame_refresh(int);
int /*<<< orphan*/ halt();
int io_getkey();
int /*<<< orphan*/ postyn(int, int, char *);
void endgame() {
  int focus = 0;
  int bottomy;
  while (1) {
    bottomy = endgame_refresh(focus);
    switch (io_getkey()) {
    case 2:
      focus--;
      break;
    case 3:
      focus++;
      break;
    case 1:
      focus++;
      break;
    case 0:
      focus--;
      break;
    case 4:
      if (postyn(61, bottomy, "Are you sure you want to quit?"))
        halt();
      break;
    case '\t':
      focus = (focus + 1) % (data_numplayers() + 1);
      break;
    case 'q':
      if (postyn(61, bottomy, "Are you sure you want to quit?"))
        halt();
      break;
    default:
      break;
    }
    if (focus < 0)
      focus = data_numplayers() - 1;
    focus = focus % data_numplayers();
  }
}


x86 assembly (clang, -O0):
<endgame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <endgame_refresh@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
call   1030 <io_getkey@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
test   %eax,%eax
je     1213 <endgame+0xc3>
jmp    1183 <endgame+0x33>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
je     1205 <endgame+0xb5>
jmp    1194 <endgame+0x44>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
je     11e9 <endgame+0x99>
jmp    11a5 <endgame+0x55>
mov    -0xc(%rbp),%eax
sub    $0x3,%eax
je     11f7 <endgame+0xa7>
jmp    11b6 <endgame+0x66>
mov    -0xc(%rbp),%eax
sub    $0x4,%eax
je     1221 <endgame+0xd1>
jmp    11c7 <endgame+0x77>
mov    -0xc(%rbp),%eax
sub    $0x9,%eax
je     124a <endgame+0xfa>
jmp    11d8 <endgame+0x88>
mov    -0xc(%rbp),%eax
sub    $0x71,%eax
je     126d <endgame+0x11d>
jmp    1296 <endgame+0x146>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    129b <endgame+0x14b>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    129b <endgame+0x14b>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    129b <endgame+0x14b>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    129b <endgame+0x14b>
mov    -0x8(%rbp),%esi
mov    $0x3d,%edi
lea    0xdd0(%rip),%rdx
call   1050 <postyn@plt>
cmp    $0x0,%eax
je     1245 <endgame+0xf5>
mov    $0x0,%al
call   1040 <halt@plt>
jmp    129b <endgame+0x14b>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1070 <data_numplayers@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
add    $0x1,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
jmp    129b <endgame+0x14b>
mov    -0x8(%rbp),%esi
mov    $0x3d,%edi
lea    0xd84(%rip),%rdx
call   1050 <postyn@plt>
cmp    $0x0,%eax
je     1291 <endgame+0x141>
mov    $0x0,%al
call   1040 <halt@plt>
jmp    129b <endgame+0x14b>
jmp    129b <endgame+0x14b>
cmpl   $0x0,-0x4(%rbp)
jge    12b2 <endgame+0x162>
mov    $0x0,%al
call   1070 <data_numplayers@plt>
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1070 <data_numplayers@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
jmp    115f <endgame+0xf>

x86 assembly (clang, -O2):
<endgame>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeca(%rip),%r14
lea    0xe9b(%rip),%r15
xor    %ebp,%ebp
jmp    1180 <endgame+0x30>
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <data_numplayers@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %edx,%ebp
mov    %ebp,%edi
call   1060 <endgame_refresh@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <io_getkey@plt>
cmp    $0x9,%eax
ja     11a9 <endgame+0x59>
mov    %eax,%eax
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
add    $0x1,%ebp
test   %ebp,%ebp
jns    1170 <endgame+0x20>
jmp    11e4 <endgame+0x94>
cmp    $0x71,%eax
jne    11e0 <endgame+0x90>
mov    $0x3d,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1050 <postyn@plt>
test   %eax,%eax
je     11e0 <endgame+0x90>
xor    %eax,%eax
call   1040 <halt@plt>
test   %ebp,%ebp
jns    1170 <endgame+0x20>
jmp    11e4 <endgame+0x94>
add    $0xffffffff,%ebp
test   %ebp,%ebp
jns    1170 <endgame+0x20>
jmp    11e4 <endgame+0x94>
add    $0xffffffff,%ebp
nopw   0x0(%rax,%rax,1)
test   %ebp,%ebp
jns    1170 <endgame+0x20>
xor    %eax,%eax
call   1070 <data_numplayers@plt>
mov    %eax,%ebp
add    $0xffffffff,%ebp
jmp    1170 <endgame+0x20>
add    $0x1,%ebp
xor    %eax,%eax
call   1070 <data_numplayers@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %edx,%ebp
test   %ebp,%ebp
jns    1170 <endgame+0x20>
jmp    11e4 <endgame+0x94>

LLVM IR (-O0):
@.str = [31 x i8] c"Are you sure you want to quit?\00"
define void @endgame() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %0, %46
%4 = load i32, i32* %1
%5 = call i32 @endgame_refresh(i32 %4)
store i32 %5, i32* %2
%6 = call i32 (...) @io_getkey()
switch i32 %6, label %39 [
i32 2, label %7
i32 3, label %10
i32 1, label %13
i32 0, label %16
i32 4, label %19
i32 9, label %26
i32 113, label %32
]
7: ; preds = %3
%8 = load i32, i32* %1
%9 = add nsw i32 %8, -1
store i32 %9, i32* %1
br label %40
10: ; preds = %3
%11 = load i32, i32* %1
%12 = add nsw i32 %11, 1
store i32 %12, i32* %1
br label %40
13: ; preds = %3
%14 = load i32, i32* %1
%15 = add nsw i32 %14, 1
store i32 %15, i32* %1
br label %40
16: ; preds = %3
%17 = load i32, i32* %1
%18 = add nsw i32 %17, -1
store i32 %18, i32* %1
br label %40
19: ; preds = %3
%20 = load i32, i32* %2
%21 = call i32 @postyn(i32 61, i32 %20, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 (...) @halt()
br label %25
25: ; preds = %23, %19
br label %40
26: ; preds = %3
%27 = load i32, i32* %1
%28 = add nsw i32 %27, 1
%29 = call i32 (...) @data_numplayers()
%30 = add nsw i32 %29, 1
%31 = srem i32 %28, %30
store i32 %31, i32* %1
br label %40
32: ; preds = %3
%33 = load i32, i32* %2
%34 = call i32 @postyn(i32 61, i32 %33, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 (...) @halt()
br label %38
38: ; preds = %36, %32
br label %40
39: ; preds = %3
br label %40
40: ; preds = %39, %38, %26, %25, %16, %13, %10, %7
%41 = load i32, i32* %1
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 (...) @data_numplayers()
%45 = sub nsw i32 %44, 1
store i32 %45, i32* %1
br label %46
46: ; preds = %43, %40
%47 = load i32, i32* %1
%48 = call i32 (...) @data_numplayers()
%49 = srem i32 %47, %48
store i32 %49, i32* %1
br label %3
}

LLVM IR (-O2):
@.str = [31 x i8] c"Are you sure you want to quit?\00"
define void @endgame() {
br label %1
1: ; preds = %34, %0
%2 = phi i32 [ 0, %0 ], [ %37, %34 ]
%3 = tail call i32 @endgame_refresh(i32 %2)
%4 = tail call i32 (...) @io_getkey()
switch i32 %4, label %28 [
i32 2, label %5
i32 3, label %7
i32 1, label %9
i32 0, label %11
i32 4, label %13
i32 9, label %18
i32 113, label %23
]
5: ; preds = %1
%6 = add nsw i32 %2, -1
br label %28
7: ; preds = %1
%8 = add nsw i32 %2, 1
br label %28
9: ; preds = %1
%10 = add nsw i32 %2, 1
br label %28
11: ; preds = %1
%12 = add nsw i32 %2, -1
br label %28
13: ; preds = %1
%14 = tail call i32 @postyn(i32 61, i32 %3, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %28, label %16
16: ; preds = %13
%17 = tail call i32 (...) @halt()
br label %28
18: ; preds = %1
%19 = add nsw i32 %2, 1
%20 = tail call i32 (...) @data_numplayers()
%21 = add nsw i32 %20, 1
%22 = srem i32 %19, %21
br label %28
23: ; preds = %1
%24 = tail call i32 @postyn(i32 61, i32 %3, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = tail call i32 (...) @halt()
br label %28
28: ; preds = %1, %23, %26, %13, %16, %18, %11, %9, %7, %5
%29 = phi i32 [ %2, %1 ], [ %2, %26 ], [ %2, %23 ], [ %22, %18 ], [ %2, %16 ], [ %2, %13 ], [ %12, %11 ], [ %10, %9 ], [ %8, %7 ], [ %6, %5 ]
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = tail call i32 (...) @data_numplayers()
%33 = add nsw i32 %32, -1
br label %34
34: ; preds = %31, %28
%35 = phi i32 [ %33, %31 ], [ %29, %28 ]
%36 = tail call i32 (...) @data_numplayers()
%37 = srem i32 %35, %36
br label %1
}