#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 atoi(char *);
int /*<<< orphan*/ printf(char *, char *);
int toInt(char str[]) {
  int res = 0;
  int i = 0;
  while (str[i] != '\0') {
    if (str[i] < 48 || str[i] > 57) {
      printf("Wrong num %s !\n", str);
      return -1;
    } else {
      i++;
    }
  }
  res = atoi(str);
  return res;
}


x86 assembly (clang, -O0):
<toInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11a3 <toInt+0x83>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jl     1179 <toInt+0x59>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x39,%eax
jle    1195 <toInt+0x75>
mov    -0x10(%rbp),%rsi
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <toInt+0x95>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <toInt+0x1a>
mov    -0x10(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toInt>:
push   %rax
mov    %rdi,%rsi
mov    (%rdi),%al
test   %al,%al
je     1141 <toInt+0x21>
lea    0x1(%rsi),%rcx
xchg   %ax,%ax
add    $0xc6,%al
cmp    $0xf5,%al
jbe    114a <toInt+0x2a>
movzbl (%rcx),%eax
add    $0x1,%rcx
test   %al,%al
jne    1130 <toInt+0x10>
mov    %rsi,%rdi
pop    %rax
jmp    1040 <atoi@plt>
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Wrong num %s !\0A\00"
define i32 @toInt(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %36, %1
%7 = load i8*, i8** %3
%8 = load i32, i32* %5
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %37
14: ; preds = %6
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp slt i32 %20, 48
br i1 %21, label %30, label %22
22: ; preds = %14
%23 = load i8*, i8** %3
%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 = icmp sgt i32 %28, 57
br i1 %29, label %30, label %33
30: ; preds = %22, %14
%31 = load i8*, i8** %3
%32 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %31)
store i32 -1, i32* %2
br label %41
33: ; preds = %22
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %36
36: ; preds = %33
br label %6
37: ; preds = %6
%38 = load i8*, i8** %3
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %4
%40 = load i32, i32* %4
store i32 %40, i32* %2
br label %41
41: ; preds = %37, %30
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str = [16 x i8] c"Wrong num %s !\0A\00"
define i32 @toInt(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %16, label %8
4: ; preds = %8
%5 = getelementptr inbounds i8, i8* %0, i64 %13
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %1, %4
%9 = phi i64 [ %13, %4 ], [ 0, %1 ]
%10 = phi i8 [ %6, %4 ], [ %2, %1 ]
%11 = add i8 %10, -58
%12 = icmp ult i8 %11, -10
%13 = add nuw i64 %9, 1
br i1 %12, label %14, label %4
14: ; preds = %8
%15 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %18
16: ; preds = %4, %1
%17 = tail call i32 @atoi(i8* %0)
br label %18
18: ; preds = %16, %14
%19 = phi i32 [ -1, %14 ], [ %17, %16 ]
ret i32 %19
}