#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;
long strtol(char const *, char **, int);
int /*<<< orphan*/ usage(int /*<<< orphan*/);
int parse_int(const char *str, int min, int max) {
  char *endptr = NULL;
  long chan = strtol(str, &endptr, 10);
  if (chan < min || chan > max || (endptr && *endptr != '\0'))
    usage(EXIT_FAILURE);
  return chan;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmp    %rcx,%rax
jl     118d <parse_int+0x6d>
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmp    %rcx,%rax
jg     118d <parse_int+0x6d>
cmpq   $0x0,-0x18(%rbp)
je     119b <parse_int+0x7b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     119b <parse_int+0x7b>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1040 <usage@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%rbx
movslq %ebp,%rax
cmp    %rax,%rbx
jl     1167 <parse_int+0x47>
movslq %r14d,%rax
cmp    %rax,%rbx
jg     1167 <parse_int+0x47>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     1175 <parse_int+0x55>
cmpb   $0x0,(%rax)
je     1175 <parse_int+0x55>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1040 <usage@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
define i32 @parse_int(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i8* null, i8** %7
%9 = load i8*, i8** %4
%10 = call i64 @strtol(i8* %9, i8** %7, i32 10)
store i64 %10, i64* %8
%11 = load i64, i64* %8
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = icmp slt i64 %11, %13
br i1 %14, label %28, label %15
15: ; preds = %3
%16 = load i64, i64* %8
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = icmp sgt i64 %16, %18
br i1 %19, label %28, label %20
20: ; preds = %15
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i8*, i8** %7
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %23, %15, %3
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @usage(i32 %29)
br label %31
31: ; preds = %28, %23, %20
%32 = load i64, i64* %8
%33 = trunc i64 %32 to i32
ret i32 %33
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
define i32 @parse_int(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%6 = call i64 @strtol(i8* %0, i8** %4, i32 10)
%7 = sext i32 %1 to i64
%8 = icmp slt i64 %6, %7
%9 = sext i32 %2 to i64
%10 = icmp sgt i64 %6, %9
%11 = or i1 %8, %10
br i1 %11, label %18, label %12
12: ; preds = %3
%13 = load i8*, i8** %4
%14 = icmp eq i8* %13, null
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = load i8, i8* %13
%17 = icmp eq i8 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15, %3
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @usage(i32 %19)
br label %21
21: ; preds = %18, %15, %12
%22 = trunc i64 %6 to i32
ret i32 %22
}