#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__ strtoul(char const *, char **, int);
long strtol(const char *pszString, char **ppszEnd, int iBase) {
  int iSign = 0;
  long l;
  while (*pszString == ' ')
    pszString++;
  if (*pszString == '-') {
    pszString++;
    iSign = 1;
  }
  l = (long)strtoul(pszString, ppszEnd, iBase);
  if (iSign)
    l = -l;
  return l;
}


x86 assembly (clang, -O0):
<strtol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    114b <strtol+0x3b>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112a <strtol+0x1a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    116e <strtol+0x5e>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strtoul@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1196 <strtol+0x86>
xor    %eax,%eax
sub    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtol>:
push   %rbx
add    $0xffffffffffffffff,%rdi
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x1(%rdi),%ebx
add    $0x1,%rdi
cmp    $0x20,%bl
je     1120 <strtol+0x10>
xor    %eax,%eax
cmp    $0x2d,%bl
sete   %al
add    %rax,%rdi
call   1030 <strtoul@plt>
mov    %rax,%rcx
neg    %rcx
cmp    $0x2d,%bl
cmove  %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @strtol(i8* %0, i8** %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %14, %3
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 32
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %4
br label %9
17: ; preds = %9
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 45
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
store i32 1, i32* %7
br label %25
25: ; preds = %22, %17
%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* %8
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i64, i64* %8
%34 = sub nsw i64 0, %33
store i64 %34, i64* %8
br label %35
35: ; preds = %32, %25
%36 = load i64, i64* %8
ret i64 %36
}

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 ], [ %8, %4 ]
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 32
%8 = getelementptr inbounds i8, i8* %5, i64 1
br i1 %7, label %4, label %9
9: ; preds = %4
%10 = icmp eq i8 %6, 45
%11 = zext i1 %10 to i64
%12 = getelementptr i8, i8* %5, i64 %11
%13 = tail call i64 @strtoul(i8* %12, i8** %1, i32 %2)
%14 = sub nsw i64 0, %13
%15 = select i1 %10, i64 %14, i64 %13
ret i64 %15
}