#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*/ ERANGE;
long INT_MAX;
long INT_MIN;
int /*<<< orphan*/ errno;
long strtol(char const *, int /*<<< orphan*/ *, int /*<<< orphan*/);
void dhcpcd_strtoi(int *val, const char *s) {
  long l;
  l = strtol(s, NULL, 0);
  if (l >= INT_MIN && l <= INT_MAX)
    *val = (int)l;
  else
    errno = ERANGE;
}


x86 assembly (clang, -O0):
<dhcpcd_strtoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2ea2(%rip),%rcx
cmp    (%rcx),%rax
jl     116c <dhcpcd_strtoi+0x5c>
mov    -0x18(%rbp),%rax
mov    0x2e96(%rip),%rcx
cmp    (%rcx),%rax
jg     116c <dhcpcd_strtoi+0x5c>
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    117e <dhcpcd_strtoi+0x6e>
mov    0x2e65(%rip),%rax
mov    (%rax),%ecx
mov    0x2e4c(%rip),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dhcpcd_strtoi>:
push   %rbx
mov    %rdi,%rbx
mov    %rsi,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    0x2eb9(%rip),%rcx
cmp    (%rcx),%rax
jl     113c <dhcpcd_strtoi+0x2c>
mov    0x2eb5(%rip),%rcx
cmp    (%rcx),%rax
jg     113c <dhcpcd_strtoi+0x2c>
mov    %eax,(%rbx)
pop    %rbx
ret
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    0x2e7c(%rip),%rcx
mov    %eax,(%rcx)
pop    %rbx
ret

LLVM IR (-O0):
@INT_MIN = global i64 0
@INT_MAX = global i64 0
@ERANGE = global i32 0
@errno = global i32 0
define void @dhcpcd_strtoi(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
store i32* %0, i32** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i64 @strtol(i8* %6, i32* null, i32 0)
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = load i64, i64* @INT_MIN
%10 = icmp sge i64 %8, %9
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i64, i64* %5
%13 = load i64, i64* @INT_MAX
%14 = icmp sle i64 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i64, i64* %5
%17 = trunc i64 %16 to i32
%18 = load i32*, i32** %3
store i32 %17, i32* %18
br label %21
19: ; preds = %11, %2
%20 = load i32, i32* @ERANGE
store i32 %20, i32* @errno
br label %21
21: ; preds = %19, %15
ret void
}

LLVM IR (-O2):
@INT_MIN = global i64 0
@INT_MAX = global i64 0
@ERANGE = global i32 0
@errno = global i32 0
define void @dhcpcd_strtoi(i32* nocapture writeonly %0, i8* nocapture %1) {
%3 = tail call i64 @strtol(i8* nocapture %1, i32* null, i32 0)
%4 = load i64, i64* @INT_MIN
%5 = icmp slt i64 %3, %4
%6 = load i64, i64* @INT_MAX
%7 = icmp sgt i64 %3, %6
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = trunc i64 %3 to i32
store i32 %10, i32* %0
br label %13
11: ; preds = %2
%12 = load i32, i32* @ERANGE
store i32 %12, i32* @errno
br label %13
13: ; preds = %11, %9
ret void
}