#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 io_getkey();
int /*<<< orphan*/ pregame_refresh(int *, int);
int *pregame() {
  static int ret[8] = {0, 1, 1, 1, 1, 1, 1, 1};
  ret[7] = 3;
  int cursor = 0;
  int pregaming = 1;
  while (pregaming) {
    pregame_refresh(ret, cursor);
    switch (io_getkey()) {
    case 2:
      cursor--;
      if (cursor < 0)
        cursor = ret[7] + 1;
      break;
    case 3:
      cursor = (cursor + 1) % (ret[7] + 2);
      break;
    case 1:
    case 4:
      if (cursor == 0) {
        ret[7]++;
        if (ret[7] > 7)
          ret[7] = 3;
      } else if (cursor == ret[7] + 1) {
        pregaming = 0;
      } else {
        ret[cursor - 1] = !ret[cursor - 1];
      }
      break;
    case 0:
      if (cursor == 0) {
        ret[7]--;
        if (ret[7] < 3)
          ret[7] = 7;
      } else if (cursor == ret[7] + 1) {
      } else {
        ret[cursor - 1] = !ret[cursor - 1];
      }
      break;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<pregame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x3,0x2f2a(%rip)
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     12df <pregame+0x1bf>
mov    -0x4(%rbp),%esi
lea    0x2eec(%rip),%rdi
call   1040 <pregame_refresh@plt>
xor    %eax,%eax
call   1030 <io_getkey@plt>
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x4,%eax
ja     12da <pregame+0x1ba>
mov    -0x10(%rbp),%rax
lea    0xe86(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11a2 <pregame+0x82>
mov    0x2ec0(%rip),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    12da <pregame+0x1ba>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    0x2ea9(%rip),%ecx
add    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
jmp    12da <pregame+0x1ba>
cmpl   $0x0,-0x4(%rbp)
jne    11f6 <pregame+0xd6>
mov    0x2e8b(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e82(%rip)
cmpl   $0x7,0x2e7b(%rip)
jle    11f1 <pregame+0xd1>
movl   $0x3,0x2e6b(%rip)
jmp    124c <pregame+0x12c>
mov    -0x4(%rbp),%eax
mov    0x2e5d(%rip),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    1216 <pregame+0xf6>
movl   $0x0,-0x8(%rbp)
jmp    1247 <pregame+0x127>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e1a(%rip),%rax
cmpl   $0x0,(%rax,%rcx,4)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edx
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2dfc(%rip),%rax
mov    %edx,(%rax,%rcx,4)
jmp    124c <pregame+0x12c>
jmp    12da <pregame+0x1ba>
cmpl   $0x0,-0x4(%rbp)
jne    1286 <pregame+0x166>
mov    0x2dfb(%rip),%eax
add    $0xffffffff,%eax
mov    %eax,0x2df2(%rip)
cmpl   $0x3,0x2deb(%rip)
jge    1281 <pregame+0x161>
movl   $0x7,0x2ddb(%rip)
jmp    12d5 <pregame+0x1b5>
mov    -0x4(%rbp),%eax
mov    0x2dcd(%rip),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    129f <pregame+0x17f>
jmp    12d0 <pregame+0x1b0>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2d91(%rip),%rax
cmpl   $0x0,(%rax,%rcx,4)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edx
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2d73(%rip),%rax
mov    %edx,(%rax,%rcx,4)
jmp    12d5 <pregame+0x1b5>
jmp    12da <pregame+0x1ba>
jmp    1140 <pregame+0x20>
lea    0x2d5a(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pregame>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
movl   $0x3,0x2f2a(%rip)
lea    0x2f07(%rip),%r14
lea    0xec0(%rip),%r15
mov    $0x7,%r12d
mov    $0x3,%ebp
jmp    115c <pregame+0x3c>
nopl   (%rax)
cmp    $0x7,%ecx
cmovge %ebp,%eax
mov    %eax,0x2f00(%rip)
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <pregame_refresh@plt>
xor    %eax,%eax
call   1030 <io_getkey@plt>
cmp    $0x4,%eax
ja     1160 <pregame+0x40>
mov    %eax,%eax
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    0x2ed5(%rip),%ecx
lea    0x1(%rcx),%eax
test   %ebx,%ebx
je     1150 <pregame+0x30>
cmp    %eax,%ebx
jne    11a5 <pregame+0x85>
jmp    1205 <pregame+0xe5>
mov    0x2ec2(%rip),%eax
test   %ebx,%ebx
je     11f0 <pregame+0xd0>
add    $0x1,%eax
cmp    %eax,%ebx
je     1160 <pregame+0x40>
movslq %ebx,%rax
xor    %ecx,%ecx
cmpl   $0x0,-0x4(%r14,%rax,4)
sete   %cl
mov    %ecx,-0x4(%r14,%rax,4)
jmp    1160 <pregame+0x40>
lea    -0x1(%rbx),%eax
test   %ebx,%ebx
mov    %eax,%ebx
jg     1160 <pregame+0x40>
mov    0x2e93(%rip),%ebx
add    $0x1,%ebx
jmp    1160 <pregame+0x40>
add    $0x1,%ebx
mov    0x2e85(%rip),%ecx
add    $0x2,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %edx,%ebx
jmp    1160 <pregame+0x40>
cs nopw 0x0(%rax,%rax,1)
lea    -0x1(%rax),%ecx
cmp    $0x4,%eax
cmovl  %r12d,%ecx
mov    %ecx,0x2e5c(%rip)
jmp    115c <pregame+0x3c>
lea    0x2e34(%rip),%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@pregame.ret = internal global [8 x i32] [i32 0, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1]
define i32* @pregame() {
%1 = alloca i32
%2 = alloca i32
store i32 3, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
store i32 0, i32* %1
store i32 1, i32* %2
br label %3
3: ; preds = %87, %0
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %88
6: ; preds = %3
%7 = load i32, i32* %1
%8 = call i32 @pregame_refresh(i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 0), i32 %7)
%9 = call i32 (...) @io_getkey()
switch i32 %9, label %87 [
i32 2, label %10
i32 3, label %19
i32 1, label %25
i32 4, label %25
i32 0, label %56
]
10: ; preds = %6
%11 = load i32, i32* %1
%12 = add nsw i32 %11, -1
store i32 %12, i32* %1
%13 = load i32, i32* %1
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
%17 = add nsw i32 %16, 1
store i32 %17, i32* %1
br label %18
18: ; preds = %15, %10
br label %87
19: ; preds = %6
%20 = load i32, i32* %1
%21 = add nsw i32 %20, 1
%22 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
%23 = add nsw i32 %22, 2
%24 = srem i32 %21, %23
store i32 %24, i32* %1
br label %87
25: ; preds = %6, %6
%26 = load i32, i32* %1
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
%30 = add nsw i32 %29, 1
store i32 %30, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
%31 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
%32 = icmp sgt i32 %31, 7
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 3, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
br label %34
34: ; preds = %33, %28
br label %55
35: ; preds = %25
%36 = load i32, i32* %1
%37 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
%38 = add nsw i32 %37, 1
%39 = icmp eq i32 %36, %38
br i1 %39, label %40, label %41
40: ; preds = %35
store i32 0, i32* %2
br label %54
41: ; preds = %35
%42 = load i32, i32* %1
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = icmp ne i32 %46, 0
%48 = xor i1 %47, true
%49 = zext i1 %48 to i32
%50 = load i32, i32* %1
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 %52
store i32 %49, i32* %53
br label %54
54: ; preds = %41, %40
br label %55
55: ; preds = %54, %34
br label %87
56: ; preds = %6
%57 = load i32, i32* %1
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %66
59: ; preds = %56
%60 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
%61 = add nsw i32 %60, -1
store i32 %61, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
%62 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
%63 = icmp slt i32 %62, 3
br i1 %63, label %64, label %65
64: ; preds = %59
store i32 7, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
br label %65
65: ; preds = %64, %59
br label %86
66: ; preds = %56
%67 = load i32, i32* %1
%68 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
%69 = add nsw i32 %68, 1
%70 = icmp eq i32 %67, %69
br i1 %70, label %71, label %72
71: ; preds = %66
br label %85
72: ; preds = %66
%73 = load i32, i32* %1
%74 = sub nsw i32 %73, 1
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 %75
%77 = load i32, i32* %76
%78 = icmp ne i32 %77, 0
%79 = xor i1 %78, true
%80 = zext i1 %79 to i32
%81 = load i32, i32* %1
%82 = sub nsw i32 %81, 1
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 %83
store i32 %80, i32* %84
br label %85
85: ; preds = %72, %71
br label %86
86: ; preds = %85, %65
br label %87
87: ; preds = %6, %86, %55, %19, %18
br label %3
88: ; preds = %3
ret i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 0)
}

LLVM IR (-O2):
@pregame.ret = internal global [8 x i32] [i32 0, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1]
define i32* @pregame() {
store i32 3, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
br label %1
1: ; preds = %39, %0
%2 = phi i32 [ 0, %0 ], [ %40, %39 ]
%3 = tail call i32 @pregame_refresh(i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 0), i32 %2)
%4 = tail call i32 (...) @io_getkey()
switch i32 %4, label %39 [
i32 2, label %5
i32 3, label %11
i32 1, label %16
i32 4, label %16
i32 0, label %32
]
5: ; preds = %1
%6 = add nsw i32 %2, -1
%7 = icmp slt i32 %2, 1
br i1 %7, label %8, label %39
8: ; preds = %5
%9 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
%10 = add nsw i32 %9, 1
br label %39
11: ; preds = %1
%12 = add nsw i32 %2, 1
%13 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
%14 = add nsw i32 %13, 2
%15 = srem i32 %12, %14
br label %39
16: ; preds = %1, %1
%17 = icmp eq i32 %2, 0
%18 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
%19 = add nsw i32 %18, 1
br i1 %17, label %20, label %23
20: ; preds = %16
%21 = icmp sgt i32 %18, 6
%22 = select i1 %21, i32 3, i32 %19
store i32 %22, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
br label %39
23: ; preds = %16
%24 = icmp eq i32 %2, %19
br i1 %24, label %51, label %25
25: ; preds = %23
%26 = add nsw i32 %2, -1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 0
%31 = zext i1 %30 to i32
store i32 %31, i32* %28
br label %39
32: ; preds = %1
%33 = icmp eq i32 %2, 0
%34 = load i32, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
br i1 %33, label %35, label %41
35: ; preds = %32
%36 = add nsw i32 %34, -1
%37 = icmp slt i32 %34, 4
%38 = select i1 %37, i32 7, i32 %36
store i32 %38, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 7)
br label %39
39: ; preds = %35, %41, %44, %20, %25, %5, %8, %1, %11
%40 = phi i32 [ %2, %1 ], [ 0, %35 ], [ %2, %41 ], [ %2, %44 ], [ 0, %20 ], [ %2, %25 ], [ %15, %11 ], [ %10, %8 ], [ %6, %5 ]
br label %1
41: ; preds = %32
%42 = add nsw i32 %34, 1
%43 = icmp eq i32 %2, %42
br i1 %43, label %39, label %44
44: ; preds = %41
%45 = add nsw i32 %2, -1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = icmp eq i32 %48, 0
%50 = zext i1 %49 to i32
store i32 %50, i32* %47
br label %39
51: ; preds = %23
ret i32* getelementptr inbounds ([8 x i32], [8 x i32]* @pregame.ret, i64 0, i64 0)
}