#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*/ io_printborder(int, int /*<<< orphan*/, int);
int io_printtext(int, int, int, char *);
int postoptions(int x, int y) {
  int width = 28;
  int yorig = y;
  int cursor = 0;
  char *a = "Buy Sell Wonder   Cancel";
  char *b = " *";
  char *c = "     *";
  char *d = "           *";
  char *e = "                    *";
  while (1) {
    y = yorig;
    io_printborder(x, y++, width);
    y = io_printtext(x, y, width, a);
    if (cursor == 0)
      y = io_printtext(x, y, width, b);
    if (cursor == 1)
      y = io_printtext(x, y, width, c);
    if (cursor == 2)
      y = io_printtext(x, y, width, d);
    if (cursor == 3)
      y = io_printtext(x, y, width, e);
    io_printborder(x, y++, width);
    switch (io_getkey()) {
    case 0:
      cursor--;
      break;
    case 1:
      cursor++;
      break;
    case 4:
      return cursor;
      break;
    default:
      break;
    }
    if (cursor < 0)
      cursor = 3;
    cursor = cursor % 4;
  }
}


x86 assembly (clang, -O0):
<postoptions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x1c,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xea7(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xec8(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xeb9(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xea8(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe94(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edx
call   1040 <io_printborder@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1030 <io_printtext@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11d9 <postoptions+0xa9>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x28(%rbp),%rcx
call   1030 <io_printtext@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    11f8 <postoptions+0xc8>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x30(%rbp),%rcx
call   1030 <io_printtext@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x2,-0x14(%rbp)
jne    1217 <postoptions+0xe7>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   1030 <io_printtext@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x3,-0x14(%rbp)
jne    1236 <postoptions+0x106>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x40(%rbp),%rcx
call   1030 <io_printtext@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edx
call   1040 <io_printborder@plt>
xor    %eax,%eax
call   1050 <io_getkey@plt>
mov    %eax,%ecx
mov    %ecx,-0x44(%rbp)
test   %eax,%eax
je     1287 <postoptions+0x157>
jmp    1265 <postoptions+0x135>
mov    -0x44(%rbp),%eax
sub    $0x1,%eax
je     1295 <postoptions+0x165>
jmp    1276 <postoptions+0x146>
mov    -0x44(%rbp),%eax
sub    $0x4,%eax
je     12a3 <postoptions+0x173>
jmp    12ac <postoptions+0x17c>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    12b1 <postoptions+0x181>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12b1 <postoptions+0x181>
mov    -0x14(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret
jmp    12b1 <postoptions+0x181>
cmpl   $0x0,-0x14(%rbp)
jge    12c2 <postoptions+0x192>
movl   $0x3,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
jmp    1189 <postoptions+0x59>

x86 assembly (clang, -O2):
<postoptions>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebp
lea    0x1(%r14),%r12d
lea    0xeb5(%rip),%r15
lea    0xede(%rip),%r13
xor    %ebx,%ebx
jmp    116d <postoptions+0x3d>
cs nopw 0x0(%rax,%rax,1)
lea    0x3(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xfffffffc,%eax
sub    %eax,%ebx
mov    %ebp,%edi
mov    %r14d,%esi
mov    $0x1c,%edx
call   1040 <io_printborder@plt>
mov    %ebp,%edi
mov    %r12d,%esi
mov    $0x1c,%edx
mov    %r15,%rcx
call   1030 <io_printtext@plt>
cmp    $0x3,%ebx
ja     11ac <postoptions+0x7c>
movslq %ebx,%rcx
movslq 0x0(%r13,%rcx,4),%rcx
add    %r13,%rcx
mov    %ebp,%edi
mov    %eax,%esi
mov    $0x1c,%edx
call   1030 <io_printtext@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    $0x1c,%edx
call   1040 <io_printborder@plt>
xor    %eax,%eax
call   1050 <io_getkey@plt>
test   %eax,%eax
je     11e0 <postoptions+0xb0>
cmp    $0x1,%eax
je     11f0 <postoptions+0xc0>
cmp    $0x4,%eax
jne    11e3 <postoptions+0xb3>
jmp    1205 <postoptions+0xd5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
test   %ebx,%ebx
jns    1160 <postoptions+0x30>
jmp    11fb <postoptions+0xcb>
nopl   (%rax)
add    $0x1,%ebx
test   %ebx,%ebx
jns    1160 <postoptions+0x30>
mov    $0x3,%ebx
jmp    116d <postoptions+0x3d>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [25 x i8] c"Buy Sell Wonder Cancel\00"
@.str.1 = [3 x i8] c" *\00"
@.str.2 = [7 x i8] c" *\00"
@.str.3 = [13 x i8] c" *\00"
@.str.4 = [22 x i8] c" *\00"
@reltable.postoptions = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.postoptions to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.postoptions to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.postoptions to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 x i8]* @.str.4 to i64), i64 ptrtoint ([4 x i32]* @reltable.postoptions to i64)) to i32)]
define i32 @postoptions(i32 %0, i32 %1) {
%3 = add nsw i32 %1, 1
br label %4
4: ; preds = %23, %2
%5 = phi i32 [ 0, %2 ], [ %27, %23 ]
%6 = tail call i32 @io_printborder(i32 %0, i32 %1, i32 28)
%7 = tail call i32 @io_printtext(i32 %0, i32 %3, i32 28, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = icmp ult i32 %5, 4
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = sext i32 %5 to i64
%11 = shl i64 %10, 2
%12 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.postoptions to i8*), i64 %11)
%13 = tail call i32 @io_printtext(i32 %0, i32 %7, i32 28, i8* %12)
br label %14
14: ; preds = %4, %9
%15 = phi i32 [ %7, %4 ], [ %13, %9 ]
%16 = tail call i32 @io_printborder(i32 %0, i32 %15, i32 28)
%17 = tail call i32 (...) @io_getkey()
switch i32 %17, label %23 [
i32 0, label %18
i32 1, label %20
i32 4, label %22
]
18: ; preds = %14
%19 = add nsw i32 %5, -1
br label %23
20: ; preds = %14
%21 = add nsw i32 %5, 1
br label %23
22: ; preds = %14
ret i32 %5
23: ; preds = %14, %20, %18
%24 = phi i32 [ %5, %14 ], [ %21, %20 ], [ %19, %18 ]
%25 = icmp slt i32 %24, 0
%26 = srem i32 %24, 4
%27 = select i1 %25, i32 3, i32 %26
br label %4
}