#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 */
scalar_t__ mrand48();
unsigned int bitrand2() {
  static int pos = (32 / 2);
  static unsigned int rnd[(32 / 2)];
  unsigned int tmp, j;
  if (pos == (32 / 2)) {
    pos = 0;
    tmp = (unsigned int)mrand48();
    for (j = 0; j < (32 / 2); ++j) {
      rnd[j] = (unsigned int)(tmp & ((2 * 2 - 1) << (j * 2))) >> (j * 2);
    }
  }
  return rnd[pos++];
}


x86 assembly (clang, -O0):
<bitrand2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpl   $0x10,0x2f09(%rip)
jne    1186 <bitrand2+0x76>
movl   $0x0,0x2ef9(%rip)
mov    $0x0,%al
call   1030 <mrand48@plt>
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x10,-0x8(%rbp)
jae    1181 <bitrand2+0x71>
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
mov    $0x3,%eax
shl    %cl,%eax
and    %eax,%edx
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
shr    %cl,%edx
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
lea    0x2ed0(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1140 <bitrand2+0x30>
jmp    1186 <bitrand2+0x76>
mov    0x2e9c(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2e91(%rip)
movslq %eax,%rcx
lea    0x2e9f(%rip),%rax
mov    (%rax,%rcx,4),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitrand2>:
push   %rax
mov    0x2f11(%rip),%eax
cmp    $0x10,%eax
jne    120f <bitrand2+0xff>
movl   $0x0,0x2efe(%rip)
xor    %eax,%eax
call   1030 <mrand48@plt>
mov    %eax,%ecx
and    $0x3,%ecx
mov    %ecx,0x2f04(%rip)
mov    %eax,%ecx
shr    $0x2,%ecx
and    $0x3,%ecx
mov    %ecx,0x2efa(%rip)
mov    %eax,%ecx
shr    $0x4,%ecx
and    $0x3,%ecx
mov    %ecx,0x2ef0(%rip)
mov    %eax,%ecx
shr    $0x6,%ecx
and    $0x3,%ecx
mov    %ecx,0x2ee6(%rip)
mov    %eax,%ecx
shr    $0x8,%ecx
and    $0x3,%ecx
mov    %ecx,0x2edc(%rip)
mov    %eax,%ecx
shr    $0xa,%ecx
and    $0x3,%ecx
mov    %ecx,0x2ed2(%rip)
mov    %eax,%ecx
shr    $0xc,%ecx
and    $0x3,%ecx
mov    %ecx,0x2ec8(%rip)
mov    %eax,%ecx
shr    $0xe,%ecx
and    $0x3,%ecx
mov    %ecx,0x2ebe(%rip)
mov    %eax,%ecx
shr    $0x10,%ecx
and    $0x3,%ecx
mov    %ecx,0x2eb4(%rip)
mov    %eax,%ecx
shr    $0x12,%ecx
and    $0x3,%ecx
mov    %ecx,0x2eaa(%rip)
mov    %eax,%ecx
shr    $0x14,%ecx
and    $0x3,%ecx
mov    %ecx,0x2ea0(%rip)
mov    %eax,%ecx
shr    $0x16,%ecx
and    $0x3,%ecx
mov    %ecx,0x2e96(%rip)
mov    %eax,%ecx
shr    $0x18,%ecx
and    $0x3,%ecx
mov    %ecx,0x2e8c(%rip)
mov    %eax,%ecx
shr    $0x1a,%ecx
and    $0x3,%ecx
mov    %ecx,0x2e82(%rip)
mov    %eax,%ecx
shr    $0x1c,%ecx
and    $0x3,%ecx
mov    %ecx,0x2e78(%rip)
shr    $0x1e,%eax
mov    %eax,0x2e73(%rip)
mov    0x2e19(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2e10(%rip)
cltq
lea    0x2e1f(%rip),%rcx
mov    (%rcx,%rax,4),%eax
pop    %rcx
ret

LLVM IR (-O0):
@bitrand2.pos = internal global i32 16
@bitrand2.rnd = internal global [16 x i32] zeroinitializer
define i32 @bitrand2() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @bitrand2.pos
%4 = icmp eq i32 %3, 16
br i1 %4, label %5, label %27
5: ; preds = %0
store i32 0, i32* @bitrand2.pos
%6 = call i64 (...) @mrand48()
%7 = trunc i64 %6 to i32
store i32 %7, i32* %1
store i32 0, i32* %2
br label %8
8: ; preds = %23, %5
%9 = load i32, i32* %2
%10 = icmp ult i32 %9, 16
br i1 %10, label %11, label %26
11: ; preds = %8
%12 = load i32, i32* %1
%13 = load i32, i32* %2
%14 = mul i32 %13, 2
%15 = shl i32 3, %14
%16 = and i32 %12, %15
%17 = load i32, i32* %2
%18 = mul i32 %17, 2
%19 = lshr i32 %16, %18
%20 = load i32, i32* %2
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 %21
store i32 %19, i32* %22
br label %23
23: ; preds = %11
%24 = load i32, i32* %2
%25 = add i32 %24, 1
store i32 %25, i32* %2
br label %8
26: ; preds = %8
br label %27
27: ; preds = %26, %0
%28 = load i32, i32* @bitrand2.pos
%29 = add nsw i32 %28, 1
store i32 %29, i32* @bitrand2.pos
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds [16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 %30
%32 = load i32, i32* %31
ret i32 %32
}

LLVM IR (-O2):
@bitrand2.pos = internal unnamed_addr global i32 16
@bitrand2.rnd = internal unnamed_addr global [16 x i32] zeroinitializer
define i32 @bitrand2() {
%1 = load i32, i32* @bitrand2.pos
%2 = icmp eq i32 %1, 16
br i1 %2, label %3, label %37
3: ; preds = %0
store i32 0, i32* @bitrand2.pos
%4 = tail call i64 (...) @mrand48()
%5 = trunc i64 %4 to i32
%6 = and i32 %5, 3
store i32 %6, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 0)
%7 = lshr i32 %5, 2
%8 = and i32 %7, 3
store i32 %8, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 1)
%9 = lshr i32 %5, 4
%10 = and i32 %9, 3
store i32 %10, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 2)
%11 = lshr i32 %5, 6
%12 = and i32 %11, 3
store i32 %12, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 3)
%13 = lshr i32 %5, 8
%14 = and i32 %13, 3
store i32 %14, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 4)
%15 = lshr i32 %5, 10
%16 = and i32 %15, 3
store i32 %16, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 5)
%17 = lshr i32 %5, 12
%18 = and i32 %17, 3
store i32 %18, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 6)
%19 = lshr i32 %5, 14
%20 = and i32 %19, 3
store i32 %20, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 7)
%21 = lshr i32 %5, 16
%22 = and i32 %21, 3
store i32 %22, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 8)
%23 = lshr i32 %5, 18
%24 = and i32 %23, 3
store i32 %24, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 9)
%25 = lshr i32 %5, 20
%26 = and i32 %25, 3
store i32 %26, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 10)
%27 = lshr i32 %5, 22
%28 = and i32 %27, 3
store i32 %28, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 11)
%29 = lshr i32 %5, 24
%30 = and i32 %29, 3
store i32 %30, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 12)
%31 = lshr i32 %5, 26
%32 = and i32 %31, 3
store i32 %32, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 13)
%33 = lshr i32 %5, 28
%34 = and i32 %33, 3
store i32 %34, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 14)
%35 = lshr i32 %5, 30
store i32 %35, i32* getelementptr inbounds ([16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 15)
%36 = load i32, i32* @bitrand2.pos
br label %37
37: ; preds = %3, %0
%38 = phi i32 [ %36, %3 ], [ %1, %0 ]
%39 = add nsw i32 %38, 1
store i32 %39, i32* @bitrand2.pos
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds [16 x i32], [16 x i32]* @bitrand2.rnd, i64 0, i64 %40
%42 = load i32, i32* %41
ret i32 %42
}