#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 apply_settings(int *);
int /*<<< orphan*/ change(int *, int, int);
int io_getkey();
int /*<<< orphan*/ io_printsetup(int, int *);
int setup_routine() {
  int go = 1;
  static int set[7];
  int i, c;
  for (i = 1; i < 4; i++)
    set[i] = 1;
  set[5] = 10;
  set[6] = 0;
  int cursor = 0;
  while (go) {
    io_printsetup(cursor, set);
    switch (c = io_getkey()) {
    case 0:
    case 1:
      change(set, cursor, c);
      break;
    case 2:
      cursor--;
      if (cursor < 0)
        cursor = 6;
      break;
    case 3:
      cursor = (cursor + 1) % 7;
      break;
    case 4:
      go = 0;
      break;
    default:
      break;
    }
  }
  return apply_settings(set);
}


x86 assembly (clang, -O0):
<setup_routine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    1180 <setup_routine+0x40>
movslq -0x8(%rbp),%rcx
lea    0x2ee5(%rip),%rax
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1156 <setup_routine+0x16>
movl   $0xa,0x2eda(%rip)
movl   $0x0,0x2ed4(%rip)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1243 <setup_routine+0x103>
mov    -0x10(%rbp),%edi
lea    0x2ea1(%rip),%rsi
call   1040 <io_printsetup@plt>
xor    %eax,%eax
call   1050 <io_getkey@plt>
mov    %eax,-0xc(%rbp)
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x4,%eax
ja     1239 <setup_routine+0xf9>
mov    -0x18(%rbp),%rax
lea    0xe28(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0x2e62(%rip),%rdi
call   1030 <change@plt>
jmp    123e <setup_routine+0xfe>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1212 <setup_routine+0xd2>
movl   $0x6,-0x10(%rbp)
jmp    123e <setup_routine+0xfe>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
jmp    123e <setup_routine+0xfe>
movl   $0x0,-0x4(%rbp)
jmp    123e <setup_routine+0xfe>
jmp    123e <setup_routine+0xfe>
jmp    119b <setup_routine+0x5b>
lea    0x2e06(%rip),%rdi
call   1060 <apply_settings@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_routine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movabs $0x100000001,%rax
mov    %rax,0x2efc(%rip)
movl   $0x1,0x2efa(%rip)
movq   $0xa,0x2ef7(%rip)
lea    0x2edc(%rip),%r14
lea    0xe85(%rip),%r15
mov    $0x6,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <io_printsetup@plt>
xor    %eax,%eax
call   1050 <io_getkey@plt>
cmp    $0x4,%eax
ja     1190 <setup_routine+0x50>
mov    %eax,%ecx
movslq (%r15,%rcx,4),%rcx
add    %r15,%rcx
jmp    *%rcx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1030 <change@plt>
jmp    1190 <setup_routine+0x50>
test   %ebx,%ebx
lea    -0x1(%rbx),%eax
cmovle %ebp,%eax
mov    %eax,%ebx
jmp    1190 <setup_routine+0x50>
mov    %ebx,%eax
add    $0x1,%eax
cltq
imul   $0xffffffff92492493,%rax,%rax
shr    $0x20,%rax
add    %ebx,%eax
add    $0x1,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x2,%eax
add    %ecx,%eax
lea    0x0(,%rax,8),%ecx
sub    %ecx,%eax
add    %eax,%ebx
add    $0x1,%ebx
jmp    1190 <setup_routine+0x50>
lea    0x2e4d(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <apply_settings@plt>

LLVM IR (-O0):
@setup_routine.set = internal global [7 x i32] zeroinitializer
define i32 @setup_routine() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 1, i32* %1
store i32 1, i32* %2
br label %5
5: ; preds = %12, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 4
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [7 x i32], [7 x i32]* @setup_routine.set, i64 0, i64 %10
store i32 1, i32* %11
br label %12
12: ; preds = %8
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
store i32 %14, i32* %2
br label %5
15: ; preds = %5
store i32 10, i32* getelementptr inbounds ([7 x i32], [7 x i32]* @setup_routine.set, i64 0, i64 5)
store i32 0, i32* getelementptr inbounds ([7 x i32], [7 x i32]* @setup_routine.set, i64 0, i64 6)
store i32 0, i32* %4
br label %16
16: ; preds = %40, %15
%17 = load i32, i32* %1
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %41
19: ; preds = %16
%20 = load i32, i32* %4
%21 = call i32 @io_printsetup(i32 %20, i32* getelementptr inbounds ([7 x i32], [7 x i32]* @setup_routine.set, i64 0, i64 0))
%22 = call i32 (...) @io_getkey()
store i32 %22, i32* %3
switch i32 %22, label %39 [
i32 0, label %23
i32 1, label %23
i32 2, label %27
i32 3, label %34
i32 4, label %38
]
23: ; preds = %19, %19
%24 = load i32, i32* %4
%25 = load i32, i32* %3
%26 = call i32 @change(i32* getelementptr inbounds ([7 x i32], [7 x i32]* @setup_routine.set, i64 0, i64 0), i32 %24, i32 %25)
br label %40
27: ; preds = %19
%28 = load i32, i32* %4
%29 = add nsw i32 %28, -1
store i32 %29, i32* %4
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 6, i32* %4
br label %33
33: ; preds = %32, %27
br label %40
34: ; preds = %19
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
%37 = srem i32 %36, 7
store i32 %37, i32* %4
br label %40
38: ; preds = %19
store i32 0, i32* %1
br label %40
39: ; preds = %19
br label %40
40: ; preds = %39, %38, %34, %33, %23
br label %16
41: ; preds = %16
%42 = call i32 @apply_settings(i32* getelementptr inbounds ([7 x i32], [7 x i32]* @setup_routine.set, i64 0, i64 0))
ret i32 %42
}

LLVM IR (-O2):
@setup_routine.set = internal global [7 x i32] zeroinitializer
define i32 @setup_routine() {
store i32 1, i32* getelementptr inbounds ([7 x i32], [7 x i32]* @setup_routine.set, i64 0, i64 1)
store i32 1, i32* getelementptr inbounds ([7 x i32], [7 x i32]* @setup_routine.set, i64 0, i64 2)
store i32 1, i32* getelementptr inbounds ([7 x i32], [7 x i32]* @setup_routine.set, i64 0, i64 3)
store i32 10, i32* getelementptr inbounds ([7 x i32], [7 x i32]* @setup_routine.set, i64 0, i64 5)
store i32 0, i32* getelementptr inbounds ([7 x i32], [7 x i32]* @setup_routine.set, i64 0, i64 6)
br label %1
1: ; preds = %16, %0
%2 = phi i32 [ 0, %0 ], [ %17, %16 ]
br label %3
3: ; preds = %6, %1
%4 = tail call i32 @io_printsetup(i32 %2, i32* getelementptr inbounds ([7 x i32], [7 x i32]* @setup_routine.set, i64 0, i64 0))
%5 = tail call i32 (...) @io_getkey()
switch i32 %5, label %6 [
i32 0, label %7
i32 1, label %7
i32 2, label %9
i32 3, label %13
i32 4, label %18
]
6: ; preds = %3, %7
br label %3
7: ; preds = %3, %3
%8 = tail call i32 @change(i32* getelementptr inbounds ([7 x i32], [7 x i32]* @setup_routine.set, i64 0, i64 0), i32 %2, i32 %5)
br label %6
9: ; preds = %3
%10 = add nsw i32 %2, -1
%11 = icmp slt i32 %2, 1
%12 = select i1 %11, i32 6, i32 %10
br label %16
13: ; preds = %3
%14 = add nsw i32 %2, 1
%15 = srem i32 %14, 7
br label %16
16: ; preds = %13, %9
%17 = phi i32 [ %12, %9 ], [ %15, %13 ]
br label %1
18: ; preds = %3
%19 = tail call i32 @apply_settings(i32* getelementptr inbounds ([7 x i32], [7 x i32]* @setup_routine.set, i64 0, i64 0))
ret i32 %19
}