#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 strtol(char *, char **, int);
int getNumber(char *string, int min, int max) {
  char *endptr;
  int number = strtol(string, &endptr, 10);
  if (string == endptr)
    return 0xFF;
  if (number > max)
    return max;
  else if (number < min)
    return min;
  return number;
}


x86 assembly (clang, -O0):
<getNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    1151 <getNumber+0x41>
movl   $0xff,-0x4(%rbp)
jmp    118a <getNumber+0x7a>
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1168 <getNumber+0x58>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118a <getNumber+0x7a>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117f <getNumber+0x6f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118a <getNumber+0x7a>
jmp    1184 <getNumber+0x74>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNumber>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
cmp    %rbp,0x8(%rsp)
je     1145 <getNumber+0x35>
cmp    %ebx,%eax
jg     114a <getNumber+0x3a>
cmp    %r14d,%eax
cmovl  %r14d,%eax
mov    %eax,%ebx
jmp    114a <getNumber+0x3a>
mov    $0xff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @getNumber(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i32 @strtol(i8* %0, i8** %4, i32 10)
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, %0
br i1 %8, label %14, label %9
9: ; preds = %3
%10 = icmp sgt i32 %6, %2
br i1 %10, label %14, label %11
11: ; preds = %9
%12 = icmp slt i32 %6, %1
%13 = select i1 %12, i32 %1, i32 %6
br label %14
14: ; preds = %11, %9, %3
%15 = phi i32 [ 255, %3 ], [ %2, %9 ], [ %13, %11 ]
ret i32 %15
}