#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 get_item_count(char const *);
int int_input(char *);
int /*<<< orphan*/ isdigit(int);
int /*<<< orphan*/ print_list(char const *, char *);
int get_item(const char *items, char *heading, char *input_prompt) {
  int item_count = get_item_count(items);
  for (int user_input = 0;;) {
    print_list(items, heading);
    user_input = int_input(input_prompt) - 1;
    if (!isdigit(user_input) && user_input >= 0 &&
        user_input < get_item_count(items))
      return user_input;
  }
}


x86 assembly (clang, -O0):
<get_item>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <get_item_count@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <print_list@plt>
mov    -0x18(%rbp),%rdi
call   1050 <int_input@plt>
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11c3 <get_item+0x83>
cmpl   $0x0,-0x20(%rbp)
jl     11c3 <get_item+0x83>
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <get_item_count@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11c3 <get_item+0x83>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret
jmp    1167 <get_item+0x27>

x86 assembly (clang, -O2):
<get_item>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1050 <get_item_count@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <print_list@plt>
mov    %r14,%rdi
call   1040 <int_input@plt>
mov    %eax,%ebx
lea    -0x3b(%rbx),%eax
test   %ebx,%ebx
jle    1150 <get_item+0x20>
cmp    $0xfffffff5,%eax
ja     1150 <get_item+0x20>
mov    %r12,%rdi
call   1050 <get_item_count@plt>
cmp    %eax,%ebx
jg     1150 <get_item+0x20>
add    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @get_item(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = call i32 @get_item_count(i8* %9)
store i32 %10, i32* %7
store i32 0, i32* %8
br label %11
11: ; preds = %31, %3
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i32 @print_list(i8* %12, i8* %13)
%15 = load i8*, i8** %6
%16 = call i32 @int_input(i8* %15)
%17 = sub nsw i32 %16, 1
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = call i32 @isdigit(i32 %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %31, label %21
21: ; preds = %11
%22 = load i32, i32* %8
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i32, i32* %8
%26 = load i8*, i8** %4
%27 = call i32 @get_item_count(i8* %26)
%28 = icmp slt i32 %25, %27
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = load i32, i32* %8
ret i32 %30
31: ; preds = %24, %21, %11
br label %11
}

LLVM IR (-O2):
define i32 @get_item(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @get_item_count(i8* %0)
br label %5
5: ; preds = %15, %3
%6 = tail call i32 @print_list(i8* %0, i8* %1)
%7 = tail call i32 @int_input(i8* %2)
%8 = add i32 %7, -59
%9 = icmp ult i32 %8, -10
%10 = icmp sgt i32 %7, 0
%11 = and i1 %10, %9
br i1 %11, label %12, label %15
12: ; preds = %5
%13 = tail call i32 @get_item_count(i8* %0)
%14 = icmp sgt i32 %7, %13
br i1 %14, label %15, label %16
15: ; preds = %12, %5
br label %5
16: ; preds = %12
%17 = add nsw i32 %7, -1
ret i32 %17
}