#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__ isspace(char const);
scalar_t__ strtoul(char const *, char **, int);
long int strtol(const char *nptr, char **endptr, int base) {
  const char *ptr;
  unsigned short negative;
  long int number;
  ptr = nptr;
  while (isspace(*ptr))
    ptr++;
  negative = 0;
  if (*ptr == '-')
    negative = 1;
  number = (long int)strtoul(nptr, endptr, base);
  return (negative ? -number : number);
}


x86 assembly (clang, -O0):
<strtol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     1162 <strtol+0x42>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113b <strtol+0x1b>
movw   $0x0,-0x22(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    117e <strtol+0x5e>
movw   $0x1,-0x22(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <strtoul@plt>
mov    %rax,-0x30(%rbp)
movzwl -0x22(%rbp),%eax
cmp    $0x0,%eax
je     11ae <strtol+0x8e>
xor    %eax,%eax
sub    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    11b6 <strtol+0x96>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtol>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rdi,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl 0x0(%rbp),%edi
call   1030 <isspace@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    1140 <strtol+0x20>
mov    -0x1(%rbp),%bpl
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <strtoul@plt>
mov    %rax,%rcx
neg    %rcx
cmp    $0x2d,%bpl
cmove  %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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