#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__ strtol(char const *, char **, int);
int /*<<< orphan*/ zc_error_prev_line(char *, char const *, int, int);
int parse_int(const char *str, char **end, int *result, const char *name,
              int min, int max) {
  *result = (int)strtol(str, end, 10);
  if (*result < min || *result > max) {
    zc_error_prev_line("%s must be within the range [%d .. %d]", name, min,
                       max);
    return 0;
  } else {
    return 1;
  }
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9d,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
cmp    -0x2c(%rbp),%eax
jl     1178 <parse_int+0x58>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
cmp    -0x30(%rbp),%eax
jle    119a <parse_int+0x7a>
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
lea    0xe77(%rip),%rdi
call   1030 <zc_error_prev_line@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a1 <parse_int+0x81>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r9d,%r15d
mov    %r8d,%ebp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
mov    %ecx,(%rbx)
cmp    %ebp,%ecx
jl     1150 <parse_int+0x30>
mov    $0x1,%eax
cmp    %r15d,%ecx
jle    1166 <parse_int+0x46>
lea    0xea9(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %r15d,%ecx
call   1030 <zc_error_prev_line@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"%s must be within the range [%d .. %d]\00"
define i32 @parse_int(i8* %0, i8** %1, i32* %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %8
store i8** %1, i8*** %9
store i32* %2, i32** %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%14 = load i8*, i8** %8
%15 = load i8**, i8*** %9
%16 = call i64 @strtol(i8* %14, i8** %15, i32 10)
%17 = trunc i64 %16 to i32
%18 = load i32*, i32** %10
store i32 %17, i32* %18
%19 = load i32*, i32** %10
%20 = load i32, i32* %19
%21 = load i32, i32* %12
%22 = icmp slt i32 %20, %21
br i1 %22, label %28, label %23
23: ; preds = %6
%24 = load i32*, i32** %10
%25 = load i32, i32* %24
%26 = load i32, i32* %13
%27 = icmp sgt i32 %25, %26
br i1 %27, label %28, label %33
28: ; preds = %23, %6
%29 = load i8*, i8** %11
%30 = load i32, i32* %12
%31 = load i32, i32* %13
%32 = call i32 @zc_error_prev_line(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %29, i32 %30, i32 %31)
store i32 0, i32* %7
br label %34
33: ; preds = %23
store i32 1, i32* %7
br label %34
34: ; preds = %33, %28
%35 = load i32, i32* %7
ret i32 %35
}

LLVM IR (-O2):
@.str = [39 x i8] c"%s must be within the range [%d .. %d]\00"
define i32 @parse_int(i8* %0, i8** nocapture %1, i32* nocapture writeonly %2, i8* %3, i32 %4, i32 %5) {
%7 = tail call i64 @strtol(i8* %0, i8** %1, i32 10)
%8 = trunc i64 %7 to i32
store i32 %8, i32* %2
%9 = icmp slt i32 %8, %4
%10 = icmp sgt i32 %8, %5
%11 = or i1 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = tail call i32 @zc_error_prev_line(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %4, i32 %5)
br label %14
14: ; preds = %6, %12
%15 = phi i32 [ 0, %12 ], [ 1, %6 ]
ret i32 %15
}