#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*/ fprintf(int /*<<< orphan*/, char *, char const *);
int sscanf(char const *, char *, int *);
int /*<<< orphan*/ stderr;
int arg_to_int(const char *arg, int min, int max, int defalt, const char *opt) {
  int i = defalt;
  int rv;
  if (!arg)
    goto done;
  rv = sscanf(arg, "%d", &i);
  if (rv != 1) {
    fprintf(stderr, "%s: integer argument required.\n", opt);
    i = defalt;
    goto done;
  }
  if (i < min || max < i) {
    fprintf(stderr, "%s: argument out of integer range.\n", opt);
    i = defalt;
    goto done;
  }
done:
  return i;
}


x86 assembly (clang, -O0):
<arg_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114f <arg_to_int+0x2f>
jmp    11d5 <arg_to_int+0xb5>
mov    -0x8(%rbp),%rdi
lea    0xea6(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <sscanf@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
je     1194 <arg_to_int+0x74>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe7f(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11d5 <arg_to_int+0xb5>
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     11ac <arg_to_int+0x8c>
mov    -0x10(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11d0 <arg_to_int+0xb0>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe63(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11d5 <arg_to_int+0xb5>
jmp    11d5 <arg_to_int+0xb5>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arg_to_int>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %ecx,0x4(%rsp)
test   %rdi,%rdi
je     117e <arg_to_int+0x5e>
mov    %r8,%r14
mov    %edx,%r15d
mov    %esi,%ebp
lea    0xebf(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    1166 <arg_to_int+0x46>
mov    0x4(%rsp),%eax
lea    0xec8(%rip),%rsi
cmp    %ebp,%eax
jl     116d <arg_to_int+0x4d>
cmp    %r15d,%eax
jle    1180 <arg_to_int+0x60>
jmp    116d <arg_to_int+0x4d>
lea    0xe96(%rip),%rsi
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rdx
call   1030 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"%s: integer argument required.\0A\00"
@.str.2 = [36 x i8] c"%s: argument out of integer range.\0A\00"
define i32 @arg_to_int(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%13 = load i32, i32* %9
store i32 %13, i32* %11
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %5
br label %41
17: ; preds = %5
%18 = load i8*, i8** %6
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %11)
store i32 %19, i32* %12
%20 = load i32, i32* %12
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %10
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i32, i32* %9
store i32 %26, i32* %11
br label %41
27: ; preds = %17
%28 = load i32, i32* %11
%29 = load i32, i32* %7
%30 = icmp slt i32 %28, %29
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i32, i32* %8
%33 = load i32, i32* %11
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %40
35: ; preds = %31, %27
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %10
%38 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = load i32, i32* %9
store i32 %39, i32* %11
br label %41
40: ; preds = %31
br label %41
41: ; preds = %40, %35, %22, %16
%42 = load i32, i32* %11
ret i32 %42
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"%s: integer argument required.\0A\00"
@.str.2 = [36 x i8] c"%s: argument out of integer range.\0A\00"
define i32 @arg_to_int(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
store i32 %3, i32* %6
%8 = icmp eq i8* %0, null
br i1 %8, label %21, label %9
9: ; preds = %5
%10 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, %1
%15 = icmp sgt i32 %13, %2
%16 = or i1 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %12, %9
%18 = phi i8* [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), %12 ]
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* %18, i8* %4)
br label %21
21: ; preds = %17, %12, %5
%22 = phi i32 [ %13, %12 ], [ %3, %5 ], [ %3, %17 ]
ret i32 %22
}