#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 */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           scalar_t__);
int /*<<< orphan*/ stderr;
scalar_t__ strtol(char const *, int /*<<< orphan*/ *, int);
int to_int(const char *s) {
  int val;
  errno = 0;
  val = (int)strtol(s, NULL, 10);
  if (errno != 0) {
    fprintf(stderr, "*** Can\'t read string \'%s\' as an int; errno = %d ***\n",
            s, errno);
    errno = 0;
    exit(EXIT_FAILURE);
  }
  return val;
}


x86 assembly (clang, -O0):
<to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e72(%rip),%rax
cmpq   $0x0,(%rax)
je     11af <to_int+0x7f>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    0x2e54(%rip),%rax
mov    (%rax),%rcx
lea    0xe72(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e3e(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_int>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e9a(%rip),%r14
movq   $0x0,(%r14)
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    (%r14),%rcx
test   %rcx,%rcx
jne    1161 <to_int+0x31>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
movq   $0x0,(%r14)
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [54 x i8] c"*** Can't read string '%s' as an int; errno = %d ***\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @to_int(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i64 0, i64* @errno
%4 = load i8*, i8** %2
%5 = call i64 @strtol(i8* %4, i32* null, i32 10)
%6 = trunc i64 %5 to i32
store i32 %6, i32* %3
%7 = load i64, i64* @errno
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %2
%12 = load i64, i64* @errno
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %11, i64 %12)
store i64 0, i64* @errno
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
%17 = load i32, i32* %3
ret i32 %17
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [54 x i8] c"*** Can't read string '%s' as an int; errno = %d ***\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @to_int(i8* %0) {
store i64 0, i64* @errno
%2 = tail call i64 @strtol(i8* nocapture %0, i32* null, i32 10)
%3 = load i64, i64* @errno
%4 = icmp eq i64 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %3)
store i64 0, i64* @errno
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %1
%11 = trunc i64 %2 to i32
ret i32 %11
}