#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*/ EXIT_FAILURE;
int /*<<< orphan*/ bound_values(int, int, int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ file_print(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void range_check(int displacement, int number_of_bytes) {
  if (4 == number_of_bytes)
    return;
  else if (3 == number_of_bytes) {
    bound_values(displacement, number_of_bytes, -8388608, 16777216);
    return;
  } else if (2 == number_of_bytes) {
    bound_values(displacement, number_of_bytes, -32768, 65535);
    return;
  } else if (1 == number_of_bytes) {
    bound_values(displacement, number_of_bytes, -128, 255);
    return;
  }
  file_print("Received an invalid number of bytes in range_check\n", stderr);
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<range_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x4,%eax
cmp    -0x8(%rbp),%eax
jne    1151 <range_check+0x21>
jmp    11fb <range_check+0xcb>
mov    $0x3,%eax
cmp    -0x8(%rbp),%eax
jne    1179 <range_check+0x49>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0xff800000,%edx
mov    $0x1000000,%ecx
call   1030 <bound_values@plt>
jmp    11fb <range_check+0xcb>
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jne    11a1 <range_check+0x71>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0xffff8000,%edx
mov    $0xffff,%ecx
call   1030 <bound_values@plt>
jmp    11fb <range_check+0xcb>
mov    $0x1,%eax
cmp    -0x8(%rbp),%eax
jne    11c9 <range_check+0x99>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0xffffff80,%edx
mov    $0xff,%ecx
call   1030 <bound_values@plt>
jmp    11fb <range_check+0xcb>
jmp    11ce <range_check+0x9e>
jmp    11d3 <range_check+0xa3>
jmp    11d8 <range_check+0xa8>
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
lea    0xe18(%rip),%rdi
call   1050 <file_print@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<range_check>:
push   %rax
add    $0xffffffff,%esi
cmp    $0x3,%esi
ja     118a <range_check+0x5a>
lea    0xec0(%rip),%rax
movslq (%rax,%rsi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    $0x1,%esi
mov    $0xffffff80,%edx
mov    $0xff,%ecx
pop    %rax
jmp    1030 <bound_values@plt>
mov    $0x3,%esi
mov    $0xff800000,%edx
mov    $0x1000000,%ecx
pop    %rax
jmp    1030 <bound_values@plt>
mov    $0x2,%esi
mov    $0xffff8000,%edx
mov    $0xffff,%ecx
pop    %rax
jmp    1030 <bound_values@plt>
pop    %rax
ret
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    0xe76(%rip),%rdi
call   1050 <file_print@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [52 x i8] c"Received an invalid number of bytes in range_check\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
define void @range_check(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp eq i32 4, %5
br i1 %6, label %7, label %8
7: ; preds = %2
br label %37
8: ; preds = %2
%9 = load i32, i32* %4
%10 = icmp eq i32 3, %9
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = call i32 @bound_values(i32 %12, i32 %13, i32 -8388608, i32 16777216)
br label %37
15: ; preds = %8
%16 = load i32, i32* %4
%17 = icmp eq i32 2, %16
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = call i32 @bound_values(i32 %19, i32 %20, i32 -32768, i32 65535)
br label %37
22: ; preds = %15
%23 = load i32, i32* %4
%24 = icmp eq i32 1, %23
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = call i32 @bound_values(i32 %26, i32 %27, i32 -128, i32 255)
br label %37
29: ; preds = %22
br label %30
30: ; preds = %29
br label %31
31: ; preds = %30
br label %32
32: ; preds = %31
%33 = load i32, i32* @stderr
%34 = call i32 @file_print(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %25, %18, %11, %7
ret void
}

LLVM IR (-O2):
@.str = [52 x i8] c"Received an invalid number of bytes in range_check\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
define void @range_check(i32 %0, i32 %1) {
switch i32 %1, label %9 [
i32 4, label %14
i32 3, label %3
i32 2, label %5
i32 1, label %7
]
3: ; preds = %2
%4 = tail call i32 @bound_values(i32 %0, i32 3, i32 -8388608, i32 16777216)
br label %14
5: ; preds = %2
%6 = tail call i32 @bound_values(i32 %0, i32 2, i32 -32768, i32 65535)
br label %14
7: ; preds = %2
%8 = tail call i32 @bound_values(i32 %0, i32 1, i32 -128, i32 255)
br label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @file_print(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2, %7, %5, %3
ret void
}