#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 const *);
scalar_t__ isdigit(char const);
scalar_t__ isspace(char const);
int argtonum(const char *arg) {
  if (arg) {
    while (isspace(*arg))
      arg++;
    if (isdigit(*arg))
      return atoi(arg);
  }
  return -1;
}


x86 assembly (clang, -O0):
<argtonum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119f <argtonum+0x6f>
jmp    114c <argtonum+0x1c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1173 <argtonum+0x43>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    114c <argtonum+0x1c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     119a <argtonum+0x6a>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    11a6 <argtonum+0x76>
jmp    119f <argtonum+0x6f>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argtonum>:
push   %rbx
test   %rdi,%rdi
je     1168 <argtonum+0x38>
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
nopl   (%rax)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <isspace@plt>
test   %rax,%rax
jne    1140 <argtonum+0x10>
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1168 <argtonum+0x38>
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <atoi@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @argtonum(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 %6, label %24
6: ; preds = %1
br label %7
7: ; preds = %12, %6
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = call i64 @isspace(i8 signext %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %3
br label %7
15: ; preds = %7
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = call i64 @isdigit(i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %2
br label %25
23: ; preds = %15
br label %24
24: ; preds = %23, %1
store i32 -1, i32* %2
br label %25
25: ; preds = %24, %20
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @argtonum(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %15, label %3
3: ; preds = %1, %3
%4 = phi i8* [ %8, %3 ], [ %0, %1 ]
%5 = load i8, i8* %4
%6 = tail call i64 @isspace(i8 signext %5)
%7 = icmp eq i64 %6, 0
%8 = getelementptr inbounds i8, i8* %4, i64 1
br i1 %7, label %9, label %3
9: ; preds = %3
%10 = load i8, i8* %4
%11 = tail call i64 @isdigit(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 @atoi(i8* %4)
br label %15
15: ; preds = %1, %9, %13
%16 = phi i32 [ %14, %13 ], [ -1, %9 ], [ -1, %1 ]
ret i32 %16
}