#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 */
long long buftoll(unsigned char const *, int, int *);
long long buftoll_range(const unsigned char *nptr, int size, long long minval,
                        long long maxval, int *err) {
  long long value;
  value = buftoll(nptr, size, err);
  if (*err)
    return 0;
  if (value < minval || value > maxval) {
    *err = 109;
    return 0;
  }
  return value;
}


x86 assembly (clang, -O0):
<buftoll_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1030 <buftoll@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
cmpl   $0x0,(%rax)
je     1159 <buftoll_range+0x49>
movq   $0x0,-0x8(%rbp)
jmp    1194 <buftoll_range+0x84>
mov    -0x38(%rbp),%rax
cmp    -0x20(%rbp),%rax
jl     1175 <buftoll_range+0x65>
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
jle    118c <buftoll_range+0x7c>
mov    -0x30(%rbp),%rax
movl   $0x6d,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    1194 <buftoll_range+0x84>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buftoll_range>:
push   %r15
push   %r14
push   %rbx
mov    %r8,%rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %r8,%rdx
call   1030 <buftoll@plt>
cmpl   $0x0,(%rbx)
jne    113b <buftoll_range+0x2b>
cmp    %r15,%rax
jl     1135 <buftoll_range+0x25>
cmp    %r14,%rax
jle    113d <buftoll_range+0x2d>
movl   $0x6d,(%rbx)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @buftoll_range(i8* %0, i32 %1, i64 %2, i64 %3, i32* %4) {
%6 = tail call i64 @buftoll(i8* %0, i32 %1, i32* %4)
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %5
%10 = icmp slt i64 %6, %2
%11 = icmp sgt i64 %6, %3
%12 = or i1 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 109, i32* %4
br label %14
14: ; preds = %9, %5, %13
%15 = phi i64 [ 0, %13 ], [ 0, %5 ], [ %6, %9 ]
ret i64 %15
}