#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 */
char EOF;
int atoi(char *);
scalar_t__ isdigit(char);
scalar_t__ isspace(char);
int CLIReadNum(char *str) {
  char c;
  char charNum[50];
  char *charNumPtr = charNum;
  int length = 0;
  do {
    c = *str++;
    if (isspace(c))
      continue;
    else if (isdigit(c))
      break;
    else
      return -1;
  } while (1);
  do {
    if (isspace(c) || c == EOF || c == '\0')
      break;
    if (length > 49)
      return -1;
    if (!isdigit(c))
      return -1;
    *charNumPtr = c;
    charNumPtr++;
    length++;
    c = *str++;
  } while (1);
  *charNumPtr = '\0';
  return atoi(charNum);
}


x86 assembly (clang, -O0):
<CLIReadNum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1177 <CLIReadNum+0x47>
jmp    119b <CLIReadNum+0x6b>
movsbl -0x11(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     118f <CLIReadNum+0x5f>
jmp    11aa <CLIReadNum+0x7a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1273 <CLIReadNum+0x143>
mov    $0x1,%al
test   $0x1,%al
jne    114b <CLIReadNum+0x1b>
jmp    11aa <CLIReadNum+0x7a>
jmp    11af <CLIReadNum+0x7f>
movsbl -0x11(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
jne    11e5 <CLIReadNum+0xb5>
movsbl -0x11(%rbp),%eax
mov    0x2e1b(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11e5 <CLIReadNum+0xb5>
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jne    11ea <CLIReadNum+0xba>
jmp    1260 <CLIReadNum+0x130>
cmpl   $0x31,-0x5c(%rbp)
jle    1200 <CLIReadNum+0xd0>
movl   $0xffffffff,-0x4(%rbp)
jmp    1273 <CLIReadNum+0x143>
movsbl -0x11(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    121f <CLIReadNum+0xef>
movl   $0xffffffff,-0x4(%rbp)
jmp    1273 <CLIReadNum+0x143>
mov    -0x11(%rbp),%cl
mov    -0x58(%rbp),%rax
mov    %cl,(%rax)
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    11af <CLIReadNum+0x7f>
jmp    1260 <CLIReadNum+0x130>
mov    -0x58(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x50(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CLIReadNum>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%rbx
nop
movzbl (%rbx),%r15d
add    $0x1,%rbx
movsbl %r15b,%ebp
mov    %ebp,%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    1140 <CLIReadNum+0x10>
mov    %ebp,%edi
call   1030 <isdigit@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     11db <CLIReadNum+0xab>
mov    %ebp,%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     117b <CLIReadNum+0x4b>
mov    %rsp,%rax
jmp    11cd <CLIReadNum+0x9d>
xor    %ebp,%ebp
mov    0x2e64(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %r15b,%r15b
je     11c9 <CLIReadNum+0x99>
cmp    (%r12),%r15b
je     11c9 <CLIReadNum+0x99>
cmp    $0x32,%ebp
je     11db <CLIReadNum+0xab>
movsbl %r15b,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11db <CLIReadNum+0xab>
mov    %r15b,(%rsp,%rbp,1)
movzbl (%rbx,%rbp,1),%r15d
movsbl %r15b,%edi
call   1040 <isspace@plt>
add    $0x1,%rbp
test   %rax,%rax
je     1190 <CLIReadNum+0x60>
lea    (%rsp,%rbp,1),%rax
movb   $0x0,(%rax)
mov    %rsp,%rdi
call   1050 <atoi@plt>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i8 0
define i32 @CLIReadNum(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca [50 x i8]
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
store i8* %8, i8** %6
store i32 0, i32* %7
br label %9
9: ; preds = %23, %1
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %3
%12 = load i8, i8* %10
store i8 %12, i8* %4
%13 = load i8, i8* %4
%14 = call i64 @isspace(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %9
br label %23
17: ; preds = %9
%18 = load i8, i8* %4
%19 = call i64 @isdigit(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
br label %24
22: ; preds = %17
store i32 -1, i32* %2
br label %64
23: ; preds = %16
br i1 true, label %9, label %24
24: ; preds = %23, %21
br label %25
25: ; preds = %59, %24
%26 = load i8, i8* %4
%27 = call i64 @isspace(i8 signext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %39, label %29
29: ; preds = %25
%30 = load i8, i8* %4
%31 = sext i8 %30 to i32
%32 = load i8, i8* @EOF
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %31, %33
br i1 %34, label %39, label %35
35: ; preds = %29
%36 = load i8, i8* %4
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35, %29, %25
br label %60
40: ; preds = %35
%41 = load i32, i32* %7
%42 = icmp sgt i32 %41, 49
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 -1, i32* %2
br label %64
44: ; preds = %40
%45 = load i8, i8* %4
%46 = call i64 @isdigit(i8 signext %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %49, label %48
48: ; preds = %44
store i32 -1, i32* %2
br label %64
49: ; preds = %44
%50 = load i8, i8* %4
%51 = load i8*, i8** %6
store i8 %50, i8* %51
%52 = load i8*, i8** %6
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %6
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
%56 = load i8*, i8** %3
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %3
%58 = load i8, i8* %56
store i8 %58, i8* %4
br label %59
59: ; preds = %49
br i1 true, label %25, label %60
60: ; preds = %59, %39
%61 = load i8*, i8** %6
store i8 0, i8* %61
%62 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%63 = call i32 @atoi(i8* %62)
store i32 %63, i32* %2
br label %64
64: ; preds = %60, %48, %43, %22
%65 = load i32, i32* %2
ret i32 %65
}

LLVM IR (-O2):
@EOF = global i8 0
define i32 @CLIReadNum(i8* nocapture %0) {
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %4, %1
%5 = phi i8* [ %0, %1 ], [ %6, %4 ]
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = load i8, i8* %5
%8 = tail call i64 @isspace(i8 signext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %4
10: ; preds = %4
%11 = tail call i64 @isdigit(i8 signext %7)
%12 = icmp eq i64 %11, 0
br i1 %12, label %40, label %13
13: ; preds = %10
%14 = tail call i64 @isspace(i8 signext %7)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %37
16: ; preds = %13, %30
%17 = phi i32 [ %32, %30 ], [ 0, %13 ]
%18 = phi i8* [ %31, %30 ], [ %3, %13 ]
%19 = phi i8 [ %34, %30 ], [ %7, %13 ]
%20 = phi i8* [ %33, %30 ], [ %6, %13 ]
%21 = load i8, i8* @EOF
%22 = icmp eq i8 %19, %21
%23 = icmp eq i8 %19, 0
%24 = or i1 %23, %22
br i1 %24, label %37, label %25
25: ; preds = %16
%26 = icmp eq i32 %17, 50
br i1 %26, label %40, label %27
27: ; preds = %25
%28 = tail call i64 @isdigit(i8 signext %19)
%29 = icmp eq i64 %28, 0
br i1 %29, label %40, label %30
30: ; preds = %27
store i8 %19, i8* %18
%31 = getelementptr inbounds i8, i8* %18, i64 1
%32 = add nuw nsw i32 %17, 1
%33 = getelementptr inbounds i8, i8* %20, i64 1
%34 = load i8, i8* %20
%35 = tail call i64 @isspace(i8 signext %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %16, label %37
37: ; preds = %16, %30, %13
%38 = phi i8* [ %3, %13 ], [ %31, %30 ], [ %18, %16 ]
store i8 0, i8* %38
%39 = call i32 @atoi(i8* %3)
br label %40
40: ; preds = %27, %25, %10, %37
%41 = phi i32 [ %39, %37 ], [ -1, %10 ], [ -1, %25 ], [ -1, %27 ]
ret i32 %41
}