#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 getchar();
int /*<<< orphan*/ printf(char *, ...);
int command(char *choices[], int display) {
  int chosen = 0;
  int selected;
  char **option;
  do {
    option = choices;
    if (display) {
      while (*option) {
        printf("%s\n", *option);
        option++;
      }
    }
    do {
      selected = getchar();
    } while (selected == '\n');
    option = choices;
    while (*option) {
      if (selected == *option[0]) {
        chosen = 1;
        break;
      }
      option++;
    }
    if (!chosen) {
      printf("Unknown choice\n");
    }
  } while (!chosen);
  return selected;
}


x86 assembly (clang, -O0):
<command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1186 <command+0x66>
jmp    114d <command+0x2d>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1181 <command+0x61>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    114d <command+0x2d>
jmp    1186 <command+0x66>
jmp    118b <command+0x6b>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
je     118b <command+0x6b>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     11e7 <command+0xc7>
mov    -0x14(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11d6 <command+0xb6>
movl   $0x1,-0x10(%rbp)
jmp    11e7 <command+0xc7>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    11a7 <command+0x87>
cmpl   $0x0,-0x10(%rbp)
jne    11ff <command+0xdf>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1204 <command+0xe4>
cmpl   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1136 <command+0x16>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<command>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0x8(%rdi),%r12
lea    0xec7(%rip),%r14
jmp    1148 <command+0x28>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
test   %r15d,%r15d
je     1180 <command+0x60>
mov    (%rbx),%rdi
test   %rdi,%rdi
je     1180 <command+0x60>
mov    %r12,%rbp
nopl   0x0(%rax,%rax,1)
call   1030 <puts@plt>
mov    0x0(%rbp),%rdi
add    $0x8,%rbp
test   %rdi,%rdi
jne    1160 <command+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     1180 <command+0x60>
mov    (%rbx),%rdx
mov    %r12,%rcx
test   %rdx,%rdx
je     1140 <command+0x20>
nopw   0x0(%rax,%rax,1)
movsbl (%rdx),%edx
cmp    %edx,%eax
je     11b5 <command+0x95>
mov    (%rcx),%rdx
add    $0x8,%rcx
test   %rdx,%rdx
jne    11a0 <command+0x80>
jmp    1140 <command+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [16 x i8] c"Unknown choice\0A\00"
define i32 @command(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
store i8** %0, i8*** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %8
8: ; preds = %54, %2
%9 = load i8**, i8*** %3
store i8** %9, i8*** %7
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %8
br label %13
13: ; preds = %17, %12
%14 = load i8**, i8*** %7
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i8**, i8*** %7
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i8**, i8*** %7
%22 = getelementptr inbounds i8*, i8** %21, i32 1
store i8** %22, i8*** %7
br label %13
23: ; preds = %13
br label %24
24: ; preds = %23, %8
br label %25
25: ; preds = %27, %24
%26 = call i32 (...) @getchar()
store i32 %26, i32* %6
br label %27
27: ; preds = %25
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 10
br i1 %29, label %25, label %30
30: ; preds = %27
%31 = load i8**, i8*** %3
store i8** %31, i8*** %7
br label %32
32: ; preds = %45, %30
%33 = load i8**, i8*** %7
%34 = load i8*, i8** %33
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %48
36: ; preds = %32
%37 = load i32, i32* %6
%38 = load i8**, i8*** %7
%39 = getelementptr inbounds i8*, i8** %38, i64 0
%40 = load i8*, i8** %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %37, %42
br i1 %43, label %44, label %45
44: ; preds = %36
store i32 1, i32* %5
br label %48
45: ; preds = %36
%46 = load i8**, i8*** %7
%47 = getelementptr inbounds i8*, i8** %46, i32 1
store i8** %47, i8*** %7
br label %32
48: ; preds = %44, %32
%49 = load i32, i32* %5
%50 = icmp ne i32 %49, 0
br i1 %50, label %53, label %51
51: ; preds = %48
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %53
53: ; preds = %51, %48
br label %54
54: ; preds = %53
%55 = load i32, i32* %5
%56 = icmp ne i32 %55, 0
%57 = xor i1 %56, true
br i1 %57, label %8, label %58
58: ; preds = %54
%59 = load i32, i32* %6
ret i32 %59
}

LLVM IR (-O2):
@str = [15 x i8] c"Unknown choice\00"
define i32 @command(i8** nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br label %4
4: ; preds = %32, %2
br i1 %3, label %15, label %5
5: ; preds = %4
%6 = load i8*, i8** %0
%7 = icmp eq i8* %6, null
br i1 %7, label %15, label %8
8: ; preds = %5, %8
%9 = phi i8* [ %13, %8 ], [ %6, %5 ]
%10 = phi i8** [ %12, %8 ], [ %0, %5 ]
%11 = tail call i32 @puts(i8* %9)
%12 = getelementptr inbounds i8*, i8** %10, i64 1
%13 = load i8*, i8** %12
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %8
15: ; preds = %8, %5, %4
br label %16
16: ; preds = %15, %16
%17 = tail call i32 (...) @getchar()
%18 = icmp eq i32 %17, 10
br i1 %18, label %16, label %19
19: ; preds = %16
%20 = load i8*, i8** %0
%21 = icmp eq i8* %20, null
br i1 %21, label %32, label %25
22: ; preds = %25
%23 = load i8*, i8** %31
%24 = icmp eq i8* %23, null
br i1 %24, label %32, label %25
25: ; preds = %19, %22
%26 = phi i8* [ %23, %22 ], [ %20, %19 ]
%27 = phi i8** [ %31, %22 ], [ %0, %19 ]
%28 = load i8, i8* %26
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %17, %29
%31 = getelementptr inbounds i8*, i8** %27, i64 1
br i1 %30, label %34, label %22
32: ; preds = %22, %19
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %4
34: ; preds = %25
ret i32 %17
}