#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 myrand();
int randomsize() {
  int j, k;
  k = myrand();
  j = (k & 3) + (k >> 2 & 3) + (k >> 4 & 3) + (k >> 6 & 3) + (k >> 8 & 3) +
      (k >> 10 & 3);
  j = 1 << j;
  return (myrand() % j) + 1;
}


x86 assembly (clang, -O0):
<randomsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <myrand@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x3,%eax
mov    -0x8(%rbp),%ecx
sar    $0x2,%ecx
and    $0x3,%ecx
add    %ecx,%eax
mov    -0x8(%rbp),%ecx
sar    $0x4,%ecx
and    $0x3,%ecx
add    %ecx,%eax
mov    -0x8(%rbp),%ecx
sar    $0x6,%ecx
and    $0x3,%ecx
add    %ecx,%eax
mov    -0x8(%rbp),%ecx
sar    $0x8,%ecx
and    $0x3,%ecx
add    %ecx,%eax
mov    -0x8(%rbp),%ecx
sar    $0xa,%ecx
and    $0x3,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1030 <myrand@plt>
cltd
idivl  -0x4(%rbp)
mov    %edx,%eax
add    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomsize>:
push   %rbx
xor    %eax,%eax
call   1030 <myrand@plt>
mov    %eax,%ecx
and    $0x3,%ecx
mov    %eax,%edx
shr    $0x2,%edx
and    $0x3,%edx
add    %ecx,%edx
mov    %eax,%ecx
shr    $0x4,%ecx
and    $0x3,%ecx
add    %edx,%ecx
mov    %eax,%edx
shr    $0x6,%edx
and    $0x3,%edx
add    %ecx,%edx
mov    %eax,%ecx
shr    $0x8,%ecx
and    $0x3,%ecx
add    %edx,%ecx
shr    $0xa,%eax
and    $0x3,%eax
add    %eax,%ecx
mov    $0x1,%ebx
shl    %cl,%ebx
xor    %eax,%eax
call   1030 <myrand@plt>
cltd
idiv   %ebx
lea    0x1(%rdx),%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @randomsize() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @myrand()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = and i32 %4, 3
%6 = load i32, i32* %2
%7 = ashr i32 %6, 2
%8 = and i32 %7, 3
%9 = add nsw i32 %5, %8
%10 = load i32, i32* %2
%11 = ashr i32 %10, 4
%12 = and i32 %11, 3
%13 = add nsw i32 %9, %12
%14 = load i32, i32* %2
%15 = ashr i32 %14, 6
%16 = and i32 %15, 3
%17 = add nsw i32 %13, %16
%18 = load i32, i32* %2
%19 = ashr i32 %18, 8
%20 = and i32 %19, 3
%21 = add nsw i32 %17, %20
%22 = load i32, i32* %2
%23 = ashr i32 %22, 10
%24 = and i32 %23, 3
%25 = add nsw i32 %21, %24
store i32 %25, i32* %1
%26 = load i32, i32* %1
%27 = shl i32 1, %26
store i32 %27, i32* %1
%28 = call i32 (...) @myrand()
%29 = load i32, i32* %1
%30 = srem i32 %28, %29
%31 = add nsw i32 %30, 1
ret i32 %31
}

LLVM IR (-O2):
define i32 @randomsize() {
%1 = tail call i32 (...) @myrand()
%2 = and i32 %1, 3
%3 = lshr i32 %1, 2
%4 = and i32 %3, 3
%5 = add nuw nsw i32 %4, %2
%6 = lshr i32 %1, 4
%7 = and i32 %6, 3
%8 = add nuw nsw i32 %5, %7
%9 = lshr i32 %1, 6
%10 = and i32 %9, 3
%11 = add nuw nsw i32 %8, %10
%12 = lshr i32 %1, 8
%13 = and i32 %12, 3
%14 = add nuw nsw i32 %11, %13
%15 = lshr i32 %1, 10
%16 = and i32 %15, 3
%17 = add nuw nsw i32 %14, %16
%18 = shl nuw nsw i32 1, %17
%19 = tail call i32 (...) @myrand()
%20 = srem i32 %19, %18
%21 = add nsw i32 %20, 1
ret i32 %21
}