#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 */
typedef int /*<<< orphan*/ WINDOW;

/* Variables and functions */
int /*<<< orphan*/ A_BOLD;
int /*<<< orphan*/ A_REVERSE;
int FALSE;
int TRUE;
int /*<<< orphan*/ waddch(int /*<<< orphan*/ *, char const);
int /*<<< orphan*/ wattroff(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ wattron(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ wmove(int /*<<< orphan*/ *, int, int);
void menu_write_item(WINDOW *win, int xpos, int reverse, const char st[]) {
  int cnt;
  int high = FALSE;
  if (reverse)
    wattron(win, A_REVERSE);
  wmove(win, 1, xpos + 1);
  for (cnt = 0; st[cnt] != 0; cnt++) {
    if (st[cnt] == '~') {
      if (!reverse) {
        wattron(win, A_BOLD);
        high = TRUE;
      }
    } else {
      waddch(win, st[cnt]);
      if (high) {
        high = FALSE;
        wattroff(win, A_BOLD);
      }
    }
  }
  if (reverse)
    wattroff(win, A_REVERSE);
}


x86 assembly (clang, -O0):
<menu_write_item>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     117e <menu_write_item+0x3e>
mov    -0x8(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
call   1050 <wattron@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
mov    $0x1,%esi
call   1060 <wmove@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1245 <menu_write_item+0x105>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jne    11f0 <menu_write_item+0xb0>
cmpl   $0x0,-0x10(%rbp)
jne    11eb <menu_write_item+0xab>
mov    -0x8(%rbp),%rdi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
call   1050 <wattron@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    1232 <menu_write_item+0xf2>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1030 <waddch@plt>
cmpl   $0x0,-0x20(%rbp)
je     122d <menu_write_item+0xed>
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
call   1040 <wattroff@plt>
jmp    1232 <menu_write_item+0xf2>
jmp    1237 <menu_write_item+0xf7>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1199 <menu_write_item+0x59>
cmpl   $0x0,-0x10(%rbp)
je     1261 <menu_write_item+0x121>
mov    -0x8(%rbp),%rdi
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
call   1040 <wattroff@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<menu_write_item>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbp
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%r13
mov    0x2e72(%rip),%r12
mov    (%r12),%ebx
test   %edx,%edx
je     1177 <menu_write_item+0x37>
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1050 <wattron@plt>
add    $0x1,%r15d
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
call   1060 <wmove@plt>
mov    0x2e36(%rip),%r15
jmp    11b3 <menu_write_item+0x73>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12),%ebx
mov    (%r15),%esi
mov    %r13,%rdi
call   1040 <wattroff@plt>
add    $0x1,%rbp
movzbl 0x0(%rbp),%eax
cmp    $0x7e,%al
je     11e0 <menu_write_item+0xa0>
test   %al,%al
je     11ff <menu_write_item+0xbf>
movsbl %al,%esi
mov    %r13,%rdi
call   1030 <waddch@plt>
test   %ebx,%ebx
jne    11a0 <menu_write_item+0x60>
xor    %ebx,%ebx
add    $0x1,%rbp
jmp    11b3 <menu_write_item+0x73>
cs nopw 0x0(%rax,%rax,1)
test   %r14d,%r14d
jne    11af <menu_write_item+0x6f>
mov    (%r15),%esi
mov    %r13,%rdi
call   1050 <wattron@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%ebx
add    $0x1,%rbp
jmp    11b3 <menu_write_item+0x73>
test   %r14d,%r14d
je     1223 <menu_write_item+0xe3>
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <wattroff@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@FALSE = global i32 0
@A_REVERSE = global i32 0
@A_BOLD = global i32 0
@TRUE = global i32 0
define void @menu_write_item(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%11 = load i32, i32* @FALSE
store i32 %11, i32* %10
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = load i32*, i32** %5
%16 = load i32, i32* @A_REVERSE
%17 = call i32 @wattron(i32* %15, i32 %16)
br label %18
18: ; preds = %14, %4
%19 = load i32*, i32** %5
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
%22 = call i32 @wmove(i32* %19, i32 1, i32 %21)
store i32 0, i32* %9
br label %23
23: ; preds = %65, %18
%24 = load i8*, i8** %8
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %68
31: ; preds = %23
%32 = load i8*, i8** %8
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 126
br i1 %38, label %39, label %48
39: ; preds = %31
%40 = load i32, i32* %7
%41 = icmp ne i32 %40, 0
br i1 %41, label %47, label %42
42: ; preds = %39
%43 = load i32*, i32** %5
%44 = load i32, i32* @A_BOLD
%45 = call i32 @wattron(i32* %43, i32 %44)
%46 = load i32, i32* @TRUE
store i32 %46, i32* %10
br label %47
47: ; preds = %42, %39
br label %64
48: ; preds = %31
%49 = load i32*, i32** %5
%50 = load i8*, i8** %8
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = call i32 @waddch(i32* %49, i8 signext %54)
%56 = load i32, i32* %10
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %48
%59 = load i32, i32* @FALSE
store i32 %59, i32* %10
%60 = load i32*, i32** %5
%61 = load i32, i32* @A_BOLD
%62 = call i32 @wattroff(i32* %60, i32 %61)
br label %63
63: ; preds = %58, %48
br label %64
64: ; preds = %63, %47
br label %65
65: ; preds = %64
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
store i32 %67, i32* %9
br label %23
68: ; preds = %23
%69 = load i32, i32* %7
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %68
%72 = load i32*, i32** %5
%73 = load i32, i32* @A_REVERSE
%74 = call i32 @wattroff(i32* %72, i32 %73)
br label %75
75: ; preds = %71, %68
ret void
}

LLVM IR (-O2):
@FALSE = global i32 0
@A_REVERSE = global i32 0
@A_BOLD = global i32 0
@TRUE = global i32 0
define void @menu_write_item(i32* %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = load i32, i32* @FALSE
%6 = icmp eq i32 %2, 0
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = load i32, i32* @A_REVERSE
%9 = tail call i32 @wattron(i32* %0, i32 %8)
br label %10
10: ; preds = %7, %4
%11 = add nsw i32 %1, 1
%12 = tail call i32 @wmove(i32* %0, i32 1, i32 %11)
br label %13
13: ; preds = %30, %10
%14 = phi i64 [ %32, %30 ], [ 0, %10 ]
%15 = phi i32 [ %31, %30 ], [ %5, %10 ]
%16 = getelementptr inbounds i8, i8* %3, i64 %14
%17 = load i8, i8* %16
switch i8 %17, label %23 [
i8 0, label %33
i8 126, label %18
]
18: ; preds = %13
br i1 %6, label %19, label %30
19: ; preds = %18
%20 = load i32, i32* @A_BOLD
%21 = tail call i32 @wattron(i32* %0, i32 %20)
%22 = load i32, i32* @TRUE
br label %30
23: ; preds = %13
%24 = tail call i32 @waddch(i32* %0, i8 signext %17)
%25 = icmp eq i32 %15, 0
br i1 %25, label %30, label %26
26: ; preds = %23
%27 = load i32, i32* @FALSE
%28 = load i32, i32* @A_BOLD
%29 = tail call i32 @wattroff(i32* %0, i32 %28)
br label %30
30: ; preds = %19, %18, %26, %23
%31 = phi i32 [ %15, %18 ], [ %22, %19 ], [ %27, %26 ], [ 0, %23 ]
%32 = add nuw i64 %14, 1
br label %13
33: ; preds = %13
br i1 %6, label %37, label %34
34: ; preds = %33
%35 = load i32, i32* @A_REVERSE
%36 = tail call i32 @wattroff(i32* %0, i32 %35)
br label %37
37: ; preds = %34, %33
ret void
}