#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*/ assert(int);
size_t lrand48();
size_t randomBlockSize(const size_t lowbsBytes, const size_t highbsBytes,
                       const size_t alignmentbits) {
  assert(alignmentbits < 100);
  size_t lowbs_k = lowbsBytes >> alignmentbits;
  if (lowbs_k < 1)
    lowbs_k = 1;
  size_t highbs_k = highbsBytes >> alignmentbits;
  if (highbs_k < 1)
    highbs_k = 1;
  size_t randombs_k = lowbs_k;
  if (highbs_k > lowbs_k) {
    randombs_k += (lrand48() % (highbs_k - lowbs_k + 1));
  }
  size_t randombs = randombs_k << alignmentbits;
  if (randombs <= 0) {
    randombs = 1 << alignmentbits;
  }
  return randombs;
}


x86 assembly (clang, -O0):
<randomBlockSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x64,-0x18(%rbp)
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
shr    %cl,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x1,-0x20(%rbp)
jae    1168 <randomBlockSize+0x48>
movq   $0x1,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
shr    %cl,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x1,-0x28(%rbp)
jae    118a <randomBlockSize+0x6a>
movq   $0x1,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    11c0 <randomBlockSize+0xa0>
mov    $0x0,%al
call   1040 <lrand48@plt>
mov    -0x28(%rbp),%rcx
sub    -0x20(%rbp),%rcx
add    $0x1,%rcx
xor    %edx,%edx
div    %rcx
add    -0x30(%rbp),%rdx
mov    %rdx,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    %cl,%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
ja     11ed <randomBlockSize+0xcd>
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomBlockSize>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %edi,%edi
cmp    $0x64,%rdx
setb   %dil
call   1030 <assert@plt>
mov    %r14d,%ecx
shr    %cl,%r15
test   %r15,%r15
mov    $0x1,%eax
cmove  %rax,%r15
shr    %cl,%rbx
test   %rbx,%rbx
cmove  %rax,%rbx
sub    %r15,%rbx
jbe    1183 <randomBlockSize+0x63>
xor    %eax,%eax
call   1040 <lrand48@plt>
add    $0x1,%rbx
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
je     117c <randomBlockSize+0x5c>
xor    %edx,%edx
div    %rbx
jmp    1180 <randomBlockSize+0x60>
xor    %edx,%edx
div    %ebx
add    %rdx,%r15
mov    %r14d,%ecx
shl    %cl,%r15
mov    $0x1,%eax
shl    %cl,%eax
test   %r15,%r15
cltq
cmovne %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @randomBlockSize(i64 %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%11 = load i64, i64* %6
%12 = icmp ult i64 %11, 100
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i64, i64* %4
%16 = load i64, i64* %6
%17 = lshr i64 %15, %16
store i64 %17, i64* %7
%18 = load i64, i64* %7
%19 = icmp ult i64 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %3
store i64 1, i64* %7
br label %21
21: ; preds = %20, %3
%22 = load i64, i64* %5
%23 = load i64, i64* %6
%24 = lshr i64 %22, %23
store i64 %24, i64* %8
%25 = load i64, i64* %8
%26 = icmp ult i64 %25, 1
br i1 %26, label %27, label %28
27: ; preds = %21
store i64 1, i64* %8
br label %28
28: ; preds = %27, %21
%29 = load i64, i64* %7
store i64 %29, i64* %9
%30 = load i64, i64* %8
%31 = load i64, i64* %7
%32 = icmp ugt i64 %30, %31
br i1 %32, label %33, label %42
33: ; preds = %28
%34 = call i64 (...) @lrand48()
%35 = load i64, i64* %8
%36 = load i64, i64* %7
%37 = sub i64 %35, %36
%38 = add i64 %37, 1
%39 = urem i64 %34, %38
%40 = load i64, i64* %9
%41 = add i64 %40, %39
store i64 %41, i64* %9
br label %42
42: ; preds = %33, %28
%43 = load i64, i64* %9
%44 = load i64, i64* %6
%45 = shl i64 %43, %44
store i64 %45, i64* %10
%46 = load i64, i64* %10
%47 = icmp ule i64 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %42
%49 = load i64, i64* %6
%50 = trunc i64 %49 to i32
%51 = shl i32 1, %50
%52 = sext i32 %51 to i64
store i64 %52, i64* %10
br label %53
53: ; preds = %48, %42
%54 = load i64, i64* %10
ret i64 %54
}

LLVM IR (-O2):
define i64 @randomBlockSize(i64 %0, i64 %1, i64 %2) {
%4 = icmp ult i64 %2, 100
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = lshr i64 %0, %2
%8 = icmp eq i64 %7, 0
%9 = select i1 %8, i64 1, i64 %7
%10 = lshr i64 %1, %2
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i64 1, i64 %10
%13 = icmp ugt i64 %12, %9
br i1 %13, label %14, label %20
14: ; preds = %3
%15 = tail call i64 (...) @lrand48()
%16 = sub i64 1, %9
%17 = add i64 %16, %12
%18 = urem i64 %15, %17
%19 = add i64 %18, %9
br label %20
20: ; preds = %14, %3
%21 = phi i64 [ %19, %14 ], [ %9, %3 ]
%22 = shl i64 %21, %2
%23 = icmp eq i64 %22, 0
%24 = trunc i64 %2 to i32
%25 = shl nuw i32 1, %24
%26 = sext i32 %25 to i64
%27 = select i1 %23, i64 %26, i64 %22
ret i64 %27
}