#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*/ safe_sprintf(char *, char **, char *, char const *, int, int,
                                int);
int fn_range_check(const char *fname, int nfargs, int minargs, int maxargs,
                   char *result, char **bufc) {
  if ((nfargs >= minargs) && (nfargs <= maxargs)) {
    return 1;
  }
  if (maxargs == (minargs + 1))
    safe_sprintf(result, bufc,
                 "#-1 FUNCTION (%s) EXPECTS %d OR %d ARGUMENTS BUT GOT %d",
                 fname, minargs, maxargs, nfargs);
  else
    safe_sprintf(
        result, bufc,
        "#-1 FUNCTION (%s) EXPECTS BETWEEN %d AND %d ARGUMENTS BUT GOT %d",
        fname, minargs, maxargs, nfargs);
  return 0;
}


x86 assembly (clang, -O0):
<fn_range_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     1151 <fn_range_check+0x41>
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1151 <fn_range_check+0x41>
movl   $0x1,-0x4(%rbp)
jmp    11ba <fn_range_check+0xaa>
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    118d <fn_range_check+0x7d>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x14(%rbp),%eax
lea    0xe80(%rip),%rdx
mov    %eax,(%rsp)
call   1030 <safe_sprintf@plt>
jmp    11b3 <fn_range_check+0xa3>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x14(%rbp),%eax
lea    0xe8d(%rip),%rdx
mov    %eax,(%rsp)
call   1030 <safe_sprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fn_range_check>:
mov    %ecx,%r10d
mov    %edx,%r11d
mov    %rdi,%rcx
cmp    %edx,%esi
jl     1128 <fn_range_check+0x18>
mov    $0x1,%eax
cmp    %r10d,%esi
jg     1128 <fn_range_check+0x18>
ret
push   %rax
lea    0x1(%r11),%eax
cmp    %r10d,%eax
lea    0xec9(%rip),%rax
lea    0xefa(%rip),%rdx
cmove  %rax,%rdx
mov    %esi,(%rsp)
mov    %r8,%rdi
mov    %r9,%rsi
mov    %r11d,%r8d
mov    %r10d,%r9d
call   1030 <safe_sprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
@.str = [56 x i8] c"#-1 FUNCTION (%s) EXPECTS %d OR %d ARGUMENTS BUT GOT %d\00"
@.str.1 = [65 x i8] c"#-1 FUNCTION (%s) EXPECTS BETWEEN %d AND %d ARGUMENTS BUT GOT %d\00"
define i32 @fn_range_check(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4, i8** %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8**
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i8** %5, i8*** %13
%14 = load i32, i32* %9
%15 = load i32, i32* %10
%16 = icmp sge i32 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %6
%18 = load i32, i32* %9
%19 = load i32, i32* %11
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 1, i32* %7
br label %44
22: ; preds = %17, %6
%23 = load i32, i32* %11
%24 = load i32, i32* %10
%25 = add nsw i32 %24, 1
%26 = icmp eq i32 %23, %25
br i1 %26, label %27, label %35
27: ; preds = %22
%28 = load i8*, i8** %12
%29 = load i8**, i8*** %13
%30 = load i8*, i8** %8
%31 = load i32, i32* %10
%32 = load i32, i32* %11
%33 = load i32, i32* %9
%34 = call i32 @safe_sprintf(i8* %28, i8** %29, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %30, i32 %31, i32 %32, i32 %33)
br label %43
35: ; preds = %22
%36 = load i8*, i8** %12
%37 = load i8**, i8*** %13
%38 = load i8*, i8** %8
%39 = load i32, i32* %10
%40 = load i32, i32* %11
%41 = load i32, i32* %9
%42 = call i32 @safe_sprintf(i8* %36, i8** %37, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i8* %38, i32 %39, i32 %40, i32 %41)
br label %43
43: ; preds = %35, %27
store i32 0, i32* %7
br label %44
44: ; preds = %43, %21
%45 = load i32, i32* %7
ret i32 %45
}

LLVM IR (-O2):
@.str = [56 x i8] c"#-1 FUNCTION (%s) EXPECTS %d OR %d ARGUMENTS BUT GOT %d\00"
@.str.1 = [65 x i8] c"#-1 FUNCTION (%s) EXPECTS BETWEEN %d AND %d ARGUMENTS BUT GOT %d\00"
define i32 @fn_range_check(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4, i8** %5) {
%7 = icmp slt i32 %1, %2
%8 = icmp sgt i32 %1, %3
%9 = or i1 %7, %8
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = add nsw i32 %2, 1
%12 = icmp eq i32 %11, %3
%13 = select i1 %12, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0)
%14 = tail call i32 @safe_sprintf(i8* %4, i8** %5, i8* %13, i8* %0, i32 %2, i32 %3, i32 %1)
br label %15
15: ; preds = %10, %6
%16 = phi i32 [ 1, %6 ], [ 0, %10 ]
ret i32 %16
}