#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*/ buf;

/* Variables and functions */
int atoui(char *);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int read_prompt(char *, int);
int /*<<< orphan*/ sclp_set_write_mask(int, int);
int get_index(void) {
  char buf[11];
  int len;
  int i;
  memset(buf, 0, sizeof(buf));
  sclp_set_write_mask(0x00000040, 0x00000040);
  len = read_prompt(buf, sizeof(buf) - 1);
  sclp_set_write_mask(0, 0x00000040);
  if (len == 0) {
    return 0;
  }
  for (i = 0; i < len; i++) {
    if (!isdigit(buf[i])) {
      return -1;
    }
  }
  return atoui(buf);
}


x86 assembly (clang, -O0):
<get_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0xf(%rbp),%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1060 <memset@plt>
mov    $0x40,%esi
mov    %esi,%edi
call   1030 <sclp_set_write_mask@plt>
lea    -0xf(%rbp),%rdi
mov    $0xa,%esi
call   1050 <read_prompt@plt>
mov    %eax,-0x14(%rbp)
xor    %edi,%edi
mov    $0x40,%esi
call   1030 <sclp_set_write_mask@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11a7 <get_index+0x57>
movl   $0x0,-0x4(%rbp)
jmp    11fc <get_index+0xac>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f0 <get_index+0xa0>
movslq -0x18(%rbp),%rax
movsbl -0xf(%rbp,%rax,1),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    11dd <get_index+0x8d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fc <get_index+0xac>
jmp    11e2 <get_index+0x92>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ae <get_index+0x5e>
lea    -0xf(%rbp),%rdi
call   1070 <atoui@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_index>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xd(%rsp),%rbp
xor    %ebx,%ebx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1060 <memset@plt>
mov    $0x40,%edi
mov    $0x40,%esi
call   1030 <sclp_set_write_mask@plt>
mov    %rbp,%rdi
mov    $0xa,%esi
call   1050 <read_prompt@plt>
mov    %eax,%ebp
xor    %edi,%edi
mov    $0x40,%esi
call   1030 <sclp_set_write_mask@plt>
test   %ebp,%ebp
je     11ca <get_index+0x7a>
jle    11b7 <get_index+0x67>
mov    %ebp,%ebx
xor    %ebp,%ebp
movsbl 0xd(%rsp,%rbp,1),%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     11c5 <get_index+0x75>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11a0 <get_index+0x50>
lea    0xd(%rsp),%rdi
call   1070 <atoui@plt>
mov    %eax,%ebx
jmp    11ca <get_index+0x7a>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_index() {
%1 = alloca i32
%2 = alloca [11 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 11)
%7 = call i32 @sclp_set_write_mask(i32 64, i32 64)
%8 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%9 = call i32 @read_prompt(i8* %8, i32 10)
store i32 %9, i32* %3
%10 = call i32 @sclp_set_write_mask(i32 0, i32 64)
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %0
store i32 0, i32* %1
br label %34
14: ; preds = %0
store i32 0, i32* %4
br label %15
15: ; preds = %28, %14
%16 = load i32, i32* %4
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = call i32 @isdigit(i8 signext %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %19
store i32 -1, i32* %1
br label %34
27: ; preds = %19
br label %28
28: ; preds = %27
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %15
31: ; preds = %15
%32 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%33 = call i32 @atoui(i8* %32)
store i32 %33, i32* %1
br label %34
34: ; preds = %31, %26, %13
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
define i32 @get_index() {
%1 = alloca [11 x i8]
%2 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 0, i32 11)
%4 = call i32 @sclp_set_write_mask(i32 64, i32 64)
%5 = call i32 @read_prompt(i8* %2, i32 10)
%6 = call i32 @sclp_set_write_mask(i32 0, i32 64)
%7 = icmp eq i32 %5, 0
br i1 %7, label %23, label %8
8: ; preds = %0
%9 = icmp sgt i32 %5, 0
br i1 %9, label %10, label %21
10: ; preds = %8
%11 = zext i32 %5 to i64
br label %14
12: ; preds = %14
%13 = icmp eq i64 %20, %11
br i1 %13, label %21, label %14
14: ; preds = %10, %12
%15 = phi i64 [ 0, %10 ], [ %20, %12 ]
%16 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = call i32 @isdigit(i8 signext %17)
%19 = icmp eq i32 %18, 0
%20 = add nuw nsw i64 %15, 1
br i1 %19, label %23, label %12
21: ; preds = %12, %8
%22 = call i32 @atoui(i8* %2)
br label %23
23: ; preds = %14, %0, %21
%24 = phi i32 [ %22, %21 ], [ 0, %0 ], [ -1, %14 ]
ret i32 %24
}