#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*/ printf(char *, int);
int strtol(char *, char **, int);
int test_getarg(char *arg, int *arg_ival, int min, int max) {
  char *err;
  *arg_ival = strtol(arg, &err, 10);
  if (*err)
    return -1;
  if (*arg_ival < min || *arg_ival > max) {
    printf("test number out of range: %i\n", *arg_ival);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_getarg>:
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),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     1169 <test_getarg+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <test_getarg+0x8c>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x1c(%rbp),%eax
jl     1187 <test_getarg+0x67>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x20(%rbp),%eax
jle    11a5 <test_getarg+0x85>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <test_getarg+0x8c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_getarg>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,(%rbx)
mov    0x8(%rsp),%rdx
mov    $0xffffffff,%ecx
cmpb   $0x0,(%rdx)
jne    116e <test_getarg+0x4e>
cmp    %ebp,%eax
jl     115b <test_getarg+0x3b>
xor    %ecx,%ecx
cmp    %r14d,%eax
jle    116e <test_getarg+0x4e>
lea    0xe9e(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"test number out of range: %i\0A\00"
define i32 @test_getarg(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 = call i32 @strtol(i8* %11, i8** %10, i32 10)
%13 = load i32*, i32** %7
store i32 %12, i32* %13
%14 = load i8*, i8** %10
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 -1, i32* %5
br label %33
18: ; preds = %4
%19 = load i32*, i32** %7
%20 = load i32, i32* %19
%21 = load i32, i32* %8
%22 = icmp slt i32 %20, %21
br i1 %22, label %28, label %23
23: ; preds = %18
%24 = load i32*, i32** %7
%25 = load i32, i32* %24
%26 = load i32, i32* %9
%27 = icmp sgt i32 %25, %26
br i1 %27, label %28, label %32
28: ; preds = %23, %18
%29 = load i32*, i32** %7
%30 = load i32, i32* %29
%31 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %30)
store i32 -1, i32* %5
br label %33
32: ; preds = %23
store i32 0, i32* %5
br label %33
33: ; preds = %32, %28, %17
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
@.str = [30 x i8] c"test number out of range: %i\0A\00"
define i32 @test_getarg(i8* %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = call i32 @strtol(i8* %0, i8** %5, i32 10)
store i32 %7, i32* %1
%8 = load i8*, i8** %5
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %4
%12 = icmp slt i32 %7, %2
%13 = icmp sgt i32 %7, %3
%14 = or i1 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %17
17: ; preds = %11, %4, %15
%18 = phi i32 [ -1, %15 ], [ -1, %4 ], [ 0, %11 ]
ret i32 %18
}