#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 */
long INT_MAX;
long strtol(char const *const, char **, int);
int filterInput(const char *restrict const toCheck) {
  long int temp;
  if (!toCheck)
    return 0;
  temp = strtol(toCheck, (char **)NULL, 10);
  if (temp > INT_MAX)
    return INT_MAX;
  else if (temp < 0)
    return 0;
  return temp;
}


x86 assembly (clang, -O0):
<filterInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1133 <filterInput+0x23>
movl   $0x0,-0x4(%rbp)
jmp    1192 <filterInput+0x82>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e94(%rip),%rcx
cmp    (%rcx),%rax
jle    116f <filterInput+0x5f>
mov    0x2e84(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
jmp    1192 <filterInput+0x82>
cmpq   $0x0,-0x18(%rbp)
jge    1186 <filterInput+0x76>
movl   $0x0,-0x4(%rbp)
jmp    1192 <filterInput+0x82>
jmp    118b <filterInput+0x7b>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filterInput>:
push   %rbx
test   %rdi,%rdi
je     1140 <filterInput+0x30>
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%rcx
mov    0x2eba(%rip),%rax
mov    (%rax),%rax
cmp    %rax,%rcx
jg     113e <filterInput+0x2e>
test   %rcx,%rcx
cmovg  %ecx,%ebx
mov    %ebx,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@INT_MAX = global i64 0
define i32 @filterInput(i8* noalias %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i32 0, i32* %2
br label %25
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i64 @strtol(i8* %9, i8** null, i32 10)
store i64 %10, i64* %4
%11 = load i64, i64* %4
%12 = load i64, i64* @INT_MAX
%13 = icmp sgt i64 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i64, i64* @INT_MAX
%16 = trunc i64 %15 to i32
store i32 %16, i32* %2
br label %25
17: ; preds = %8
%18 = load i64, i64* %4
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 0, i32* %2
br label %25
21: ; preds = %17
br label %22
22: ; preds = %21
%23 = load i64, i64* %4
%24 = trunc i64 %23 to i32
store i32 %24, i32* %2
br label %25
25: ; preds = %22, %20, %14, %7
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@INT_MAX = global i64 0
define i32 @filterInput(i8* noalias %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = tail call i64 @strtol(i8* nocapture %0, i8** null, i32 10)
%5 = load i64, i64* @INT_MAX
%6 = icmp sgt i64 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = trunc i64 %5 to i32
br label %13
9: ; preds = %3
%10 = icmp sgt i64 %4, 0
%11 = select i1 %10, i64 %4, i64 0
%12 = trunc i64 %11 to i32
br label %13
13: ; preds = %9, %1, %7
%14 = phi i32 [ %8, %7 ], [ 0, %1 ], [ %12, %9 ]
ret i32 %14
}