#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 expo(int, int);
char *getStr();
int length(char *);
int /*<<< orphan*/ printf(char *);
int getInt(void) {
  char *int_str = getStr();
  int len = length(int_str);
  int int_out = 0;
  int i;
  for (i = 0; i < len; i++) {
    if (*(int_str + i) - '0' >= 48 && *(int_str + i) - '0' <= 57) {
      printf("Invalid Input!\n");
      return -1;
    }
    int_out += (*(int_str + i) - '0') * (expo(10, (len - 1) - i));
  }
  return int_out;
}


x86 assembly (clang, -O0):
<getInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1060 <getStr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <length@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1205 <getInt+0xc5>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sub    $0x30,%eax
cmp    $0x30,%eax
jl     11c1 <getInt+0x81>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sub    $0x30,%eax
cmp    $0x39,%eax
jg     11c1 <getInt+0x81>
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <getInt+0xcb>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sub    $0x30,%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
sub    -0x1c(%rbp),%esi
mov    $0xa,%edi
call   1050 <expo@plt>
mov    %al,%cl
mov    -0x20(%rbp),%eax
movsbl %cl,%ecx
imul   %ecx,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116d <getInt+0x2d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getInt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r12d,%r12d
xor    %eax,%eax
call   1060 <getStr@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <length@plt>
test   %eax,%eax
jle    11c6 <getInt+0x86>
mov    %eax,%r13d
mov    %eax,%r15d
add    $0xffffffff,%r13d
xor    %ebp,%ebp
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%r14,%rbp,1),%ebx
lea    -0x60(%rbx),%eax
cmp    $0x9,%al
jbe    11b4 <getInt+0x74>
add    $0xffffffd0,%ebx
mov    $0xa,%edi
mov    %r13d,%esi
call   1050 <expo@plt>
movsbl %al,%eax
imul   %ebx,%eax
add    %eax,%r12d
add    $0x1,%rbp
add    $0xffffffff,%r13d
cmp    %rbp,%r15
jne    1180 <getInt+0x40>
jmp    11c6 <getInt+0x86>
lea    0xe45(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Invalid Input!\0A\00"
define i32 @getInt() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call i8* (...) @getStr()
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @length(i8* %7)
store i32 %8, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %50, %0
%10 = load i32, i32* %5
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %53
13: ; preds = %9
%14 = load i8*, i8** %2
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = sub nsw i32 %19, 48
%21 = icmp sge i32 %20, 48
br i1 %21, label %22, label %33
22: ; preds = %13
%23 = load i8*, i8** %2
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = sub nsw i32 %28, 48
%30 = icmp sle i32 %29, 57
br i1 %30, label %31, label %33
31: ; preds = %22
%32 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %55
33: ; preds = %22, %13
%34 = load i8*, i8** %2
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = sub nsw i32 %39, 48
%41 = load i32, i32* %3
%42 = sub nsw i32 %41, 1
%43 = load i32, i32* %5
%44 = sub nsw i32 %42, %43
%45 = call signext i8 @expo(i32 10, i32 %44)
%46 = sext i8 %45 to i32
%47 = mul nsw i32 %40, %46
%48 = load i32, i32* %4
%49 = add nsw i32 %48, %47
store i32 %49, i32* %4
br label %50
50: ; preds = %33
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %9
53: ; preds = %9
%54 = load i32, i32* %4
store i32 %54, i32* %1
br label %55
55: ; preds = %53, %31
%56 = load i32, i32* %1
ret i32 %56
}

LLVM IR (-O2):
@str = [15 x i8] c"Invalid Input!\00"
define i32 @getInt() {
%1 = tail call i8* (...) @getStr()
%2 = tail call i32 @length(i8* %1)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %27
4: ; preds = %0
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %15
%7 = phi i64 [ 0, %4 ], [ %25, %15 ]
%8 = phi i32 [ 0, %4 ], [ %24, %15 ]
%9 = getelementptr inbounds i8, i8* %1, i64 %7
%10 = load i8, i8* %9
%11 = add i8 %10, -96
%12 = icmp ult i8 %11, 10
br i1 %12, label %13, label %15
13: ; preds = %6
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %27
15: ; preds = %6
%16 = trunc i64 %7 to i32
%17 = sext i8 %10 to i32
%18 = add nsw i32 %17, -48
%19 = xor i32 %16, -1
%20 = add i32 %2, %19
%21 = tail call signext i8 @expo(i32 10, i32 %20)
%22 = sext i8 %21 to i32
%23 = mul nsw i32 %18, %22
%24 = add nsw i32 %23, %8
%25 = add nuw nsw i64 %7, 1
%26 = icmp eq i64 %25, %5
br i1 %26, label %27, label %6
27: ; preds = %15, %0, %13
%28 = phi i32 [ -1, %13 ], [ 0, %0 ], [ %24, %15 ]
ret i32 %28
}