#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;
int /*<<< orphan*/ leprintf(char *);
long strtol(char *, char **, int);
long stol(char *s, char **endp) {
  long n;
  errno = 0;
  n = strtol(s, endp, 10);
  if (errno)
    leprintf("strtol:");
  if (*endp == s)
    leprintf("strtol: invalid number");
  return n;
}


x86 assembly (clang, -O0):
<stol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea9(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e85(%rip),%rax
cmpq   $0x0,(%rax)
je     1171 <stol+0x51>
lea    0xe94(%rip),%rdi
call   1030 <leprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    -0x8(%rbp),%rax
jne    118e <stol+0x6e>
lea    0xe7f(%rip),%rdi
call   1030 <leprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stol>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2eab(%rip),%r12
movq   $0x0,(%r12)
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%r14
cmpq   $0x0,(%r12)
je     115d <stol+0x3d>
lea    0xea8(%rip),%rdi
call   1030 <leprintf@plt>
cmp    %rbx,(%r15)
jne    116e <stol+0x4e>
lea    0xe9f(%rip),%rdi
call   1030 <leprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [8 x i8] c"strtol:\00"
@.str.1 = [23 x i8] c"strtol: invalid number\00"
define i64 @stol(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i64
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i64 0, i64* @errno
%6 = load i8*, i8** %3
%7 = load i8**, i8*** %4
%8 = call i64 @strtol(i8* %6, i8** %7, i32 10)
store i64 %8, i64* %5
%9 = load i64, i64* @errno
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @leprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i8**, i8*** %4
%15 = load i8*, i8** %14
%16 = load i8*, i8** %3
%17 = icmp eq i8* %15, %16
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @leprintf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = load i64, i64* %5
ret i64 %21
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [8 x i8] c"strtol:\00"
@.str.1 = [23 x i8] c"strtol: invalid number\00"
define i64 @stol(i8* %0, i8** nocapture %1) {
store i64 0, i64* @errno
%3 = tail call i64 @strtol(i8* %0, i8** %1, i32 10)
%4 = load i64, i64* @errno
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @leprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = load i8*, i8** %1
%10 = icmp eq i8* %9, %0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @leprintf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
ret i64 %3
}