#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 strtoul(char const *, char **, int /*<<< orphan*/);
int get_int(const char **text, int *value, int min, int max) {
  char *end;
  *value = strtoul(*text, &end, 0);
  if (end == *text)
    return -1;
  if (*value < min || *value > max)
    return -1;
  *text = end;
  return 0;
}


x86 assembly (clang, -O0):
<get_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jne    115d <get_int+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <get_int+0x89>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x1c(%rbp),%eax
jl     117b <get_int+0x6b>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x20(%rbp),%eax
jle    1187 <get_int+0x77>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <get_int+0x89>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_int>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    (%rdi),%rdi
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    %eax,%ecx
mov    %eax,0x0(%rbp)
mov    (%rsp),%rdx
mov    $0xffffffff,%eax
cmp    (%rbx),%rdx
je     1152 <get_int+0x42>
cmp    %r15d,%ecx
jl     1152 <get_int+0x42>
cmp    %r14d,%ecx
jg     1152 <get_int+0x42>
mov    %rdx,(%rbx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @get_int(i8** nocapture %0, i32* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = load i8*, i8** %0
%8 = call i32 @strtoul(i8* %7, i8** %5, i32 0)
store i32 %8, i32* %1
%9 = load i8*, i8** %5
%10 = load i8*, i8** %0
%11 = icmp eq i8* %9, %10
br i1 %11, label %17, label %12
12: ; preds = %4
%13 = icmp slt i32 %8, %2
%14 = icmp sgt i32 %8, %3
%15 = or i1 %13, %14
br i1 %15, label %17, label %16
16: ; preds = %12
store i8* %9, i8** %0
br label %17
17: ; preds = %12, %4, %16
%18 = phi i32 [ 0, %16 ], [ -1, %4 ], [ -1, %12 ]
ret i32 %18
}