#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 safe_atoi(char *s) {
  if (!s)
    return 0;
  if ((s[0] >= '0' && s[0] <= '9') || s[0] == '-' || s[0] == '+')
    return atoi(s);
  return 0;
}


x86 assembly (clang, -O0):
<safe_atoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1133 <safe_atoi+0x23>
movl   $0x0,-0x4(%rbp)
jmp    118b <safe_atoi+0x7b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     1153 <safe_atoi+0x43>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    1173 <safe_atoi+0x63>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     1173 <safe_atoi+0x63>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    1184 <safe_atoi+0x74>
mov    -0x10(%rbp),%rdi
call   1030 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    118b <safe_atoi+0x7b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_atoi>:
test   %rdi,%rdi
je     112c <safe_atoi+0x1c>
mov    (%rdi),%al
lea    -0x30(%rax),%ecx
cmp    $0xa,%cl
jb     1127 <safe_atoi+0x17>
cmp    $0x2d,%al
je     1127 <safe_atoi+0x17>
cmp    $0x2b,%al
jne    112c <safe_atoi+0x1c>
jmp    1030 <atoi@plt>
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @safe_atoi(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = icmp ne i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
store i32 0, i32* %2
br label %35
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp sge i32 %11, 48
br i1 %12, label %13, label %19
13: ; preds = %7
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp sle i32 %17, 57
br i1 %18, label %31, label %19
19: ; preds = %13, %7
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 45
br i1 %24, label %31, label %25
25: ; preds = %19
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 43
br i1 %30, label %31, label %34
31: ; preds = %25, %19, %13
%32 = load i8*, i8** %3
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %2
br label %35
34: ; preds = %25
store i32 0, i32* %2
br label %35
35: ; preds = %34, %31, %6
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
define i32 @safe_atoi(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %10, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = add i8 %4, -48
%6 = icmp ult i8 %5, 10
br i1 %6, label %8, label %7
7: ; preds = %3
switch i8 %4, label %10 [
i8 45, label %8
i8 43, label %8
]
8: ; preds = %7, %7, %3
%9 = tail call i32 @atoi(i8* %0)
br label %10
10: ; preds = %7, %1, %8
%11 = phi i32 [ %9, %8 ], [ 0, %1 ], [ 0, %7 ]
ret i32 %11
}