#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 COLS;
int KEY_DOWN;
int KEY_RESIZE;
int KEY_UP;
int /*<<< orphan*/ clear();
int getch();
int /*<<< orphan*/ mvprintw(int, int, char *);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ show_menu_options(char *, char **, int);
int strlen(char *);
char *show_menu(char *title, char *options[], int num_options) {
  int i, xpos = 0, xlef = 0, xri = 0, cursor_position = 0, c = 0;
  clear();
  show_menu_options(title, options, num_options);
  do {
    if (xlef > 0) {
      mvprintw(cursor_position + 5, xlef, " ");
      mvprintw(cursor_position + 5, xri, " ");
    }
    if (c == KEY_DOWN) {
      cursor_position++;
    } else if (c == KEY_UP) {
      cursor_position--;
    } else if (c == KEY_RESIZE) {
      clear();
      show_menu_options(title, options, num_options);
    }
    if (cursor_position >= num_options) {
      cursor_position = 0;
    } else if (cursor_position < 0) {
      cursor_position = num_options - 1;
    }
    xpos = (COLS - strlen(options[cursor_position])) / 2;
    xlef = xpos - 2;
    xri = xpos + strlen(options[cursor_position]) + 1;
    mvprintw(cursor_position + 5, xlef, ">");
    mvprintw(cursor_position + 5, xri, "<");
    refresh();
  } while ((c = getch()) != '\n' && c != ' ');
  return options[cursor_position];
}


x86 assembly (clang, -O0):
<show_menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    $0x0,%al
call   1060 <clear@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1080 <show_menu_options@plt>
cmpl   $0x0,-0x20(%rbp)
jle    11e1 <show_menu+0x81>
mov    -0x28(%rbp),%edi
add    $0x5,%edi
mov    -0x20(%rbp),%esi
lea    0xe39(%rip),%rdx
call   1070 <mvprintw@plt>
mov    -0x28(%rbp),%edi
add    $0x5,%edi
mov    -0x24(%rbp),%esi
lea    0xe24(%rip),%rdx
call   1070 <mvprintw@plt>
mov    -0x2c(%rbp),%eax
mov    0x2df5(%rip),%rcx
cmp    (%rcx),%eax
jne    1201 <show_menu+0xa1>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1254 <show_menu+0xf4>
mov    -0x2c(%rbp),%eax
mov    0x2dcd(%rip),%rcx
cmp    (%rcx),%eax
jne    1221 <show_menu+0xc1>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    124f <show_menu+0xef>
mov    -0x2c(%rbp),%eax
mov    0x2dc5(%rip),%rcx
cmp    (%rcx),%eax
jne    124a <show_menu+0xea>
mov    $0x0,%al
call   1060 <clear@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1080 <show_menu_options@plt>
jmp    124f <show_menu+0xef>
jmp    1254 <show_menu+0xf4>
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     126c <show_menu+0x10c>
movl   $0x0,-0x28(%rbp)
jmp    1284 <show_menu+0x124>
cmpl   $0x0,-0x28(%rbp)
jge    127f <show_menu+0x11f>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1284 <show_menu+0x124>
mov    0x2d45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
sub    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
add    $0x5,%edi
mov    -0x20(%rbp),%esi
lea    0xd12(%rip),%rdx
call   1070 <mvprintw@plt>
mov    -0x28(%rbp),%edi
add    $0x5,%edi
mov    -0x24(%rbp),%esi
lea    0xcff(%rip),%rdx
call   1070 <mvprintw@plt>
mov    $0x0,%al
call   1040 <refresh@plt>
mov    $0x0,%al
call   1050 <getch@plt>
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x35(%rbp)
je     1335 <show_menu+0x1d5>
cmpl   $0x20,-0x2c(%rbp)
setne  %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    11ad <show_menu+0x4d>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_menu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <clear@plt>
mov    %rbx,0x20(%rsp)
mov    %rbx,%rdi
mov    %r14,0x8(%rsp)
mov    %r14,%rsi
mov    %ebp,%edx
call   1080 <show_menu_options@plt>
mov    %rbp,%rax
mov    %rbp,0x18(%rsp)
lea    -0x1(%rbp),%eax
mov    %eax,0x14(%rsp)
xor    %r15d,%r15d
xor    %r13d,%r13d
xor    %r14d,%r14d
xor    %ebp,%ebp
xchg   %ax,%ax
test   %r15d,%r15d
jle    11dc <show_menu+0x7c>
lea    0x5(%r14),%r12d
mov    %r12d,%edi
mov    %r15d,%esi
lea    0xe3a(%rip),%rbx
mov    %rbx,%rdx
call   1070 <mvprintw@plt>
mov    %r12d,%edi
mov    %r13d,%esi
mov    %rbx,%rdx
call   1070 <mvprintw@plt>
mov    0x2dfd(%rip),%rax
cmp    (%rax),%ebp
jne    11f0 <show_menu+0x90>
add    $0x1,%r14d
jmp    1240 <show_menu+0xe0>
nopl   (%rax)
mov    0x2de1(%rip),%rax
cmp    (%rax),%ebp
jne    1210 <show_menu+0xb0>
add    $0xffffffff,%r14d
jmp    1240 <show_menu+0xe0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2dd9(%rip),%rax
cmp    (%rax),%ebp
jne    1240 <show_menu+0xe0>
xor    %eax,%eax
call   1060 <clear@plt>
mov    0x20(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    0x18(%rsp),%rdx
call   1080 <show_menu_options@plt>
cs nopw 0x0(%rax,%rax,1)
test   %r14d,%r14d
mov    %r14d,%eax
cmovs  0x14(%rsp),%eax
cmp    0x18(%rsp),%r14d
mov    %eax,%r14d
mov    $0x0,%eax
cmovge %eax,%r14d
mov    0x2d6d(%rip),%rax
mov    (%rax),%ebp
movslq %r14d,%r12
mov    0x8(%rsp),%r13
mov    0x0(%r13,%r12,8),%rdi
call   1030 <strlen@plt>
sub    %eax,%ebp
mov    %ebp,%ebx
shr    $0x1f,%ebx
add    %ebp,%ebx
sar    %ebx
lea    -0x2(%rbx),%r15d
mov    0x0(%r13,%r12,8),%rdi
call   1030 <strlen@plt>
lea    (%rax,%rbx,1),%r13d
add    $0x1,%r13d
lea    0x5(%r12),%ebp
mov    %ebp,%edi
mov    %r15d,%esi
lea    0xd59(%rip),%rdx
call   1070 <mvprintw@plt>
mov    %ebp,%edi
mov    %r13d,%esi
lea    0xd4a(%rip),%rdx
call   1070 <mvprintw@plt>
xor    %eax,%eax
call   1040 <refresh@plt>
xor    %eax,%eax
call   1050 <getch@plt>
cmp    $0x20,%eax
je     12dd <show_menu+0x17d>
mov    %eax,%ebp
cmp    $0xa,%eax
jne    11b0 <show_menu+0x50>
mov    0x8(%rsp),%rax
mov    (%rax,%r12,8),%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@KEY_DOWN = global i32 0
@KEY_UP = global i32 0
@KEY_RESIZE = global i32 0
@COLS = global i32 0
@.str.1 = [2 x i8] c">\00"
@.str.2 = [2 x i8] c"<\00"
define i8* @show_menu(i8* %0, i8** %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
%13 = call i32 (...) @clear()
%14 = load i8*, i8** %4
%15 = load i8**, i8*** %5
%16 = load i32, i32* %6
%17 = call i32 @show_menu_options(i8* %14, i8** %15, i32 %16)
br label %18
18: ; preds = %104, %3
%19 = load i32, i32* %9
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %18
%22 = load i32, i32* %11
%23 = add nsw i32 %22, 5
%24 = load i32, i32* %9
%25 = call i32 @mvprintw(i32 %23, i32 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* %11
%27 = add nsw i32 %26, 5
%28 = load i32, i32* %10
%29 = call i32 @mvprintw(i32 %27, i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %21, %18
%31 = load i32, i32* %12
%32 = load i32, i32* @KEY_DOWN
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 1
store i32 %36, i32* %11
br label %56
37: ; preds = %30
%38 = load i32, i32* %12
%39 = load i32, i32* @KEY_UP
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* %11
%43 = add nsw i32 %42, -1
store i32 %43, i32* %11
br label %55
44: ; preds = %37
%45 = load i32, i32* %12
%46 = load i32, i32* @KEY_RESIZE
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %54
48: ; preds = %44
%49 = call i32 (...) @clear()
%50 = load i8*, i8** %4
%51 = load i8**, i8*** %5
%52 = load i32, i32* %6
%53 = call i32 @show_menu_options(i8* %50, i8** %51, i32 %52)
br label %54
54: ; preds = %48, %44
br label %55
55: ; preds = %54, %41
br label %56
56: ; preds = %55, %34
%57 = load i32, i32* %11
%58 = load i32, i32* %6
%59 = icmp sge i32 %57, %58
br i1 %59, label %60, label %61
60: ; preds = %56
store i32 0, i32* %11
br label %68
61: ; preds = %56
%62 = load i32, i32* %11
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32, i32* %6
%66 = sub nsw i32 %65, 1
store i32 %66, i32* %11
br label %67
67: ; preds = %64, %61
br label %68
68: ; preds = %67, %60
%69 = load i32, i32* @COLS
%70 = load i8**, i8*** %5
%71 = load i32, i32* %11
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8*, i8** %70, i64 %72
%74 = load i8*, i8** %73
%75 = call i32 @strlen(i8* %74)
%76 = sub nsw i32 %69, %75
%77 = sdiv i32 %76, 2
store i32 %77, i32* %8
%78 = load i32, i32* %8
%79 = sub nsw i32 %78, 2
store i32 %79, i32* %9
%80 = load i32, i32* %8
%81 = load i8**, i8*** %5
%82 = load i32, i32* %11
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8*, i8** %81, i64 %83
%85 = load i8*, i8** %84
%86 = call i32 @strlen(i8* %85)
%87 = add nsw i32 %80, %86
%88 = add nsw i32 %87, 1
store i32 %88, i32* %10
%89 = load i32, i32* %11
%90 = add nsw i32 %89, 5
%91 = load i32, i32* %9
%92 = call i32 @mvprintw(i32 %90, i32 %91, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%93 = load i32, i32* %11
%94 = add nsw i32 %93, 5
%95 = load i32, i32* %10
%96 = call i32 @mvprintw(i32 %94, i32 %95, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%97 = call i32 (...) @refresh()
br label %98
98: ; preds = %68
%99 = call i32 (...) @getch()
store i32 %99, i32* %12
%100 = icmp ne i32 %99, 10
br i1 %100, label %101, label %104
101: ; preds = %98
%102 = load i32, i32* %12
%103 = icmp ne i32 %102, 32
br label %104
104: ; preds = %101, %98
%105 = phi i1 [ false, %98 ], [ %103, %101 ]
br i1 %105, label %18, label %106
106: ; preds = %104
%107 = load i8**, i8*** %5
%108 = load i32, i32* %11
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i8*, i8** %107, i64 %109
%111 = load i8*, i8** %110
ret i8* %111
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@KEY_DOWN = global i32 0
@KEY_UP = global i32 0
@KEY_RESIZE = global i32 0
@COLS = global i32 0
@.str.1 = [2 x i8] c">\00"
@.str.2 = [2 x i8] c"<\00"
define i8* @show_menu(i8* %0, i8** %1, i32 %2) {
%4 = tail call i32 (...) @clear()
%5 = tail call i32 @show_menu_options(i8* %0, i8** %1, i32 %2)
%6 = add nsw i32 %2, -1
br label %7
7: ; preds = %33, %3
%8 = phi i32 [ 0, %3 ], [ %46, %33 ]
%9 = phi i32 [ 0, %3 ], [ %50, %33 ]
%10 = phi i32 [ 0, %3 ], [ %38, %33 ]
%11 = phi i32 [ 0, %3 ], [ %55, %33 ]
%12 = icmp sgt i32 %8, 0
br i1 %12, label %13, label %17
13: ; preds = %7
%14 = add nsw i32 %10, 5
%15 = tail call i32 @mvprintw(i32 %14, i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @mvprintw(i32 %14, i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %13, %7
%18 = load i32, i32* @KEY_DOWN
%19 = icmp eq i32 %11, %18
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = add nsw i32 %10, 1
br label %33
22: ; preds = %17
%23 = load i32, i32* @KEY_UP
%24 = icmp eq i32 %11, %23
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = add nsw i32 %10, -1
br label %33
27: ; preds = %22
%28 = load i32, i32* @KEY_RESIZE
%29 = icmp eq i32 %11, %28
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = tail call i32 (...) @clear()
%32 = tail call i32 @show_menu_options(i8* %0, i8** %1, i32 %2)
br label %33
33: ; preds = %25, %30, %27, %20
%34 = phi i32 [ %21, %20 ], [ %26, %25 ], [ %10, %30 ], [ %10, %27 ]
%35 = icmp slt i32 %34, %2
%36 = icmp slt i32 %34, 0
%37 = select i1 %36, i32 %6, i32 %34
%38 = select i1 %35, i32 %37, i32 0
%39 = load i32, i32* @COLS
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds i8*, i8** %1, i64 %40
%42 = load i8*, i8** %41
%43 = tail call i32 @strlen(i8* %42)
%44 = sub nsw i32 %39, %43
%45 = sdiv i32 %44, 2
%46 = add nsw i32 %45, -2
%47 = load i8*, i8** %41
%48 = tail call i32 @strlen(i8* %47)
%49 = add i32 %48, 1
%50 = add i32 %49, %45
%51 = add nsw i32 %38, 5
%52 = tail call i32 @mvprintw(i32 %51, i32 %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%53 = tail call i32 @mvprintw(i32 %51, i32 %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%54 = tail call i32 (...) @refresh()
%55 = tail call i32 (...) @getch()
switch i32 %55, label %7 [
i32 32, label %56
i32 10, label %56
]
56: ; preds = %33, %33
%57 = getelementptr inbounds i8*, i8** %1, i64 %40
%58 = load i8*, i8** %57
ret i8* %58
}