#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 strtoint(char const *const);
int strtoint_clipped(const char *const str, int min, int max) {
  int r = strtoint(str);
  if (r == -1)
    return r;
  else if (r < min)
    return min;
  else if (r > max)
    return max;
  else
    return r;
}


x86 assembly (clang, -O0):
<strtoint_clipped>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strtoint@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1143 <strtoint_clipped+0x33>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1177 <strtoint_clipped+0x67>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    115a <strtoint_clipped+0x4a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1177 <strtoint_clipped+0x67>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1171 <strtoint_clipped+0x61>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1177 <strtoint_clipped+0x67>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtoint_clipped>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%ebx
call   1030 <strtoint@plt>
cmp    $0xffffffff,%eax
je     112e <strtoint_clipped+0x1e>
cmp    %ebx,%eax
jl     1133 <strtoint_clipped+0x23>
cmp    %ebp,%eax
cmovg  %ebp,%eax
mov    %eax,%ebx
jmp    1133 <strtoint_clipped+0x23>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @strtoint_clipped(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = call i32 @strtoint(i8* %9)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i32, i32* %8
store i32 %14, i32* %4
br label %29
15: ; preds = %3
%16 = load i32, i32* %8
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load i32, i32* %6
store i32 %20, i32* %4
br label %29
21: ; preds = %15
%22 = load i32, i32* %8
%23 = load i32, i32* %7
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i32, i32* %7
store i32 %26, i32* %4
br label %29
27: ; preds = %21
%28 = load i32, i32* %8
store i32 %28, i32* %4
br label %29
29: ; preds = %27, %25, %19, %13
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @strtoint_clipped(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @strtoint(i8* %0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = icmp slt i32 %4, %1
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = icmp sgt i32 %4, %2
%10 = select i1 %9, i32 %2, i32 %4
br label %11
11: ; preds = %8, %6, %3
%12 = phi i32 [ -1, %3 ], [ %1, %6 ], [ %10, %8 ]
ret i32 %12
}