int relabsd_util_parse_int(const char string[const restrict 1], const int min,
                           const int max, int output[const restrict 1]) {
  char *invalid_char;
  long int buffer;
  buffer = strtol(string, &invalid_char, 10);
  if ((invalid_char[0] != '\0') || (string[0] == '\0')) {
    return -1;
  }
  if ((buffer < ((long int)min)) || (buffer > ((long int)max))) {
    return -2;
  }
  *output = ((int)buffer);
  return 0;
}


x86 assembly (clang, -O0):
<relabsd_util_parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    115c <relabsd_util_parse_int+0x4c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1168 <relabsd_util_parse_int+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <relabsd_util_parse_int+0x99>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
jl     118a <relabsd_util_parse_int+0x7a>
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmp    %rcx,%rax
jle    1196 <relabsd_util_parse_int+0x86>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11a9 <relabsd_util_parse_int+0x99>
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<relabsd_util_parse_int>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%ebx
mov    %rdi,%rbp
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%rcx
mov    (%rsp),%rdx
mov    $0xffffffff,%eax
cmpb   $0x0,(%rdx)
je     114b <relabsd_util_parse_int+0x3b>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
cmpb   $0x0,0x0(%rbp)
je     1140 <relabsd_util_parse_int+0x30>
movslq %ebx,%rdx
mov    $0xfffffffe,%eax
cmp    %rdx,%rcx
jl     1140 <relabsd_util_parse_int+0x30>
movslq %r15d,%rdx
cmp    %rdx,%rcx
jg     1140 <relabsd_util_parse_int+0x30>
mov    %ecx,(%r14)
xor    %eax,%eax
jmp    1140 <relabsd_util_parse_int+0x30>

LLVM IR (-O0):
define i32 @relabsd_util_parse_int(i8* noalias %0, i32 %1, i32 %2, i32* noalias %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%12 = load i8*, i8** %6
%13 = call i64 @strtol(i8* %12, i8** %10, i32 10)
store i64 %13, i64* %11
%14 = load i8*, i8** %10
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %4
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19, %4
store i32 -1, i32* %5
br label %41
26: ; preds = %19
%27 = load i64, i64* %11
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %36, label %31
31: ; preds = %26
%32 = load i64, i64* %11
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = icmp sgt i64 %32, %34
br i1 %35, label %36, label %37
36: ; preds = %31, %26
store i32 -2, i32* %5
br label %41
37: ; preds = %31
%38 = load i64, i64* %11
%39 = trunc i64 %38 to i32
%40 = load i32*, i32** %9
store i32 %39, i32* %40
store i32 0, i32* %5
br label %41
41: ; preds = %37, %36, %25
%42 = load i32, i32* %5
ret i32 %42
}

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