#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 /*<<< orphan*/ elm_menu(short);
int getch();
int /*<<< orphan*/ system(char *);
short menu(short pos) {
  short choix = pos;
  int c;
  elm_menu(choix);
  while ((c = getch()) != '\r') {
    if (c == 50) {
      (choix == 11) ? (choix = 1) : (choix++);
      system("cls");
      elm_menu(choix);
    } else if (c == 56) {
      (choix == 1) ? (choix = 11) : (choix--);
      system("cls");
      elm_menu(choix);
    } else
      continue;
  }
  return ((short)choix);
}


x86 assembly (clang, -O0):
<menu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    -0x2(%rbp),%ax
mov    %ax,-0x4(%rbp)
movswl -0x4(%rbp),%edi
call   1050 <elm_menu@plt>
mov    $0x0,%al
call   1040 <getch@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xd,%eax
je     120a <menu+0xda>
cmpl   $0x32,-0x8(%rbp)
jne    11af <menu+0x7f>
movswl -0x4(%rbp),%eax
cmp    $0xb,%eax
jne    1185 <menu+0x55>
movw   $0x1,-0x4(%rbp)
jmp    1195 <menu+0x65>
mov    -0x4(%rbp),%ax
mov    %ax,%cx
add    $0x1,%cx
mov    %cx,-0x4(%rbp)
cwtl
lea    0xe64(%rip),%rdi
call   1030 <system@plt>
movswl -0x4(%rbp),%edi
call   1050 <elm_menu@plt>
jmp    1205 <menu+0xd5>
cmpl   $0x38,-0x8(%rbp)
jne    11fb <menu+0xcb>
movswl -0x4(%rbp),%eax
cmp    $0x1,%eax
jne    11d1 <menu+0xa1>
movw   $0xb,-0x4(%rbp)
jmp    11e1 <menu+0xb1>
mov    -0x4(%rbp),%ax
mov    %ax,%cx
add    $0xffff,%cx
mov    %cx,-0x4(%rbp)
cwtl
lea    0xe18(%rip),%rdi
call   1030 <system@plt>
movswl -0x4(%rbp),%edi
call   1050 <elm_menu@plt>
jmp    1200 <menu+0xd0>
jmp    1150 <menu+0x20>
jmp    1205 <menu+0xd5>
jmp    1150 <menu+0x20>
movswl -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<menu>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
lea    0xec3(%rip),%r14
movswl %bx,%edi
call   1050 <elm_menu@plt>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <getch@plt>
cmp    $0xd,%eax
je     11a3 <menu+0x73>
cmp    $0x38,%eax
je     1180 <menu+0x50>
cmp    $0x32,%eax
jne    1150 <menu+0x20>
mov    $0x1,%cx
mov    $0xb,%ax
mov    $0x1,%bp
jmp    118c <menu+0x5c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0xb,%bp
mov    $0xffff,%cx
mov    $0x1,%ax
movswl %cx,%ecx
add    %ebx,%ecx
cmp    %ax,%bx
cmovne %ecx,%ebp
mov    %r14,%rdi
call   1030 <system@plt>
mov    %ebp,%ebx
jmp    113d <menu+0xd>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"cls\00"
define signext i16 @menu(i16 signext %0) {
%2 = alloca i16
%3 = alloca i16
%4 = alloca i32
store i16 %0, i16* %2
%5 = load i16, i16* %2
store i16 %5, i16* %3
%6 = load i16, i16* %3
%7 = call i32 @elm_menu(i16 signext %6)
br label %8
8: ; preds = %47, %45, %1
%9 = call i32 (...) @getch()
store i32 %9, i32* %4
%10 = icmp ne i32 %9, 13
br i1 %10, label %11, label %48
11: ; preds = %8
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 50
br i1 %13, label %14, label %28
14: ; preds = %11
%15 = load i16, i16* %3
%16 = sext i16 %15 to i32
%17 = icmp eq i32 %16, 11
br i1 %17, label %18, label %19
18: ; preds = %14
store i16 1, i16* %3
br label %23
19: ; preds = %14
%20 = load i16, i16* %3
%21 = add i16 %20, 1
store i16 %21, i16* %3
%22 = sext i16 %20 to i32
br label %23
23: ; preds = %19, %18
%24 = phi i32 [ 1, %18 ], [ %22, %19 ]
%25 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%26 = load i16, i16* %3
%27 = call i32 @elm_menu(i16 signext %26)
br label %47
28: ; preds = %11
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 56
br i1 %30, label %31, label %45
31: ; preds = %28
%32 = load i16, i16* %3
%33 = sext i16 %32 to i32
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %36
35: ; preds = %31
store i16 11, i16* %3
br label %40
36: ; preds = %31
%37 = load i16, i16* %3
%38 = add i16 %37, -1
store i16 %38, i16* %3
%39 = sext i16 %37 to i32
br label %40
40: ; preds = %36, %35
%41 = phi i32 [ 11, %35 ], [ %39, %36 ]
%42 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%43 = load i16, i16* %3
%44 = call i32 @elm_menu(i16 signext %43)
br label %46
45: ; preds = %28
br label %8
46: ; preds = %40
br label %47
47: ; preds = %46, %23
br label %8
48: ; preds = %8
%49 = load i16, i16* %3
ret i16 %49
}

LLVM IR (-O2):
@.str = [4 x i8] c"cls\00"
define signext i16 @menu(i16 signext %0) {
br label %2
2: ; preds = %8, %1
%3 = phi i16 [ %14, %8 ], [ %0, %1 ]
%4 = tail call i32 @elm_menu(i16 signext %3)
br label %5
5: ; preds = %2, %5
%6 = tail call i32 (...) @getch()
switch i32 %6, label %5 [
i32 13, label %16
i32 50, label %7
i32 56, label %8
]
7: ; preds = %5
br label %8
8: ; preds = %5, %7
%9 = phi i16 [ 11, %7 ], [ 1, %5 ]
%10 = phi i16 [ 1, %7 ], [ -1, %5 ]
%11 = phi i16 [ 1, %7 ], [ 11, %5 ]
%12 = icmp eq i16 %3, %9
%13 = add i16 %3, %10
%14 = select i1 %12, i16 %11, i16 %13
%15 = tail call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %2
16: ; preds = %5
ret i16 %3
}