#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*/ cf_err(char *);
scalar_t__ errno;
long strtol(char *, char **, int);
int cf_int(char *val) {
  char *end;
  errno = 0;
  long int x = strtol(val, &end, 10);
  if (errno || end == val || end && *end)
    cf_err("Invalid number");
  if ((long int)(int)x != x)
    cf_err("Number out of range");
  return x;
}


x86 assembly (clang, -O0):
<cf_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ead(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e89(%rip),%rax
cmpq   $0x0,(%rax)
jne    118a <cf_int+0x6a>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     118a <cf_int+0x6a>
cmpq   $0x0,-0x10(%rbp)
je     1196 <cf_int+0x76>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1196 <cf_int+0x76>
lea    0xe6f(%rip),%rdi
call   1040 <cf_err@plt>
mov    -0x18(%rbp),%rax
cltq
cmp    -0x18(%rbp),%rax
je     11b2 <cf_int+0x92>
lea    0xe62(%rip),%rdi
call   1040 <cf_err@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cf_int>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2ead(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%rbx
cmpq   $0x0,(%r15)
je     117e <cf_int+0x5e>
lea    0xea7(%rip),%rdi
call   1040 <cf_err@plt>
movslq %ebx,%rax
cmp    %rbx,%rax
je     1172 <cf_int+0x52>
lea    0xea2(%rip),%rdi
call   1040 <cf_err@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x8(%rsp),%rax
cmp    %r14,%rax
je     1152 <cf_int+0x32>
test   %rax,%rax
je     115e <cf_int+0x3e>
cmpb   $0x0,(%rax)
jne    1152 <cf_int+0x32>
jmp    115e <cf_int+0x3e>

LLVM IR (-O0):
@errno = global i64 0
@.str = [15 x i8] c"Invalid number\00"
@.str.1 = [20 x i8] c"Number out of range\00"
define i32 @cf_int(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* @errno
%5 = load i8*, i8** %2
%6 = call i64 @strtol(i8* %5, i8** %3, i32 10)
store i64 %6, i64* %4
%7 = load i64, i64* @errno
%8 = icmp ne i64 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8*, i8** %2
%12 = icmp eq i8* %10, %11
br i1 %12, label %21, label %13
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16, %9, %1
%22 = call i32 @cf_err(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %16, %13
%24 = load i64, i64* %4
%25 = trunc i64 %24 to i32
%26 = sext i32 %25 to i64
%27 = load i64, i64* %4
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 @cf_err(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %23
%32 = load i64, i64* %4
%33 = trunc i64 %32 to i32
ret i32 %33
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [15 x i8] c"Invalid number\00"
@.str.1 = [20 x i8] c"Number out of range\00"
define i32 @cf_int(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 10)
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = icmp eq i8* %8, %0
br i1 %9, label %15, label %10
10: ; preds = %7
%11 = icmp eq i8* %8, null
br i1 %11, label %17, label %12
12: ; preds = %10
%13 = load i8, i8* %8
%14 = icmp eq i8 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12, %7, %1
%16 = tail call i32 @cf_err(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %12, %10
%18 = add i64 %4, 2147483648
%19 = icmp ult i64 %18, 4294967296
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @cf_err(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = trunc i64 %4 to i32
ret i32 %23
}