#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 */
long LONG_MAX;
int /*<<< orphan*/ printf(char *);
long strtol(char *, char **, int);
int string_handler(char arr[]) {
  char *ptr;
  long ret = strtol(arr, &ptr, 10);
  if (arr == ptr)
    printf("Value invalid\n");
  else if ((ret == LONG_MAX || ret == LONG_MAX))
    printf("Invalid character type\n");
  else if (ret > 127 || ret < -127)
    printf("Out of range");
  else
    return ret;
  return -1;
}


x86 assembly (clang, -O0):
<string_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    1161 <string_handler+0x41>
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
jmp    11d7 <string_handler+0xb7>
mov    -0x20(%rbp),%rax
mov    0x2e74(%rip),%rcx
cmp    (%rcx),%rax
je     1189 <string_handler+0x69>
mov    -0x20(%rbp),%rax
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%rax
jne    119a <string_handler+0x7a>
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
jmp    11d2 <string_handler+0xb2>
cmpq   $0x7f,-0x20(%rbp)
jg     11b0 <string_handler+0x90>
cmpq   $0xffffffffffffff81,-0x20(%rbp)
jge    11c1 <string_handler+0xa1>
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
jmp    11cd <string_handler+0xad>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11de <string_handler+0xbe>
jmp    11d2 <string_handler+0xb2>
jmp    11d7 <string_handler+0xb7>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_handler>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
cmp    %rbx,0x8(%rsp)
je     1168 <string_handler+0x38>
mov    0x2e8b(%rip),%rcx
cmp    (%rcx),%rax
jne    1176 <string_handler+0x46>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
jmp    1192 <string_handler+0x62>
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
jmp    1192 <string_handler+0x62>
mov    %rax,%rcx
add    $0xffffffffffffff80,%rcx
cmp    $0xffffffffffffff00,%rcx
ja     1197 <string_handler+0x67>
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Value invalid\0A\00"
@LONG_MAX = global i64 0
@.str.1 = [24 x i8] c"Invalid character type\0A\00"
@.str.2 = [13 x i8] c"Out of range\00"
define i32 @string_handler(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strtol(i8* %6, i8** %4, i32 10)
store i64 %7, i64* %5
%8 = load i8*, i8** %3
%9 = load i8*, i8** %4
%10 = icmp eq i8* %8, %9
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %36
13: ; preds = %1
%14 = load i64, i64* %5
%15 = load i64, i64* @LONG_MAX
%16 = icmp eq i64 %14, %15
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i64, i64* %5
%19 = load i64, i64* @LONG_MAX
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17, %13
%22 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %35
23: ; preds = %17
%24 = load i64, i64* %5
%25 = icmp sgt i64 %24, 127
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i64, i64* %5
%28 = icmp slt i64 %27, -127
br i1 %28, label %29, label %31
29: ; preds = %26, %23
%30 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %34
31: ; preds = %26
%32 = load i64, i64* %5
%33 = trunc i64 %32 to i32
store i32 %33, i32* %2
br label %37
34: ; preds = %29
br label %35
35: ; preds = %34, %21
br label %36
36: ; preds = %35, %11
store i32 -1, i32* %2
br label %37
37: ; preds = %36, %31
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@LONG_MAX = global i64 0
@.str.2 = [13 x i8] c"Out of range\00"
@str = [23 x i8] c"Invalid character type\00"
@str.3 = [14 x i8] c"Value invalid\00"
define i32 @string_handler(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtol(i8* %0, i8** %2, i32 10)
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, %0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.3, i64 0, i64 0))
br label %21
9: ; preds = %1
%10 = load i64, i64* @LONG_MAX
%11 = icmp eq i64 %4, %10
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %21
14: ; preds = %9
%15 = add i64 %4, -128
%16 = icmp ult i64 %15, -255
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %21
19: ; preds = %14
%20 = trunc i64 %4 to i32
br label %21
21: ; preds = %7, %17, %12, %19
%22 = phi i32 [ %20, %19 ], [ -1, %12 ], [ -1, %17 ], [ -1, %7 ]
ret i32 %22
}