#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 unsigned long long uint64_t;

/* Variables and functions */
int RAND_MAX;
int random();
int /*<<< orphan*/ srandom(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
uint64_t bit_shuffle(int n) {
  srandom(time(NULL));
  uint64_t r = 0;
  int i;
  for (i = 0; i < n; i += 2) {
    if (random() * 2 >= RAND_MAX) {
      r |= (1ULL << i);
      r &= ~(1ULL << (i + 1));
    } else {
      r |= 1ULL << (i + 1);
    }
  }
  return r;
}


x86 assembly (clang, -O0):
<bit_shuffle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e4 <bit_shuffle+0xb4>
mov    $0x0,%al
call   1050 <random@plt>
shl    $0x1,%eax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%eax
jl     11b7 <bit_shuffle+0x87>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
xor    $0xffffffffffffffff,%rax
and    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11d1 <bit_shuffle+0xa1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11d6 <bit_shuffle+0xa6>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    115a <bit_shuffle+0x2a>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bit_shuffle>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
test   %r15d,%r15d
jle    118b <bit_shuffle+0x5b>
mov    0x2e92(%rip),%r14
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1170 <bit_shuffle+0x40>
nopl   0x0(%rax)
lea    0x1(%rbp),%eax
bts    %rax,%rbx
add    $0x2,%rbp
cmp    %r15d,%ebp
jge    118b <bit_shuffle+0x5b>
xor    %eax,%eax
call   1050 <random@plt>
add    %eax,%eax
cmp    (%r14),%eax
jl     1160 <bit_shuffle+0x30>
bts    %rbp,%rbx
lea    0x1(%rbp),%eax
btr    %rax,%rbx
jmp    1167 <bit_shuffle+0x37>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i32 0
define i64 @bit_shuffle(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 @time(i32* null)
%6 = call i32 @srandom(i32 %5)
store i64 0, i64* %3
store i32 0, i32* %4
br label %7
7: ; preds = %37, %1
%8 = load i32, i32* %4
%9 = load i32, i32* %2
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %40
11: ; preds = %7
%12 = call i32 (...) @random()
%13 = mul nsw i32 %12, 2
%14 = load i32, i32* @RAND_MAX
%15 = icmp sge i32 %13, %14
br i1 %15, label %16, label %29
16: ; preds = %11
%17 = load i32, i32* %4
%18 = zext i32 %17 to i64
%19 = shl i64 1, %18
%20 = load i64, i64* %3
%21 = or i64 %20, %19
store i64 %21, i64* %3
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
%24 = zext i32 %23 to i64
%25 = shl i64 1, %24
%26 = xor i64 %25, -1
%27 = load i64, i64* %3
%28 = and i64 %27, %26
store i64 %28, i64* %3
br label %36
29: ; preds = %11
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
%32 = zext i32 %31 to i64
%33 = shl i64 1, %32
%34 = load i64, i64* %3
%35 = or i64 %34, %33
store i64 %35, i64* %3
br label %36
36: ; preds = %29, %16
br label %37
37: ; preds = %36
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 2
store i32 %39, i32* %4
br label %7
40: ; preds = %7
%41 = load i64, i64* %3
ret i64 %41
}

LLVM IR (-O2):
@RAND_MAX = global i32 0
define i64 @bit_shuffle(i32 %0) {
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srandom(i32 %2)
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %28
5: ; preds = %1, %23
%6 = phi i64 [ %25, %23 ], [ 0, %1 ]
%7 = phi i64 [ %24, %23 ], [ 0, %1 ]
%8 = tail call i32 (...) @random()
%9 = shl nsw i32 %8, 1
%10 = load i32, i32* @RAND_MAX
%11 = icmp slt i32 %9, %10
br i1 %11, label %19, label %12
12: ; preds = %5
%13 = shl nuw i64 1, %6
%14 = or i64 %13, %7
%15 = or i64 %6, 1
%16 = shl nuw i64 1, %15
%17 = xor i64 %16, -1
%18 = and i64 %14, %17
br label %23
19: ; preds = %5
%20 = or i64 %6, 1
%21 = shl nuw i64 1, %20
%22 = or i64 %21, %7
br label %23
23: ; preds = %12, %19
%24 = phi i64 [ %18, %12 ], [ %22, %19 ]
%25 = add nuw i64 %6, 2
%26 = trunc i64 %25 to i32
%27 = icmp slt i32 %26, %0
br i1 %27, label %5, label %28
28: ; preds = %23, %1
%29 = phi i64 [ 0, %1 ], [ %24, %23 ]
ret i64 %29
}