#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__ errno;
scalar_t__ isspace(char);
long strtol(char const *, char **, int);
int parse_long(const char *s, long *val) {
  char *end;
  errno = 0;
  *val = strtol(s, &end, 10);
  if ((end == s) || (errno != 0)) {
    return 0;
  }
  while (isspace(*end))
    end++;
  if (*end != '\0') {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<parse_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ea9(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1179 <parse_long+0x59>
mov    0x2e71(%rip),%rax
cmpq   $0x0,(%rax)
je     1185 <parse_long+0x65>
movl   $0x0,-0x4(%rbp)
jmp    11d4 <parse_long+0xb4>
jmp    118a <parse_long+0x6a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     11b1 <parse_long+0x91>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    118a <parse_long+0x6a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11cd <parse_long+0xad>
movl   $0x0,-0x4(%rbp)
jmp    11d4 <parse_long+0xb4>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_long>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2eab(%rip),%r12
movq   $0x0,(%r12)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,(%r14)
mov    (%rsp),%rbx
xor    %eax,%eax
cmp    %r15,%rbx
je     117a <parse_long+0x5a>
cmpq   $0x0,(%r12)
jne    117a <parse_long+0x5a>
nop
movsbl (%rbx),%edi
call   1030 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1160 <parse_long+0x40>
xor    %eax,%eax
cmpb   $0x0,-0x1(%rbx)
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@errno = global i64 0
define i32 @parse_long(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%5 = call i64 @strtol(i8* %0, i8** %3, i32 10)
store i64 %5, i64* %1
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, %0
%8 = load i64, i64* @errno
%9 = icmp ne i64 %8, 0
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %21, label %11
11: ; preds = %2, %11
%12 = phi i8* [ %16, %11 ], [ %6, %2 ]
%13 = load i8, i8* %12
%14 = tail call i64 @isspace(i8 signext %13)
%15 = icmp eq i64 %14, 0
%16 = getelementptr inbounds i8, i8* %12, i64 1
br i1 %15, label %17, label %11
17: ; preds = %11
%18 = load i8, i8* %12
%19 = icmp eq i8 %18, 0
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %17, %2
%22 = phi i32 [ 0, %2 ], [ %20, %17 ]
ret i32 %22
}