#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 */
typedef scalar_t__ int64_t;

/* Variables and functions */
scalar_t__ INT16_MAX;
scalar_t__ INT16_MIN;
scalar_t__ INT32_MAX;
scalar_t__ INT32_MIN;
scalar_t__ INT8_MAX;
scalar_t__ INT8_MIN;
scalar_t__ UINT16_MAX;
scalar_t__ UINT32_MAX;
scalar_t__ UINT8_MAX;
int /*<<< orphan*/ assert(int);
unsigned bits_for_range(int64_t low, int64_t high) {
  assert(low <= high);
  if (low < 0) {
    if (low >= INT8_MIN && high <= INT8_MAX)
      return 8;
    else if (low >= INT16_MIN && high <= INT16_MAX)
      return 16;
    else if (low >= INT32_MIN && high <= INT32_MAX)
      return 32;
    else
      return 64;
  } else {
    if (high <= 1)
      return 1;
    else if (high <= UINT8_MAX)
      return 8;
    else if (high <= UINT16_MAX)
      return 16;
    else if (high <= UINT32_MAX)
      return 32;
    else
      return 64;
  }
}


x86 assembly (clang, -O0):
<bits_for_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
jge    11e8 <bits_for_range+0xd8>
mov    -0x10(%rbp),%rax
mov    0x2e95(%rip),%rcx
cmp    (%rcx),%rax
jl     1174 <bits_for_range+0x64>
mov    -0x18(%rbp),%rax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rax
jg     1174 <bits_for_range+0x64>
movl   $0x8,-0x4(%rbp)
jmp    1266 <bits_for_range+0x156>
mov    -0x10(%rbp),%rax
mov    0x2e29(%rip),%rcx
cmp    (%rcx),%rax
jl     11a8 <bits_for_range+0x98>
mov    -0x18(%rbp),%rax
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%rax
jg     11a8 <bits_for_range+0x98>
movl   $0x10,-0x4(%rbp)
jmp    1266 <bits_for_range+0x156>
mov    -0x10(%rbp),%rax
mov    0x2e05(%rip),%rcx
cmp    (%rcx),%rax
jl     11dc <bits_for_range+0xcc>
mov    -0x18(%rbp),%rax
mov    0x2df9(%rip),%rcx
cmp    (%rcx),%rax
jg     11dc <bits_for_range+0xcc>
movl   $0x20,-0x4(%rbp)
jmp    1266 <bits_for_range+0x156>
movl   $0x40,-0x4(%rbp)
jmp    1266 <bits_for_range+0x156>
cmpq   $0x1,-0x18(%rbp)
jg     11ff <bits_for_range+0xef>
movl   $0x1,-0x4(%rbp)
jmp    1266 <bits_for_range+0x156>
mov    -0x18(%rbp),%rax
mov    0x2da6(%rip),%rcx
cmp    (%rcx),%rax
jg     121f <bits_for_range+0x10f>
movl   $0x8,-0x4(%rbp)
jmp    1266 <bits_for_range+0x156>
mov    -0x18(%rbp),%rax
mov    0x2d76(%rip),%rcx
cmp    (%rcx),%rax
jg     123f <bits_for_range+0x12f>
movl   $0x10,-0x4(%rbp)
jmp    1266 <bits_for_range+0x156>
mov    -0x18(%rbp),%rax
mov    0x2dae(%rip),%rcx
cmp    (%rcx),%rax
jg     125f <bits_for_range+0x14f>
movl   $0x20,-0x4(%rbp)
jmp    1266 <bits_for_range+0x156>
movl   $0x40,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bits_for_range>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
cmp    %rsi,%rbx
setle  %dil
call   1030 <assert@plt>
test   %rbx,%rbx
js     1173 <bits_for_range+0x63>
mov    $0x1,%eax
cmp    $0x2,%r14
jl     11d2 <bits_for_range+0xc2>
mov    0x2e6d(%rip),%rcx
mov    $0x8,%eax
cmp    %r14,(%rcx)
jge    11d2 <bits_for_range+0xc2>
mov    0x2e48(%rip),%rcx
mov    $0x10,%eax
cmp    %r14,(%rcx)
jge    11d2 <bits_for_range+0xc2>
mov    0x2e8f(%rip),%rcx
xor    %eax,%eax
cmp    %r14,(%rcx)
setl   %al
jmp    11cc <bits_for_range+0xbc>
mov    0x2e66(%rip),%rax
cmp    %rbx,(%rax)
jg     1190 <bits_for_range+0x80>
mov    0x2e4a(%rip),%rcx
mov    $0x8,%eax
cmp    %r14,(%rcx)
jge    11d2 <bits_for_range+0xc2>
mov    0x2e11(%rip),%rax
cmp    %rbx,(%rax)
jg     11ad <bits_for_range+0x9d>
mov    0x2e25(%rip),%rcx
mov    $0x10,%eax
cmp    %r14,(%rcx)
jge    11d2 <bits_for_range+0xc2>
mov    0x2e04(%rip),%rax
cmp    %rbx,(%rax)
setg   %al
mov    0x2dff(%rip),%rcx
cmp    %r14,(%rcx)
setl   %cl
or     %al,%cl
movzbl %cl,%eax
shl    $0x5,%eax
add    $0x20,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@INT8_MIN = global i64 0
@INT8_MAX = global i64 0
@INT16_MIN = global i64 0
@INT16_MAX = global i64 0
@INT32_MIN = global i64 0
@INT32_MAX = global i64 0
@UINT8_MAX = global i64 0
@UINT16_MAX = global i64 0
@UINT32_MAX = global i64 0
define i32 @bits_for_range(i64 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
%6 = load i64, i64* %4
%7 = load i64, i64* %5
%8 = icmp sle i64 %6, %7
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i64, i64* %4
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %41
13: ; preds = %2
%14 = load i64, i64* %4
%15 = load i64, i64* @INT8_MIN
%16 = icmp sge i64 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i64, i64* %5
%19 = load i64, i64* @INT8_MAX
%20 = icmp sle i64 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 8, i32* %3
br label %61
22: ; preds = %17, %13
%23 = load i64, i64* %4
%24 = load i64, i64* @INT16_MIN
%25 = icmp sge i64 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i64, i64* %5
%28 = load i64, i64* @INT16_MAX
%29 = icmp sle i64 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 16, i32* %3
br label %61
31: ; preds = %26, %22
%32 = load i64, i64* %4
%33 = load i64, i64* @INT32_MIN
%34 = icmp sge i64 %32, %33
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = load i64, i64* %5
%37 = load i64, i64* @INT32_MAX
%38 = icmp sle i64 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 32, i32* %3
br label %61
40: ; preds = %35, %31
store i32 64, i32* %3
br label %61
41: ; preds = %2
%42 = load i64, i64* %5
%43 = icmp sle i64 %42, 1
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 1, i32* %3
br label %61
45: ; preds = %41
%46 = load i64, i64* %5
%47 = load i64, i64* @UINT8_MAX
%48 = icmp sle i64 %46, %47
br i1 %48, label %49, label %50
49: ; preds = %45
store i32 8, i32* %3
br label %61
50: ; preds = %45
%51 = load i64, i64* %5
%52 = load i64, i64* @UINT16_MAX
%53 = icmp sle i64 %51, %52
br i1 %53, label %54, label %55
54: ; preds = %50
store i32 16, i32* %3
br label %61
55: ; preds = %50
%56 = load i64, i64* %5
%57 = load i64, i64* @UINT32_MAX
%58 = icmp sle i64 %56, %57
br i1 %58, label %59, label %60
59: ; preds = %55
store i32 32, i32* %3
br label %61
60: ; preds = %55
store i32 64, i32* %3
br label %61
61: ; preds = %60, %59, %54, %49, %44, %40, %39, %30, %21
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@INT8_MIN = global i64 0
@INT8_MAX = global i64 0
@INT16_MIN = global i64 0
@INT16_MAX = global i64 0
@INT32_MIN = global i64 0
@INT32_MAX = global i64 0
@UINT8_MAX = global i64 0
@UINT16_MAX = global i64 0
@UINT32_MAX = global i64 0
define i32 @bits_for_range(i64 %0, i64 %1) {
%3 = icmp sle i64 %0, %1
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp slt i64 %0, 0
br i1 %6, label %7, label %26
7: ; preds = %2
%8 = load i64, i64* @INT8_MIN
%9 = icmp sgt i64 %8, %0
%10 = load i64, i64* @INT8_MAX
%11 = icmp slt i64 %10, %1
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %13, label %38
13: ; preds = %7
%14 = load i64, i64* @INT16_MIN
%15 = icmp sgt i64 %14, %0
%16 = load i64, i64* @INT16_MAX
%17 = icmp slt i64 %16, %1
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %19, label %38
19: ; preds = %13
%20 = load i64, i64* @INT32_MIN
%21 = icmp sgt i64 %20, %0
%22 = load i64, i64* @INT32_MAX
%23 = icmp slt i64 %22, %1
%24 = select i1 %21, i1 true, i1 %23
%25 = select i1 %24, i32 64, i32 32
br label %38
26: ; preds = %2
%27 = icmp slt i64 %1, 2
br i1 %27, label %38, label %28
28: ; preds = %26
%29 = load i64, i64* @UINT8_MAX
%30 = icmp slt i64 %29, %1
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = load i64, i64* @UINT16_MAX
%33 = icmp slt i64 %32, %1
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i64, i64* @UINT32_MAX
%36 = icmp slt i64 %35, %1
%37 = select i1 %36, i32 64, i32 32
br label %38
38: ; preds = %19, %34, %31, %28, %26, %13, %7
%39 = phi i32 [ 8, %7 ], [ 16, %13 ], [ 1, %26 ], [ 8, %28 ], [ 16, %31 ], [ %37, %34 ], [ %25, %19 ]
ret i32 %39
}