#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*/ memcpy(char *, char const *, int);
int printstr(char *);
int /*<<< orphan*/ put_ch(char);
int /*<<< orphan*/ setattr_normal();
int /*<<< orphan*/ setattr_standout();
char *strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
void printmenuitem_options(const char *str, int sel) {
  char buf[16];
  const char *p = str;
  int ret;
  while (1) {
    if (p = strchr(str, ' ')) {
      memcpy(buf, str, p - str);
      buf[p - str] = '\0';
    } else
      strcpy(buf, str);
    if (!sel) {
      setattr_standout();
      ret = printstr(buf);
      setattr_normal();
    } else
      ret = printstr(buf);
    if (!ret || !p)
      break;
    put_ch(' ');
    str = p + 1;
    sel--;
  }
}


x86 assembly (clang, -O0):
<printmenuitem_options>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11d2 <printmenuitem_options+0x62>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0x20(%rbp,%rax,1)
jmp    11df <printmenuitem_options+0x6f>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1208 <printmenuitem_options+0x98>
mov    $0x0,%al
call   1080 <setattr_standout@plt>
lea    -0x20(%rbp),%rdi
call   1060 <printstr@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1040 <setattr_normal@plt>
jmp    1214 <printmenuitem_options+0xa4>
lea    -0x20(%rbp),%rdi
call   1060 <printstr@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1229 <printmenuitem_options+0xb9>
cmpq   $0x0,-0x28(%rbp)
jne    122e <printmenuitem_options+0xbe>
jmp    1252 <printmenuitem_options+0xe2>
mov    $0x20,%edi
call   1090 <put_ch@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1187 <printmenuitem_options+0x17>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printmenuitem_options>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r15d
mov    %rdi,%r12
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11e0 <printmenuitem_options+0x70>
mov    %rbp,%rbx
sub    %r12,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1070 <memcpy@plt>
movb   $0x0,(%rsp,%rbx,1)
sub    $0x1,%r15d
jae    11f1 <printmenuitem_options+0x81>
xor    %eax,%eax
call   1080 <setattr_standout@plt>
mov    %r14,%rdi
call   1060 <printstr@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <setattr_normal@plt>
test   %ebx,%ebx
jne    11ff <printmenuitem_options+0x8f>
jmp    121a <printmenuitem_options+0xaa>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
sub    $0x1,%r15d
jb     11c2 <printmenuitem_options+0x52>
mov    %r14,%rdi
call   1060 <printstr@plt>
mov    %eax,%ebx
test   %ebx,%ebx
je     121a <printmenuitem_options+0xaa>
test   %rbp,%rbp
je     121a <printmenuitem_options+0xaa>
mov    $0x20,%edi
call   1090 <put_ch@plt>
add    $0x1,%rbp
mov    %rbp,%r12
jmp    1190 <printmenuitem_options+0x20>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @printmenuitem_options(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [16 x i8]
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
store i8* %8, i8** %6
br label %9
9: ; preds = %2, %51
%10 = load i8*, i8** %3
%11 = call i8* @strchr(i8* %10, i8 signext 32)
store i8* %11, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %29
13: ; preds = %9
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%15 = load i8*, i8** %3
%16 = load i8*, i8** %6
%17 = load i8*, i8** %3
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = call i32 @memcpy(i8* %14, i8* %15, i32 %21)
%23 = load i8*, i8** %6
%24 = load i8*, i8** %3
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 %27
store i8 0, i8* %28
br label %33
29: ; preds = %9
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%31 = load i8*, i8** %3
%32 = call i32 @strcpy(i8* %30, i8* %31)
br label %33
33: ; preds = %29, %13
%34 = load i32, i32* %4
%35 = icmp ne i32 %34, 0
br i1 %35, label %41, label %36
36: ; preds = %33
%37 = call i32 (...) @setattr_standout()
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%39 = call i32 @printstr(i8* %38)
store i32 %39, i32* %7
%40 = call i32 (...) @setattr_normal()
br label %44
41: ; preds = %33
%42 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%43 = call i32 @printstr(i8* %42)
store i32 %43, i32* %7
br label %44
44: ; preds = %41, %36
%45 = load i32, i32* %7
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i8*, i8** %6
%49 = icmp ne i8* %48, null
br i1 %49, label %51, label %50
50: ; preds = %47, %44
br label %57
51: ; preds = %47
%52 = call i32 @put_ch(i8 signext 32)
%53 = load i8*, i8** %6
%54 = getelementptr inbounds i8, i8* %53, i64 1
store i8* %54, i8** %3
%55 = load i32, i32* %4
%56 = add nsw i32 %55, -1
store i32 %56, i32* %4
br label %9
57: ; preds = %50
ret void
}

LLVM IR (-O2):
define void @printmenuitem_options(i8* %0, i32 %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %31, %2
%6 = phi i8* [ %0, %2 ], [ %33, %31 ]
%7 = phi i32 [ %1, %2 ], [ %34, %31 ]
%8 = call i8* @strchr(i8* dereferenceable(1) %6, i8 signext 32)
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %17
10: ; preds = %5
%11 = ptrtoint i8* %8 to i64
%12 = ptrtoint i8* %6 to i64
%13 = sub i64 %11, %12
%14 = trunc i64 %13 to i32
%15 = call i32 @memcpy(i8* %4, i8* %6, i32 %14)
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %13
store i8 0, i8* %16
br label %19
17: ; preds = %5
%18 = call i32 @strcpy(i8* %4, i8* %6)
br label %19
19: ; preds = %17, %10
%20 = icmp eq i32 %7, 0
br i1 %20, label %21, label %25
21: ; preds = %19
%22 = call i32 (...) @setattr_standout()
%23 = call i32 @printstr(i8* %4)
%24 = call i32 (...) @setattr_normal()
br label %27
25: ; preds = %19
%26 = call i32 @printstr(i8* %4)
br label %27
27: ; preds = %25, %21
%28 = phi i32 [ %26, %25 ], [ %23, %21 ]
%29 = icmp ne i32 %28, 0
%30 = select i1 %29, i1 %9, i1 false
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = call i32 @put_ch(i8 signext 32)
%33 = getelementptr inbounds i8, i8* %8, i64 1
%34 = add nsw i32 %7, -1
br label %5
35: ; preds = %27
ret void
}