#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;

/* Variables and functions */
int CHAR_BIT;
int UINT64_C(int);
int /*<<< orphan*/ puts(char *);
int revbin64(int);
int /*<<< orphan*/ unit_test_checker(char *, int);
void revbin64_test(void) {
  uint64_t in = UINT64_C(0x0000000000000001);
  uint64_t out = UINT64_C(0x8000000000000000);
  int i = 0;
  int n = sizeof(uint64_t) * CHAR_BIT;
  puts("revbin64_test");
  unit_test_checker("revbin64(0) == 0", (revbin64(0) == 0));
  for (i = 0; i <= n; i++) {
    unit_test_checker("revbin64(in) == out", (revbin64(in) == out));
    in <<= 1;
    out >>= 1;
  }
  return;
}


x86 assembly (clang, -O0):
<revbin64_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x1,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x4(%rbp)
xor    %edi,%edi
call   1030 <UINT64_C@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e73(%rip),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,-0x10(%rbp)
lea    0xe82(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1050 <revbin64@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe72(%rip),%rdi
call   1060 <unit_test_checker@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11f3 <revbin64_test+0xb3>
mov    -0x4(%rbp),%edi
call   1050 <revbin64@plt>
cmp    -0x8(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe51(%rip),%rdi
call   1060 <unit_test_checker@plt>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a8 <revbin64_test+0x68>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<revbin64_test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%edi
call   1030 <UINT64_C@plt>
mov    %eax,%ebx
xor    %edi,%edi
call   1030 <UINT64_C@plt>
mov    %eax,%ebp
mov    0x2e7d(%rip),%rax
mov    (%rax),%r15d
shl    $0x2,%r15d
lea    0xe8f(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1050 <revbin64@plt>
xor    %esi,%esi
test   %eax,%eax
sete   %sil
lea    0xe82(%rip),%rdi
call   1060 <unit_test_checker@plt>
test   %r15d,%r15d
js     11d1 <revbin64_test+0x91>
or     $0x1,%r15d
lea    0xe7e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1050 <revbin64@plt>
xor    %esi,%esi
cmp    %ebp,%eax
sete   %sil
mov    %r14,%rdi
call   1060 <unit_test_checker@plt>
add    %ebx,%ebx
sar    %ebp
add    $0xffffffff,%r15d
jne    11b0 <revbin64_test+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
@.str = [14 x i8] c"revbin64_test\00"
@.str.1 = [17 x i8] c"revbin64(0) == 0\00"
@.str.2 = [20 x i8] c"revbin64(in) == out\00"
define void @revbin64_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 @UINT64_C(i32 1)
store i32 %5, i32* %1
%6 = call i32 @UINT64_C(i32 0)
store i32 %6, i32* %2
store i32 0, i32* %3
%7 = load i32, i32* @CHAR_BIT
%8 = sext i32 %7 to i64
%9 = mul i64 4, %8
%10 = trunc i64 %9 to i32
store i32 %10, i32* %4
%11 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @revbin64(i32 0)
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @unit_test_checker(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 0, i32* %3
br label %16
16: ; preds = %31, %0
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %34
20: ; preds = %16
%21 = load i32, i32* %1
%22 = call i32 @revbin64(i32 %21)
%23 = load i32, i32* %2
%24 = icmp eq i32 %22, %23
%25 = zext i1 %24 to i32
%26 = call i32 @unit_test_checker(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %1
%28 = shl i32 %27, 1
store i32 %28, i32* %1
%29 = load i32, i32* %2
%30 = ashr i32 %29, 1
store i32 %30, i32* %2
br label %31
31: ; preds = %20
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %16
34: ; preds = %16
ret void
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
@.str = [14 x i8] c"revbin64_test\00"
@.str.1 = [17 x i8] c"revbin64(0) == 0\00"
@.str.2 = [20 x i8] c"revbin64(in) == out\00"
define void @revbin64_test() {
%1 = tail call i32 @UINT64_C(i32 1)
%2 = tail call i32 @UINT64_C(i32 0)
%3 = load i32, i32* @CHAR_BIT
%4 = shl i32 %3, 2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @revbin64(i32 0)
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @unit_test_checker(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %4, 0
br i1 %10, label %25, label %11
11: ; preds = %0
%12 = or i32 %4, 1
br label %13
13: ; preds = %11, %13
%14 = phi i32 [ %21, %13 ], [ %1, %11 ]
%15 = phi i32 [ %23, %13 ], [ 0, %11 ]
%16 = phi i32 [ %22, %13 ], [ %2, %11 ]
%17 = tail call i32 @revbin64(i32 %14)
%18 = icmp eq i32 %17, %16
%19 = zext i1 %18 to i32
%20 = tail call i32 @unit_test_checker(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = shl i32 %14, 1
%22 = ashr i32 %16, 1
%23 = add nuw nsw i32 %15, 1
%24 = icmp eq i32 %23, %12
br i1 %24, label %25, label %13
25: ; preds = %13, %0
ret void
}