#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*/ error();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
long strtol(char const *, char **, int /*<<< orphan*/);
long chk_strtol(const char *s) {
  long value;
  char *end;
  errno = 0;
  value = strtol(s, &end, 0);
  if (errno || *end != 0) {
    fprintf(stderr, "Error: Bad numeral: %s\n", s);
    error();
  }
  return value;
}


x86 assembly (clang, -O0):
<chk_strtol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e74(%rip),%rax
cmpq   $0x0,(%rax)
jne    117e <chk_strtol+0x4e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     119e <chk_strtol+0x6e>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe6e(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x0,%al
call   1050 <error@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chk_strtol>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e95(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%r14
cmpq   $0x0,(%r15)
jne    1169 <chk_strtol+0x39>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     1188 <chk_strtol+0x58>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
xor    %eax,%eax
call   1050 <error@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [24 x i8] c"Error: Bad numeral: %s\0A\00"
define i64 @chk_strtol(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* @errno
%5 = load i8*, i8** %2
%6 = call i64 @strtol(i8* %5, i8** %4, i32 0)
store i64 %6, i64* %3
%7 = load i64, i64* @errno
%8 = icmp ne i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %9, %1
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %2
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 (...) @error()
br label %19
19: ; preds = %14, %9
%20 = load i64, i64* %3
ret i64 %20
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [24 x i8] c"Error: Bad numeral: %s\0A\00"
define i64 @chk_strtol(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i64 0, i64* @errno
%4 = call i64 @strtol(i8* %0, i8** %2, i32 0)
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %7, %1
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%14 = tail call i32 (...) @error()
br label %15
15: ; preds = %11, %7
ret i64 %4
}