#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__ EINVAL;
scalar_t__ ERANGE;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ stderr;
scalar_t__ strtoll(char *, int /*<<< orphan*/ *, int);
unsigned int get_uintval_from_arg(int argc, int index, char **argv,
                                  unsigned int lower_bound,
                                  unsigned int upper_bound) {
  unsigned int return_val = 0;
  if (index + 1 <= argc - 1) {
    return_val = (unsigned int)strtoll(argv[index + 1], NULL, 10);
    if (errno == EINVAL || errno == ERANGE) {
      fprintf(stderr, "Could not parse argument %s for switch %s!\n",
              argv[index], argv[index + 1]);
      return 0;
    }
  } else {
    fprintf(stderr, "too few arguments for option %s!\n", argv[index]);
    print_usage();
    return 0;
  }
  if (return_val < lower_bound || return_val > upper_bound) {
    fprintf(stderr, "%s must be between %u and %u!\n", argv[index], lower_bound,
            upper_bound);
    print_usage();
    return 0;
  }
  return return_val;
}


x86 assembly (clang, -O0):
<get_uintval_from_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     11ff <get_uintval_from_arg+0xcf>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1030 <strtoll@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%rax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%rax
je     11ba <get_uintval_from_arg+0x8a>
mov    0x2e29(%rip),%rax
mov    (%rax),%rax
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%rax
jne    11fa <get_uintval_from_arg+0xca>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1290 <get_uintval_from_arg+0x160>
jmp    1235 <get_uintval_from_arg+0x105>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1050 <print_usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1290 <get_uintval_from_arg+0x160>
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jb     124d <get_uintval_from_arg+0x11d>
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jbe    128a <get_uintval_from_arg+0x15a>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1050 <print_usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1290 <get_uintval_from_arg+0x160>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_uintval_from_arg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbp
add    $0xffffffff,%edi
cmp    %esi,%edi
jle    11b5 <get_uintval_from_arg+0x85>
mov    %r8d,%r14d
mov    %ecx,%r15d
movslq %esi,%rbx
mov    0x8(%rbp,%rbx,8),%rdi
xor    %r12d,%r12d
xor    %esi,%esi
mov    $0xa,%edx
call   1030 <strtoll@plt>
mov    0x2e6a(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e58(%rip),%rdx
cmp    (%rdx),%rcx
je     11e0 <get_uintval_from_arg+0xb0>
mov    0x2e6c(%rip),%rdx
cmp    (%rdx),%rcx
je     11e0 <get_uintval_from_arg+0xb0>
cmp    %r15d,%eax
jb     118e <get_uintval_from_arg+0x5e>
mov    %eax,%r12d
cmp    %r14d,%eax
jbe    1205 <get_uintval_from_arg+0xd5>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp,%rbx,8),%rdx
lea    0xeab(%rip),%rsi
xor    %r12d,%r12d
mov    %r15d,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11d7 <get_uintval_from_arg+0xa7>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
movslq %esi,%rax
mov    0x0(%rbp,%rax,8),%rdx
lea    0xe5f(%rip),%rsi
xor    %r12d,%r12d
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1050 <print_usage@plt>
jmp    1205 <get_uintval_from_arg+0xd5>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp,%rbx,8),%rdx
add    $0x1,%rbx
mov    0x0(%rbp,%rbx,8),%rcx
lea    0xe02(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
@stderr = global i32 0
@.str = [44 x i8] c"Could not parse argument %s for switch %s!\0A\00"
@.str.1 = [34 x i8] c"too few arguments for option %s!\0A\00"
@.str.2 = [31 x i8] c"%s must be between %u and %u!\0A\00"
define i32 @get_uintval_from_arg(i32 %0, i32 %1, i8** %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i8** %2, i8*** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 0, i32* %12
%13 = load i32, i32* %8
%14 = add nsw i32 %13, 1
%15 = load i32, i32* %7
%16 = sub nsw i32 %15, 1
%17 = icmp sle i32 %14, %16
br i1 %17, label %18, label %49
18: ; preds = %5
%19 = load i8**, i8*** %9
%20 = load i32, i32* %8
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %19, i64 %22
%24 = load i8*, i8** %23
%25 = call i64 @strtoll(i8* %24, i32* null, i32 10)
%26 = trunc i64 %25 to i32
store i32 %26, i32* %12
%27 = load i64, i64* @errno
%28 = load i64, i64* @EINVAL
%29 = icmp eq i64 %27, %28
br i1 %29, label %34, label %30
30: ; preds = %18
%31 = load i64, i64* @errno
%32 = load i64, i64* @ERANGE
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %48
34: ; preds = %30, %18
%35 = load i32, i32* @stderr
%36 = load i8**, i8*** %9
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = load i8**, i8*** %9
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %41, i64 %44
%46 = load i8*, i8** %45
%47 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %40, i8* %46)
store i32 0, i32* %6
br label %79
48: ; preds = %30
br label %58
49: ; preds = %5
%50 = load i32, i32* @stderr
%51 = load i8**, i8*** %9
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %55)
%57 = call i32 (...) @print_usage()
store i32 0, i32* %6
br label %79
58: ; preds = %48
%59 = load i32, i32* %12
%60 = load i32, i32* %10
%61 = icmp ult i32 %59, %60
br i1 %61, label %66, label %62
62: ; preds = %58
%63 = load i32, i32* %12
%64 = load i32, i32* %11
%65 = icmp ugt i32 %63, %64
br i1 %65, label %66, label %77
66: ; preds = %62, %58
%67 = load i32, i32* @stderr
%68 = load i8**, i8*** %9
%69 = load i32, i32* %8
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %68, i64 %70
%72 = load i8*, i8** %71
%73 = load i32, i32* %10
%74 = load i32, i32* %11
%75 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %72, i32 %73, i32 %74)
%76 = call i32 (...) @print_usage()
store i32 0, i32* %6
br label %79
77: ; preds = %62
%78 = load i32, i32* %12
store i32 %78, i32* %6
br label %79
79: ; preds = %77, %66, %49, %34
%80 = load i32, i32* %6
ret i32 %80
}

LLVM IR (-O2):
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
@stderr = global i32 0
@.str = [44 x i8] c"Could not parse argument %s for switch %s!\0A\00"
@.str.1 = [34 x i8] c"too few arguments for option %s!\0A\00"
@.str.2 = [31 x i8] c"%s must be between %u and %u!\0A\00"
define i32 @get_uintval_from_arg(i32 %0, i32 %1, i8** nocapture %2, i32 %3, i32 %4) {
%6 = add nsw i32 %0, -1
%7 = icmp sgt i32 %6, %1
br i1 %7, label %8, label %28
8: ; preds = %5
%9 = add nsw i32 %1, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %2, i64 %10
%12 = load i8*, i8** %11
%13 = tail call i64 @strtoll(i8* nocapture %12, i32* null, i32 10)
%14 = trunc i64 %13 to i32
%15 = load i64, i64* @errno
%16 = load i64, i64* @EINVAL
%17 = icmp eq i64 %15, %16
%18 = load i64, i64* @ERANGE
%19 = icmp eq i64 %15, %18
%20 = select i1 %17, i1 true, i1 %19
br i1 %20, label %21, label %35
21: ; preds = %8
%22 = load i32, i32* @stderr
%23 = sext i32 %1 to i64
%24 = getelementptr inbounds i8*, i8** %2, i64 %23
%25 = load i8*, i8** %24
%26 = load i8*, i8** %11
%27 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %25, i8* %26)
br label %46
28: ; preds = %5
%29 = load i32, i32* @stderr
%30 = sext i32 %1 to i64
%31 = getelementptr inbounds i8*, i8** %2, i64 %30
%32 = load i8*, i8** %31
%33 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = tail call i32 (...) @print_usage()
br label %46
35: ; preds = %8
%36 = icmp ult i32 %14, %3
%37 = icmp ugt i32 %14, %4
%38 = or i1 %36, %37
br i1 %38, label %39, label %46
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = sext i32 %1 to i64
%42 = getelementptr inbounds i8*, i8** %2, i64 %41
%43 = load i8*, i8** %42
%44 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %43, i32 %3, i32 %4)
%45 = tail call i32 (...) @print_usage()
br label %46
46: ; preds = %35, %39, %28, %21
%47 = phi i32 [ 0, %21 ], [ 0, %39 ], [ 0, %28 ], [ %14, %35 ]
ret i32 %47
}