#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 int uint64_t;
typedef int /*<<< orphan*/ src0;

/* Variables and functions */
int CHAR_BIT;
uint64_t __hsail_bitrev_u64(uint64_t src0) {
  uint64_t v = src0;
  uint64_t r = v;
  int s = sizeof(src0) * CHAR_BIT - 1;
  for (v >>= 1; v; v >>= 1) {
    r <<= 1;
    r |= v & 1;
    s--;
  }
  return r << s;
}


x86 assembly (clang, -O0):
<__hsail_bitrev_u64>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2ec6(%rip),%rax
movslq (%rax),%rax
shl    $0x2,%rax
sub    $0x1,%rax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1167 <__hsail_bitrev_u64+0x67>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0x1,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1131 <__hsail_bitrev_u64+0x31>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
shl    %cl,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<__hsail_bitrev_u64>:
mov    0x2ed9(%rip),%rax
mov    (%rax),%eax
lea    -0x1(,%rax,4),%ecx
cmp    $0x2,%edi
jae    1119 <__hsail_bitrev_u64+0x19>
mov    %edi,%eax
jmp    1134 <__hsail_bitrev_u64+0x34>
mov    %edi,%eax
mov    %edi,%edx
nopl   (%rax)
sar    %edx
mov    %edx,%esi
and    $0x1,%esi
lea    (%rsi,%rax,2),%eax
add    $0xffffffff,%ecx
cmp    $0x3,%edi
mov    %edx,%edi
ja     1120 <__hsail_bitrev_u64+0x20>
shl    %cl,%eax
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
define i32 @__hsail_bitrev_u64(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
store i32 %6, i32* %3
%7 = load i32, i32* %3
store i32 %7, i32* %4
%8 = load i32, i32* @CHAR_BIT
%9 = sext i32 %8 to i64
%10 = mul i64 4, %9
%11 = sub i64 %10, 1
%12 = trunc i64 %11 to i32
store i32 %12, i32* %5
%13 = load i32, i32* %3
%14 = ashr i32 %13, 1
store i32 %14, i32* %3
br label %15
15: ; preds = %27, %1
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %15
%19 = load i32, i32* %4
%20 = shl i32 %19, 1
store i32 %20, i32* %4
%21 = load i32, i32* %3
%22 = and i32 %21, 1
%23 = load i32, i32* %4
%24 = or i32 %23, %22
store i32 %24, i32* %4
%25 = load i32, i32* %5
%26 = add nsw i32 %25, -1
store i32 %26, i32* %5
br label %27
27: ; preds = %18
%28 = load i32, i32* %3
%29 = ashr i32 %28, 1
store i32 %29, i32* %3
br label %15
30: ; preds = %15
%31 = load i32, i32* %4
%32 = load i32, i32* %5
%33 = shl i32 %31, %32
ret i32 %33
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
define i32 @__hsail_bitrev_u64(i32 %0) {
%2 = load i32, i32* @CHAR_BIT
%3 = shl i32 %2, 2
%4 = add i32 %3, -1
%5 = icmp ult i32 %0, 2
br i1 %5, label %16, label %6
6: ; preds = %1, %6
%7 = phi i32 [ %10, %6 ], [ %0, %1 ]
%8 = phi i32 [ %14, %6 ], [ %4, %1 ]
%9 = phi i32 [ %13, %6 ], [ %0, %1 ]
%10 = ashr i32 %7, 1
%11 = shl i32 %9, 1
%12 = and i32 %10, 1
%13 = or i32 %11, %12
%14 = add i32 %8, -1
%15 = icmp ult i32 %7, 4
br i1 %15, label %16, label %6
16: ; preds = %6, %1
%17 = phi i32 [ %0, %1 ], [ %13, %6 ]
%18 = phi i32 [ %4, %1 ], [ %14, %6 ]
%19 = shl i32 %17, %18
ret i32 %19
}