#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 */
char getdisppage();
char getnumcols();
char getnumrows();
int /*<<< orphan*/ getpos(char *, char *, char);
int /*<<< orphan*/ gotoxy(char, char, char);
int /*<<< orphan*/ putch(char const, char, char);
int /*<<< orphan*/ scrollup();
void printmenuitem(const char *str, char *attr) {
  char page = getdisppage();
  char row, col;
  int hlite = 0;
  getpos(&row, &col, page);
  while (*str) {
    switch (*str) {
    case '\b':
      --col;
      break;
    case '\n':
      ++row;
      break;
    case '\r':
      col = 0;
      break;
    case 0x07:
      break;
    case '<':
      hlite = 1;
      break;
    case '>':
      hlite = 0;
      break;
    default:
      putch(*str, attr[hlite], page);
      ++col;
    }
    if (col > getnumcols()) {
      ++row;
      col = 0;
    }
    if (row > getnumrows()) {
      scrollup();
      row = getnumrows();
    }
    gotoxy(row, col, page);
    str++;
  }
}


x86 assembly (clang, -O0):
<printmenuitem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getdisppage@plt>
mov    %al,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x12(%rbp),%rdi
lea    -0x13(%rbp),%rsi
movsbl -0x11(%rbp),%edx
call   1060 <getpos@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     12c3 <printmenuitem+0x153>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
add    $0xfffffff9,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x37,%eax
ja     121c <printmenuitem+0xac>
mov    -0x20(%rbp),%rax
lea    0xe2d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x13(%rbp),%al
add    $0xff,%al
mov    %al,-0x13(%rbp)
jmp    1244 <printmenuitem+0xd4>
mov    -0x12(%rbp),%al
add    $0x1,%al
mov    %al,-0x12(%rbp)
jmp    1244 <printmenuitem+0xd4>
movb   $0x0,-0x13(%rbp)
jmp    1244 <printmenuitem+0xd4>
jmp    1244 <printmenuitem+0xd4>
movl   $0x1,-0x18(%rbp)
jmp    1244 <printmenuitem+0xd4>
movl   $0x0,-0x18(%rbp)
jmp    1244 <printmenuitem+0xd4>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rdx
mov    (%rax,%rdx,1),%al
movsbl %cl,%edi
movsbl %al,%esi
movsbl -0x11(%rbp),%edx
call   1090 <putch@plt>
mov    -0x13(%rbp),%al
add    $0x1,%al
mov    %al,-0x13(%rbp)
movsbl -0x13(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1070 <getnumcols@plt>
mov    %al,%cl
mov    -0x24(%rbp),%eax
movsbl %cl,%ecx
cmp    %ecx,%eax
jle    126e <printmenuitem+0xfe>
mov    -0x12(%rbp),%al
add    $0x1,%al
mov    %al,-0x12(%rbp)
movb   $0x0,-0x13(%rbp)
movsbl -0x12(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getnumrows@plt>
mov    %al,%cl
mov    -0x28(%rbp),%eax
movsbl %cl,%ecx
cmp    %ecx,%eax
jle    129d <printmenuitem+0x12d>
mov    $0x0,%al
call   1050 <scrollup@plt>
mov    $0x0,%al
call   1030 <getnumrows@plt>
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%cl
mov    -0x13(%rbp),%al
movsbl %cl,%edi
movsbl %al,%esi
movsbl -0x11(%rbp),%edx
call   1080 <gotoxy@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11a2 <printmenuitem+0x32>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printmenuitem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
mov    %rdi,%rbp
xor    %eax,%eax
call   1040 <getdisppage@plt>
movsbl %al,%r13d
lea    0xf(%rsp),%rdi
lea    0xe(%rsp),%rsi
mov    %r13d,%edx
call   1060 <getpos@plt>
mov    0x0(%rbp),%al
test   %al,%al
je     128c <printmenuitem+0x11c>
add    $0x1,%rbp
lea    0xe47(%rip),%r15
xor    %r12d,%r12d
jmp    11f2 <printmenuitem+0x82>
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <scrollup@plt>
xor    %eax,%eax
call   1030 <getnumrows@plt>
mov    %al,0xf(%rsp)
movsbl 0xe(%rsp),%esi
movsbl %al,%edi
mov    %r13d,%edx
call   1080 <gotoxy@plt>
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
je     128c <printmenuitem+0x11c>
movsbl %al,%edi
lea    -0x7(%rdi),%eax
cmp    $0x37,%eax
ja     120d <printmenuitem+0x9d>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
addb   $0xff,0xe(%rsp)
jmp    1250 <printmenuitem+0xe0>
mov    %r12d,%eax
mov    0x10(%rsp),%rcx
movsbl (%rcx,%rax,1),%esi
mov    %r13d,%edx
call   1090 <putch@plt>
addb   $0x1,0xe(%rsp)
jmp    1250 <printmenuitem+0xe0>
addb   $0x1,0xf(%rsp)
jmp    1250 <printmenuitem+0xe0>
movb   $0x0,0xe(%rsp)
jmp    1250 <printmenuitem+0xe0>
mov    $0x1,%r12d
jmp    1250 <printmenuitem+0xe0>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0xe(%rsp),%r14d
xor    %eax,%eax
call   1070 <getnumcols@plt>
movzbl 0xf(%rsp),%ebx
cmp    %al,%r14b
jle    1273 <printmenuitem+0x103>
add    $0x1,%bl
mov    %bl,0xf(%rsp)
movb   $0x0,0xe(%rsp)
xor    %eax,%eax
call   1030 <getnumrows@plt>
cmp    %al,%bl
jg     11c0 <printmenuitem+0x50>
movzbl 0xf(%rsp),%eax
jmp    11d2 <printmenuitem+0x62>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @printmenuitem(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = call signext i8 (...) @getdisppage()
store i8 %9, i8* %5
store i32 0, i32* %8
%10 = load i8, i8* %5
%11 = call i32 @getpos(i8* %6, i8* %7, i8 signext %10)
br label %12
12: ; preds = %60, %2
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %67
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
switch i32 %19, label %30 [
i32 8, label %20
i32 10, label %23
i32 13, label %26
i32 7, label %27
i32 60, label %28
i32 62, label %29
]
20: ; preds = %16
%21 = load i8, i8* %7
%22 = add i8 %21, -1
store i8 %22, i8* %7
br label %42
23: ; preds = %16
%24 = load i8, i8* %6
%25 = add i8 %24, 1
store i8 %25, i8* %6
br label %42
26: ; preds = %16
store i8 0, i8* %7
br label %42
27: ; preds = %16
br label %42
28: ; preds = %16
store i32 1, i32* %8
br label %42
29: ; preds = %16
store i32 0, i32* %8
br label %42
30: ; preds = %16
%31 = load i8*, i8** %3
%32 = load i8, i8* %31
%33 = load i8*, i8** %4
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = load i8, i8* %5
%39 = call i32 @putch(i8 signext %32, i8 signext %37, i8 signext %38)
%40 = load i8, i8* %7
%41 = add i8 %40, 1
store i8 %41, i8* %7
br label %42
42: ; preds = %30, %29, %28, %27, %26, %23, %20
%43 = load i8, i8* %7
%44 = sext i8 %43 to i32
%45 = call signext i8 (...) @getnumcols()
%46 = sext i8 %45 to i32
%47 = icmp sgt i32 %44, %46
br i1 %47, label %48, label %51
48: ; preds = %42
%49 = load i8, i8* %6
%50 = add i8 %49, 1
store i8 %50, i8* %6
store i8 0, i8* %7
br label %51
51: ; preds = %48, %42
%52 = load i8, i8* %6
%53 = sext i8 %52 to i32
%54 = call signext i8 (...) @getnumrows()
%55 = sext i8 %54 to i32
%56 = icmp sgt i32 %53, %55
br i1 %56, label %57, label %60
57: ; preds = %51
%58 = call i32 (...) @scrollup()
%59 = call signext i8 (...) @getnumrows()
store i8 %59, i8* %6
br label %60
60: ; preds = %57, %51
%61 = load i8, i8* %6
%62 = load i8, i8* %7
%63 = load i8, i8* %5
%64 = call i32 @gotoxy(i8 signext %61, i8 signext %62, i8 signext %63)
%65 = load i8*, i8** %3
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %3
br label %12
67: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @printmenuitem(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca i8
%4 = alloca i8
%5 = tail call signext i8 (...) @getdisppage()
%6 = call i32 @getpos(i8* %3, i8* %4, i8 signext %5)
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %54, label %9
9: ; preds = %2, %47
%10 = phi i8 [ %52, %47 ], [ %7, %2 ]
%11 = phi i32 [ %31, %47 ], [ 0, %2 ]
%12 = phi i8* [ %51, %47 ], [ %0, %2 ]
%13 = sext i8 %10 to i32
switch i32 %13, label %23 [
i32 8, label %14
i32 10, label %17
i32 13, label %20
i32 7, label %30
i32 60, label %21
i32 62, label %22
]
14: ; preds = %9
%15 = load i8, i8* %4
%16 = add i8 %15, -1
store i8 %16, i8* %4
br label %30
17: ; preds = %9
%18 = load i8, i8* %3
%19 = add i8 %18, 1
store i8 %19, i8* %3
br label %30
20: ; preds = %9
store i8 0, i8* %4
br label %30
21: ; preds = %9
br label %30
22: ; preds = %9
br label %30
23: ; preds = %9
%24 = zext i32 %11 to i64
%25 = getelementptr inbounds i8, i8* %1, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @putch(i8 signext %10, i8 signext %26, i8 signext %5)
%28 = load i8, i8* %4
%29 = add i8 %28, 1
store i8 %29, i8* %4
br label %30
30: ; preds = %23, %22, %21, %9, %20, %17, %14
%31 = phi i32 [ %11, %23 ], [ 0, %22 ], [ 1, %21 ], [ %11, %9 ], [ %11, %20 ], [ %11, %17 ], [ %11, %14 ]
%32 = load i8, i8* %4
%33 = call signext i8 (...) @getnumcols()
%34 = icmp sgt i8 %32, %33
%35 = load i8, i8* %3
br i1 %34, label %36, label %38
36: ; preds = %30
%37 = add i8 %35, 1
store i8 %37, i8* %3
store i8 0, i8* %4
br label %38
38: ; preds = %30, %36
%39 = phi i8 [ %37, %36 ], [ %35, %30 ]
%40 = call signext i8 (...) @getnumrows()
%41 = icmp sgt i8 %39, %40
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = load i8, i8* %3
br label %47
44: ; preds = %38
%45 = call i32 (...) @scrollup()
%46 = call signext i8 (...) @getnumrows()
store i8 %46, i8* %3
br label %47
47: ; preds = %42, %44
%48 = phi i8 [ %43, %42 ], [ %46, %44 ]
%49 = load i8, i8* %4
%50 = call i32 @gotoxy(i8 signext %48, i8 signext %49, i8 signext %5)
%51 = getelementptr inbounds i8, i8* %12, i64 1
%52 = load i8, i8* %51
%53 = icmp eq i8 %52, 0
br i1 %53, label %54, label %9
54: ; preds = %47, %2
ret void
}