#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ file_print(char *, int /*<<< orphan*/);
char *numerate_number(int);
int /*<<< orphan*/ stderr;
void range_check(int displacement, int number_of_bytes) {
  if (4 == number_of_bytes)
    return;
  else if (3 == number_of_bytes) {
    if ((8388607 < displacement) || (displacement < -8388608)) {
      file_print("A displacement of ", stderr);
      file_print(numerate_number(displacement), stderr);
      file_print(" does not fit in 3 bytes\n", stderr);
      exit(EXIT_FAILURE);
    }
    return;
  } else if (2 == number_of_bytes) {
    if ((32767 < displacement) || (displacement < -32768)) {
      file_print("A displacement of ", stderr);
      file_print(numerate_number(displacement), stderr);
      file_print(" does not fit in 2 bytes\n", stderr);
      exit(EXIT_FAILURE);
    }
    return;
  } else if (1 == number_of_bytes) {
    if ((127 < displacement) || (displacement < -128)) {
      file_print("A displacement of ", stderr);
      file_print(numerate_number(displacement), stderr);
      file_print(" does not fit in 1 byte\n", stderr);
      exit(EXIT_FAILURE);
    }
    return;
  }
  file_print("Invalid number of bytes given\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    12fd <range_check+0x1cd>
mov    $0x3,%eax
cmp    -0x8(%rbp),%eax
jne    11d0 <range_check+0xa0>
mov    $0x7fffff,%eax
cmp    -0x4(%rbp),%eax
jl     117a <range_check+0x4a>
cmpl   $0xff800000,-0x4(%rbp)
jge    11cb <range_check+0x9b>
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
lea    0xe76(%rip),%rdi
call   1050 <file_print@plt>
mov    -0x4(%rbp),%edi
call   1040 <numerate_number@plt>
mov    %rax,%rdi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
call   1050 <file_print@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
lea    0xe5b(%rip),%rdi
call   1050 <file_print@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1030 <exit@plt>
jmp    12fd <range_check+0x1cd>
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jne    124f <range_check+0x11f>
mov    $0x7fff,%eax
cmp    -0x4(%rbp),%eax
jl     11f9 <range_check+0xc9>
cmpl   $0xffff8000,-0x4(%rbp)
jge    124a <range_check+0x11a>
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
lea    0xdf7(%rip),%rdi
call   1050 <file_print@plt>
mov    -0x4(%rbp),%edi
call   1040 <numerate_number@plt>
mov    %rax,%rdi
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
call   1050 <file_print@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
lea    0xdf6(%rip),%rdi
call   1050 <file_print@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   1030 <exit@plt>
jmp    12fd <range_check+0x1cd>
mov    $0x1,%eax
cmp    -0x8(%rbp),%eax
jne    12cb <range_check+0x19b>
mov    $0x7f,%eax
cmp    -0x4(%rbp),%eax
jl     1275 <range_check+0x145>
cmpl   $0xffffff80,-0x4(%rbp)
jge    12c6 <range_check+0x196>
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
lea    0xd7b(%rip),%rdi
call   1050 <file_print@plt>
mov    -0x4(%rbp),%edi
call   1040 <numerate_number@plt>
mov    %rax,%rdi
mov    0x2d44(%rip),%rax
mov    (%rax),%esi
call   1050 <file_print@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%esi
lea    0xd94(%rip),%rdi
call   1050 <file_print@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
call   1030 <exit@plt>
jmp    12fd <range_check+0x1cd>
jmp    12d0 <range_check+0x1a0>
jmp    12d5 <range_check+0x1a5>
jmp    12da <range_check+0x1aa>
mov    0x2cff(%rip),%rax
mov    (%rax),%esi
lea    0xd76(%rip),%rdi
call   1050 <file_print@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   1030 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<range_check>:
push   %r14
push   %rbx
push   %rax
add    $0xffffffff,%esi
cmp    $0x3,%esi
ja     11e0 <range_check+0xb0>
mov    %edi,%ebx
lea    0xeb7(%rip),%rax
movslq (%rax,%rsi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
movsbl %bl,%eax
cmp    %ebx,%eax
je     11d8 <range_check+0xa8>
mov    0x2e80(%rip),%r14
mov    (%r14),%esi
lea    0xea6(%rip),%rdi
call   1050 <file_print@plt>
mov    %ebx,%edi
call   1040 <numerate_number@plt>
mov    (%r14),%esi
mov    %rax,%rdi
call   1050 <file_print@plt>
mov    (%r14),%esi
lea    0xecc(%rip),%rdi
jmp    1224 <range_check+0xf4>
movswl %bx,%eax
cmp    %ebx,%eax
je     11d8 <range_check+0xa8>
mov    0x2e42(%rip),%r14
mov    (%r14),%esi
lea    0xe68(%rip),%rdi
call   1050 <file_print@plt>
mov    %ebx,%edi
call   1040 <numerate_number@plt>
mov    (%r14),%esi
mov    %rax,%rdi
call   1050 <file_print@plt>
mov    (%r14),%esi
lea    0xe74(%rip),%rdi
jmp    1224 <range_check+0xf4>
lea    -0x800000(%rbx),%eax
cmp    $0xfeffffff,%eax
jbe    11f2 <range_check+0xc2>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
lea    0xe80(%rip),%rdi
jmp    1224 <range_check+0xf4>
mov    0x2de7(%rip),%r14
mov    (%r14),%esi
lea    0xe0d(%rip),%rdi
call   1050 <file_print@plt>
mov    %ebx,%edi
call   1040 <numerate_number@plt>
mov    (%r14),%esi
mov    %rax,%rdi
call   1050 <file_print@plt>
mov    (%r14),%esi
lea    0xdff(%rip),%rdi
call   1050 <file_print@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   1030 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"A displacement of \00"
@stderr = global i32 0
@.str.1 = [26 x i8] c" does not fit in 3 bytes\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [26 x i8] c" does not fit in 2 bytes\0A\00"
@.str.3 = [25 x i8] c" does not fit in 1 byte\0A\00"
@.str.4 = [31 x i8] c"Invalid number of bytes given\0A\00"
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 %79
8: ; preds = %2
%9 = load i32, i32* %4
%10 = icmp eq i32 3, %9
br i1 %10, label %11, label %29
11: ; preds = %8
%12 = load i32, i32* %3
%13 = icmp slt i32 8388607, %12
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, -8388608
br i1 %16, label %17, label %28
17: ; preds = %14, %11
%18 = load i32, i32* @stderr
%19 = call i32 @file_print(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %3
%21 = call i8* @numerate_number(i32 %20)
%22 = load i32, i32* @stderr
%23 = call i32 @file_print(i8* %21, i32 %22)
%24 = load i32, i32* @stderr
%25 = call i32 @file_print(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %14
br label %79
29: ; preds = %8
%30 = load i32, i32* %4
%31 = icmp eq i32 2, %30
br i1 %31, label %32, label %50
32: ; preds = %29
%33 = load i32, i32* %3
%34 = icmp slt i32 32767, %33
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = load i32, i32* %3
%37 = icmp slt i32 %36, -32768
br i1 %37, label %38, label %49
38: ; preds = %35, %32
%39 = load i32, i32* @stderr
%40 = call i32 @file_print(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %3
%42 = call i8* @numerate_number(i32 %41)
%43 = load i32, i32* @stderr
%44 = call i32 @file_print(i8* %42, i32 %43)
%45 = load i32, i32* @stderr
%46 = call i32 @file_print(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %35
br label %79
50: ; preds = %29
%51 = load i32, i32* %4
%52 = icmp eq i32 1, %51
br i1 %52, label %53, label %71
53: ; preds = %50
%54 = load i32, i32* %3
%55 = icmp slt i32 127, %54
br i1 %55, label %59, label %56
56: ; preds = %53
%57 = load i32, i32* %3
%58 = icmp slt i32 %57, -128
br i1 %58, label %59, label %70
59: ; preds = %56, %53
%60 = load i32, i32* @stderr
%61 = call i32 @file_print(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %3
%63 = call i8* @numerate_number(i32 %62)
%64 = load i32, i32* @stderr
%65 = call i32 @file_print(i8* %63, i32 %64)
%66 = load i32, i32* @stderr
%67 = call i32 @file_print(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %66)
%68 = load i32, i32* @EXIT_FAILURE
%69 = call i32 @exit(i32 %68)
unreachable
70: ; preds = %56
br label %79
71: ; preds = %50
br label %72
72: ; preds = %71
br label %73
73: ; preds = %72
br label %74
74: ; preds = %73
%75 = load i32, i32* @stderr
%76 = call i32 @file_print(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %75)
%77 = load i32, i32* @EXIT_FAILURE
%78 = call i32 @exit(i32 %77)
unreachable
79: ; preds = %70, %49, %28, %7
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"A displacement of \00"
@stderr = global i32 0
@.str.1 = [26 x i8] c" does not fit in 3 bytes\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [26 x i8] c" does not fit in 2 bytes\0A\00"
@.str.3 = [25 x i8] c" does not fit in 1 byte\0A\00"
@.str.4 = [31 x i8] c"Invalid number of bytes given\0A\00"
define void @range_check(i32 %0, i32 %1) {
switch i32 %1, label %42 [
i32 4, label %47
i32 3, label %3
i32 2, label %16
i32 1, label %29
]
3: ; preds = %2
%4 = add i32 %0, -8388608
%5 = icmp ult i32 %4, -16777216
br i1 %5, label %6, label %47
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @file_print(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i8* @numerate_number(i32 %0)
%10 = load i32, i32* @stderr
%11 = tail call i32 @file_print(i8* %9, i32 %10)
%12 = load i32, i32* @stderr
%13 = tail call i32 @file_print(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = add i32 %0, -32768
%18 = icmp ult i32 %17, -65536
br i1 %18, label %19, label %47
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = tail call i32 @file_print(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = tail call i8* @numerate_number(i32 %0)
%23 = load i32, i32* @stderr
%24 = tail call i32 @file_print(i8* %22, i32 %23)
%25 = load i32, i32* @stderr
%26 = tail call i32 @file_print(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %2
%30 = add i32 %0, -128
%31 = icmp ult i32 %30, -256
br i1 %31, label %32, label %47
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = tail call i32 @file_print(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = tail call i8* @numerate_number(i32 %0)
%36 = load i32, i32* @stderr
%37 = tail call i32 @file_print(i8* %35, i32 %36)
%38 = load i32, i32* @stderr
%39 = tail call i32 @file_print(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = tail call i32 @exit(i32 %40)
unreachable
42: ; preds = %2
%43 = load i32, i32* @stderr
%44 = tail call i32 @file_print(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %43)
%45 = load i32, i32* @EXIT_FAILURE
%46 = tail call i32 @exit(i32 %45)
unreachable
47: ; preds = %2, %29, %16, %3
ret void
}