#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 */
scalar_t__ ioutil_errno(int);
scalar_t__ isspace(int);
scalar_t__ strtol(char const *, char **, int);
int /*<<< orphan*/ util_check_null_string(char *);
int arg_to_int(const char *arg, int *return_value) {
  char *tailptr;
  int counter = 0;
  *return_value = (int)strtol(arg, &tailptr, 10);
  if (ioutil_errno(4))
    return -1;
  if (!util_check_null_string(tailptr)) {
    while (isspace((int)tailptr[counter]))
      counter++;
    tailptr += counter;
    if (*tailptr != 0)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<arg_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x4,%edi
call   1060 <ioutil_errno@plt>
cmp    $0x0,%rax
je     1191 <arg_to_int+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <arg_to_int+0xca>
mov    -0x20(%rbp),%rdi
call   1050 <util_check_null_string@plt>
cmp    $0x0,%eax
jne    1203 <arg_to_int+0xc3>
jmp    11a8 <arg_to_int+0x68>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     11d1 <arg_to_int+0x91>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a8 <arg_to_int+0x68>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11fe <arg_to_int+0xbe>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <arg_to_int+0xca>
jmp    1203 <arg_to_int+0xc3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arg_to_int>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,(%rbx)
mov    $0x4,%edi
call   1060 <ioutil_errno@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
jne    11ae <arg_to_int+0x6e>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <util_check_null_string@plt>
test   %eax,%eax
jne    11ab <arg_to_int+0x6b>
mov    $0xffffffffffffffff,%rbp
nopl   0x0(%rax)
movsbl 0x1(%rbx,%rbp,1),%edi
call   1030 <isspace@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    1190 <arg_to_int+0x50>
mov    %ebp,%eax
cmpb   $0x0,(%rbx,%rax,1)
jne    11ae <arg_to_int+0x6e>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @arg_to_int(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = call i64 @strtol(i8* %8, i8** %6, i32 10)
%10 = trunc i64 %9 to i32
%11 = load i32*, i32** %5
store i32 %10, i32* %11
%12 = call i64 @ioutil_errno(i32 4)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %44
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = call i32 @util_check_null_string(i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %43, label %19
19: ; preds = %15
br label %20
20: ; preds = %29, %19
%21 = load i8*, i8** %6
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = call i64 @isspace(i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %20
32: ; preds = %20
%33 = load i32, i32* %7
%34 = load i8*, i8** %6
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8* %36, i8** %6
%37 = load i8*, i8** %6
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %32
store i32 -1, i32* %3
br label %44
42: ; preds = %32
br label %43
43: ; preds = %42, %15
store i32 0, i32* %3
br label %44
44: ; preds = %43, %41, %14
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
define i32 @arg_to_int(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtol(i8* %0, i8** %3, i32 10)
%6 = trunc i64 %5 to i32
store i32 %6, i32* %1
%7 = tail call i64 @ioutil_errno(i32 4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %27
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = tail call i32 @util_check_null_string(i8* %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %9, %13
%14 = phi i64 [ %20, %13 ], [ 0, %9 ]
%15 = getelementptr inbounds i8, i8* %10, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = tail call i64 @isspace(i32 %17)
%19 = icmp eq i64 %18, 0
%20 = add nuw i64 %14, 1
br i1 %19, label %21, label %13
21: ; preds = %13
%22 = and i64 %14, 4294967295
%23 = getelementptr inbounds i8, i8* %10, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21, %9
br label %27
27: ; preds = %21, %2, %26
%28 = phi i32 [ 0, %26 ], [ -1, %2 ], [ -1, %21 ]
ret i32 %28
}