#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*/ error_msg(char *, int, int);
int str_to_int(char const *, long *);
int parse_int(const char *buf, int minval, int maxval, int *val) {
  long int tmp;
  if (str_to_int(buf, &tmp) == -1 || tmp < minval || tmp > maxval) {
    error_msg("integer in range %d..%d expected", minval, maxval);
    return 0;
  }
  *val = tmp;
  return 1;
}


x86 assembly (clang, -O0):
<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
call   1040 <str_to_int@plt>
cmp    $0xffffffff,%eax
je     116e <parse_int+0x4e>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
jl     116e <parse_int+0x4e>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmp    %rcx,%rax
jle    118c <parse_int+0x6c>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe85(%rip),%rdi
call   1030 <error_msg@plt>
movl   $0x0,-0x4(%rbp)
jmp    119f <parse_int+0x7f>
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %edx,%ebx
mov    %esi,%ebp
lea    0x8(%rsp),%rsi
call   1040 <str_to_int@plt>
cmp    $0xffffffff,%eax
je     115d <parse_int+0x3d>
mov    0x8(%rsp),%rax
movslq %ebp,%rcx
cmp    %rcx,%rax
jl     115d <parse_int+0x3d>
movslq %ebx,%rcx
cmp    %rcx,%rax
jg     115d <parse_int+0x3d>
mov    %eax,(%r14)
mov    $0x1,%eax
jmp    116f <parse_int+0x4f>
lea    0xe9c(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <error_msg@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"integer in range %d..%d expected\00"
define i32 @parse_int(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 i64
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 @str_to_int(i8* %11, i64* %10)
%13 = icmp eq i32 %12, -1
br i1 %13, label %24, label %14
14: ; preds = %4
%15 = load i64, i64* %10
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = load i64, i64* %10
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = icmp sgt i64 %20, %22
br i1 %23, label %24, label %28
24: ; preds = %19, %14, %4
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = call i32 @error_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %26)
store i32 0, i32* %5
br label %32
28: ; preds = %19
%29 = load i64, i64* %10
%30 = trunc i64 %29 to i32
%31 = load i32*, i32** %9
store i32 %30, i32* %31
store i32 1, i32* %5
br label %32
32: ; preds = %28, %24
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
@.str = [33 x i8] c"integer in range %d..%d expected\00"
define i32 @parse_int(i8* %0, i32 %1, i32 %2, i32* nocapture writeonly %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
%7 = call i32 @str_to_int(i8* %0, i64* %5)
%8 = icmp eq i32 %7, -1
br i1 %8, label %16, label %9
9: ; preds = %4
%10 = load i64, i64* %5
%11 = sext i32 %1 to i64
%12 = icmp slt i64 %10, %11
%13 = sext i32 %2 to i64
%14 = icmp sgt i64 %10, %13
%15 = or i1 %12, %14
br i1 %15, label %16, label %18
16: ; preds = %9, %4
%17 = call i32 @error_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
br label %20
18: ; preds = %9
%19 = trunc i64 %10 to i32
store i32 %19, i32* %3
br label %20
20: ; preds = %18, %16
%21 = phi i32 [ 0, %16 ], [ 1, %18 ]
ret i32 %21
}