#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*/ exits(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ probe();
int read(int /*<<< orphan*/, char *, int);
int shelfid(char *);
int /*<<< orphan*/ showtable(int);
int /*<<< orphan*/ stdout;
int pickone(void) {
  char buf[80];
  int n;
  showtable(1);
  for (;;) {
    printf("[#qp]: ");
    fflush(stdout);
    n = read(0, buf, sizeof buf);
    switch (n) {
    case 1:
      if (buf[0] == '\n')
        continue;
    case 2:
      if (buf[0] == 'p') {
        probe();
        break;
      }
      if (buf[0] == 'q')
      case 0:
      case -1:
        exits(0);
    }
    buf[n] = 0;
    n = shelfid(buf);
    if (n >= 0)
      return n;
    showtable(1);
  }
}


x86 assembly (clang, -O0):
<pickone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    $0x1,%edi
call   1030 <showtable@plt>
lea    0xe77(%rip),%rdi
call   1060 <printf@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
xor    %edi,%edi
lea    -0x50(%rbp),%rsi
mov    $0x50,%edx
call   1070 <read@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x58(%rbp)
add    $0x1,%eax
sub    $0x2,%eax
jb     122a <pickone+0xba>
jmp    11c6 <pickone+0x56>
mov    -0x58(%rbp),%eax
sub    $0x1,%eax
je     11e8 <pickone+0x78>
jmp    11d7 <pickone+0x67>
mov    -0x58(%rbp),%eax
sub    $0x2,%eax
je     11ff <pickone+0x8f>
jmp    1236 <pickone+0xc6>
movsbl -0x50(%rbp),%eax
cmp    $0xa,%eax
jne    11fa <pickone+0x8a>
jmp    1182 <pickone+0x12>
jmp    11ff <pickone+0x8f>
movsbl -0x50(%rbp),%eax
cmp    $0x70,%eax
jne    1218 <pickone+0xa8>
mov    $0x0,%al
call   1040 <probe@plt>
jmp    1236 <pickone+0xc6>
movsbl -0x50(%rbp),%eax
cmp    $0x71,%eax
jne    1231 <pickone+0xc1>
jmp    122a <pickone+0xba>
xor    %edi,%edi
call   1090 <exits@plt>
jmp    1236 <pickone+0xc6>
movslq -0x54(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
lea    -0x50(%rbp),%rdi
call   1050 <shelfid@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jl     125e <pickone+0xee>
mov    -0x54(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret
mov    $0x1,%edi
call   1030 <showtable@plt>
jmp    1182 <pickone+0x12>

x86 assembly (clang, -O2):
<pickone>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    $0x1,%edi
call   1030 <showtable@plt>
lea    0xe74(%rip),%r14
mov    0x2e4d(%rip),%r12
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1060 <printf@plt>
mov    (%r12),%edi
call   1080 <fflush@plt>
xor    %edi,%edi
mov    %r15,%rsi
mov    $0x50,%edx
call   1070 <read@plt>
mov    %eax,%ebx
lea    0x1(%rbx),%eax
cmp    $0x2,%eax
jb     1200 <pickone+0x90>
cmp    $0x2,%ebx
je     11f0 <pickone+0x80>
cmp    $0x1,%ebx
jne    1207 <pickone+0x97>
movzbl (%rsp),%eax
cmp    $0xa,%al
je     11a0 <pickone+0x30>
cmp    $0x71,%al
je     1200 <pickone+0x90>
cmp    $0x70,%al
jne    1207 <pickone+0x97>
xor    %eax,%eax
call   1040 <probe@plt>
jmp    1207 <pickone+0x97>
nopl   (%rax)
movzbl (%rsp),%eax
cmp    $0x71,%al
jne    11e0 <pickone+0x70>
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
call   1090 <exits@plt>
movslq %ebx,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
call   1050 <shelfid@plt>
test   %eax,%eax
jns    1229 <pickone+0xb9>
mov    $0x1,%edi
call   1030 <showtable@plt>
jmp    11a0 <pickone+0x30>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"[#qp]: \00"
@stdout = global i32 0
define i32 @pickone() {
%1 = alloca [80 x i8]
%2 = alloca i32
%3 = call i32 @showtable(i32 1)
br label %4
4: ; preds = %44, %16, %0
%5 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdout
%7 = call i32 @fflush(i32 %6)
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%9 = call i32 @read(i32 0, i8* %8, i32 80)
store i32 %9, i32* %2
%10 = load i32, i32* %2
switch i32 %10, label %34 [
i32 1, label %11
i32 2, label %18
i32 0, label %31
i32 -1, label %31
]
11: ; preds = %4
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 10
br i1 %15, label %16, label %17
16: ; preds = %11
br label %4
17: ; preds = %11
br label %18
18: ; preds = %4, %17
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 112
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 (...) @probe()
br label %34
25: ; preds = %18
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 113
br i1 %29, label %30, label %33
30: ; preds = %25
br label %31
31: ; preds = %4, %4, %30
%32 = call i32 @exits(i32 0)
br label %33
33: ; preds = %31, %25
br label %34
34: ; preds = %33, %4, %23
%35 = load i32, i32* %2
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %36
store i8 0, i8* %37
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%39 = call i32 @shelfid(i8* %38)
store i32 %39, i32* %2
%40 = load i32, i32* %2
%41 = icmp sge i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %34
%43 = load i32, i32* %2
ret i32 %43
44: ; preds = %34
%45 = call i32 @showtable(i32 1)
br label %4
}

LLVM IR (-O2):
@.str = [8 x i8] c"[#qp]: \00"
@stdout = global i32 0
define i32 @pickone() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @showtable(i32 1)
br label %4
4: ; preds = %28, %0
%5 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdout
%7 = call i32 @fflush(i32 %6)
%8 = call i32 @read(i32 0, i8* %2, i32 80)
switch i32 %8, label %20 [
i32 1, label %9
i32 2, label %12
i32 0, label %18
i32 -1, label %18
]
9: ; preds = %4
%10 = load i8, i8* %2
%11 = icmp eq i8 %10, 10
br i1 %11, label %28, label %14
12: ; preds = %4
%13 = load i8, i8* %2
br label %14
14: ; preds = %12, %9
%15 = phi i8 [ %13, %12 ], [ %10, %9 ]
switch i8 %15, label %20 [
i8 112, label %16
i8 113, label %18
]
16: ; preds = %14
%17 = call i32 (...) @probe()
br label %20
18: ; preds = %14, %4, %4
%19 = call i32 @exits(i32 0)
br label %20
20: ; preds = %14, %18, %4, %16
%21 = sext i32 %8 to i64
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %21
store i8 0, i8* %22
%23 = call i32 @shelfid(i8* %2)
%24 = icmp sgt i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %20
ret i32 %23
26: ; preds = %20
%27 = call i32 @showtable(i32 1)
br label %28
28: ; preds = %26, %9
br label %4
}