#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__ isdigit(char);
int strlen(char *);
long atol(char *string) {
  static long value, lv;
  static char *p;
  value = 0L;
  p = string + strlen(string);
  while (!isdigit(*p))
    p--;
  for (lv = 1L; isdigit(*p) && p >= string; lv *= 10)
    value += ((*p--) - '0') * lv;
  return value;
}


x86 assembly (clang, -O0):
<atol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,0x2f01(%rip)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,0x2eed(%rip)
mov    0x2ee6(%rip),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1180 <atol+0x60>
jmp    1197 <atol+0x77>
mov    0x2ec1(%rip),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,0x2eb6(%rip)
jmp    115b <atol+0x3b>
movq   $0x1,0x2e9e(%rip)
mov    0x2e9f(%rip),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
je     11d4 <atol+0xb4>
mov    0x2e7e(%rip),%rax
cmp    -0x8(%rbp),%rax
setae  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11e4 <atol+0xc4>
jmp    122b <atol+0x10b>
mov    0x2e5d(%rip),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x2e4f(%rip)
movsbl (%rax),%eax
sub    $0x30,%eax
cltq
imul   0x2e37(%rip),%rax
add    0x2e28(%rip),%rax
mov    %rax,0x2e21(%rip)
imul   $0xa,0x2e21(%rip),%rax
0a
mov    %rax,0x2e1a(%rip)
jmp    11a2 <atol+0x82>
mov    0x2e06(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atol>:
push   %rbx
mov    %rdi,%rbx
movq   $0x0,0x2f09(%rip)
call   1040 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rcx
mov    %rcx,0x2f07(%rip)
movsbl (%rbx,%rax,1),%edi
cs nopw 0x0(%rax,%rax,1)
nop
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1172 <atol+0x52>
mov    0x2ee7(%rip),%rax
lea    -0x1(%rax),%rcx
mov    %rcx,0x2edc(%rip)
movsbl -0x1(%rax),%edi
jmp    1150 <atol+0x30>
movq   $0x1,0x2ec3(%rip)
mov    0x2ec4(%rip),%rax
movsbl (%rax),%edi
nopw   0x0(%rax,%rax,1)
call   1030 <isdigit@plt>
test   %rax,%rax
je     11df <atol+0xbf>
mov    0x2ea7(%rip),%rax
cmp    %rbx,%rax
jb     11df <atol+0xbf>
lea    -0x1(%rax),%rcx
mov    %rcx,0x2e97(%rip)
movsbq (%rax),%rcx
add    $0xffffffffffffffd0,%rcx
mov    0x2e80(%rip),%rdx
imul   %rdx,%rcx
add    %rcx,0x2e6d(%rip)
add    %rdx,%rdx
lea    (%rdx,%rdx,4),%rcx
mov    %rcx,0x2e67(%rip)
movsbl -0x1(%rax),%edi
jmp    1190 <atol+0x70>
mov    0x2e52(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@atol.value = internal global i64 0
@atol.lv = internal global i64 0
@atol.p = internal global i8* null
define i64 @atol(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* @atol.value
%3 = load i8*, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %3, i64 %6
store i8* %7, i8** @atol.p
br label %8
8: ; preds = %14, %1
%9 = load i8*, i8** @atol.p
%10 = load i8, i8* %9
%11 = call i64 @isdigit(i8 signext %10)
%12 = icmp ne i64 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i8*, i8** @atol.p
%16 = getelementptr inbounds i8, i8* %15, i32 -1
store i8* %16, i8** @atol.p
br label %8
17: ; preds = %8
store i64 1, i64* @atol.lv
br label %18
18: ; preds = %40, %17
%19 = load i8*, i8** @atol.p
%20 = load i8, i8* %19
%21 = call i64 @isdigit(i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i8*, i8** @atol.p
%25 = load i8*, i8** %2
%26 = icmp uge i8* %24, %25
br label %27
27: ; preds = %23, %18
%28 = phi i1 [ false, %18 ], [ %26, %23 ]
br i1 %28, label %29, label %43
29: ; preds = %27
%30 = load i8*, i8** @atol.p
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** @atol.p
%32 = load i8, i8* %30
%33 = sext i8 %32 to i32
%34 = sub nsw i32 %33, 48
%35 = sext i32 %34 to i64
%36 = load i64, i64* @atol.lv
%37 = mul nsw i64 %35, %36
%38 = load i64, i64* @atol.value
%39 = add nsw i64 %38, %37
store i64 %39, i64* @atol.value
br label %40
40: ; preds = %29
%41 = load i64, i64* @atol.lv
%42 = mul nsw i64 %41, 10
store i64 %42, i64* @atol.lv
br label %18
43: ; preds = %27
%44 = load i64, i64* @atol.value
ret i64 %44
}

LLVM IR (-O2):
@atol.value = internal unnamed_addr global i64 0
@atol.lv = internal unnamed_addr global i64 0
@atol.p = internal unnamed_addr global i8* null
define i64 @atol(i8* %0) {
store i64 0, i64* @atol.value
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
store i8* %4, i8** @atol.p
%5 = load i8, i8* %4
%6 = tail call i64 @isdigit(i8 signext %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %16, %1
store i64 1, i64* @atol.lv
%9 = load i8*, i8** @atol.p
%10 = load i8, i8* %9
%11 = tail call i64 @isdigit(i8 signext %10)
%12 = icmp ne i64 %11, 0
%13 = load i8*, i8** @atol.p
%14 = icmp uge i8* %13, %0
%15 = select i1 %12, i1 %14, i1 false
br i1 %15, label %22, label %39
16: ; preds = %1, %16
%17 = load i8*, i8** @atol.p
%18 = getelementptr inbounds i8, i8* %17, i64 -1
store i8* %18, i8** @atol.p
%19 = load i8, i8* %18
%20 = tail call i64 @isdigit(i8 signext %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %16, label %8
22: ; preds = %8, %22
%23 = phi i8* [ %36, %22 ], [ %13, %8 ]
%24 = getelementptr inbounds i8, i8* %23, i64 -1
store i8* %24, i8** @atol.p
%25 = load i8, i8* %23
%26 = sext i8 %25 to i64
%27 = add nsw i64 %26, -48
%28 = load i64, i64* @atol.lv
%29 = mul nsw i64 %27, %28
%30 = load i64, i64* @atol.value
%31 = add nsw i64 %29, %30
store i64 %31, i64* @atol.value
%32 = mul nsw i64 %28, 10
store i64 %32, i64* @atol.lv
%33 = load i8, i8* %24
%34 = tail call i64 @isdigit(i8 signext %33)
%35 = icmp ne i64 %34, 0
%36 = load i8*, i8** @atol.p
%37 = icmp uge i8* %36, %0
%38 = select i1 %35, i1 %37, i1 false
br i1 %38, label %22, label %39
39: ; preds = %22, %8
%40 = load i64, i64* @atol.value
ret i64 %40
}