#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 UINT64_C(int);
int rolx(int, int);
int rorx(int, int);
uint64_t mirror(uint64_t u) {
  u = (u & UINT64_C(0x5555555555555555)) << 1 |
      ((u >> 1) & UINT64_C(0x5555555555555555));
  u = (u & UINT64_C(0x3333333333333333)) << 2 |
      ((u >> 2) & UINT64_C(0x3333333333333333));
  u = (u & UINT64_C(0x0f0f0f0f0f0f0f0f)) << 4 |
      ((u >> 4) & UINT64_C(0x0f0f0f0f0f0f0f0f));
  u = rorx(u & UINT64_C(0x00ff00ff00ff00ff), 8) |
      (rolx(u, 8) & UINT64_C(0x00ff00ff00ff00ff));
  return u;
}


x86 assembly (clang, -O0):
<mirror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    $0x55555555,%edi
call   1030 <UINT64_C@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
and    %ecx,%eax
shl    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    $0x55555555,%edi
call   1030 <UINT64_C@plt>
mov    -0x30(%rbp),%ecx
mov    %eax,%edx
mov    -0x2c(%rbp),%eax
and    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x33333333,%edi
call   1030 <UINT64_C@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
and    %ecx,%eax
shl    $0x2,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    $0x33333333,%edi
call   1030 <UINT64_C@plt>
mov    -0x24(%rbp),%ecx
mov    %eax,%edx
mov    -0x20(%rbp),%eax
and    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0xf0f0f0f,%edi
call   1030 <UINT64_C@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
and    %ecx,%eax
shl    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x18(%rbp)
mov    $0xf0f0f0f,%edi
call   1030 <UINT64_C@plt>
mov    -0x18(%rbp),%ecx
mov    %eax,%edx
mov    -0x14(%rbp),%eax
and    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0xff00ff,%edi
call   1030 <UINT64_C@plt>
mov    -0x10(%rbp),%edi
and    %eax,%edi
mov    $0x8,%esi
call   1040 <rorx@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1050 <rolx@plt>
mov    %eax,-0xc(%rbp)
mov    $0xff00ff,%edi
call   1030 <UINT64_C@plt>
mov    -0xc(%rbp),%ecx
mov    %eax,%edx
mov    -0x8(%rbp),%eax
and    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mirror>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x55555555,%edi
call   1030 <UINT64_C@plt>
and    %ebx,%eax
lea    (%rax,%rax,1),%ebp
sar    %ebx
mov    $0x55555555,%edi
call   1030 <UINT64_C@plt>
and    %eax,%ebx
or     %ebp,%ebx
mov    $0x33333333,%edi
call   1030 <UINT64_C@plt>
and    %ebx,%eax
lea    0x0(,%rax,4),%ebp
sar    $0x2,%ebx
mov    $0x33333333,%edi
call   1030 <UINT64_C@plt>
and    %eax,%ebx
or     %ebp,%ebx
mov    $0xf0f0f0f,%edi
call   1030 <UINT64_C@plt>
mov    %eax,%ebp
and    %ebx,%ebp
shl    $0x4,%ebp
sar    $0x4,%ebx
mov    $0xf0f0f0f,%edi
call   1030 <UINT64_C@plt>
and    %eax,%ebx
or     %ebp,%ebx
mov    $0xff00ff,%edi
call   1030 <UINT64_C@plt>
and    %ebx,%eax
mov    %eax,%edi
mov    $0x8,%esi
call   1040 <rorx@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    $0x8,%esi
call   1050 <rolx@plt>
mov    %eax,%ebx
mov    $0xff00ff,%edi
call   1030 <UINT64_C@plt>
and    %ebx,%eax
or     %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mirror(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i32 @UINT64_C(i32 1431655765)
%5 = and i32 %3, %4
%6 = shl i32 %5, 1
%7 = load i32, i32* %2
%8 = ashr i32 %7, 1
%9 = call i32 @UINT64_C(i32 1431655765)
%10 = and i32 %8, %9
%11 = or i32 %6, %10
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = call i32 @UINT64_C(i32 858993459)
%14 = and i32 %12, %13
%15 = shl i32 %14, 2
%16 = load i32, i32* %2
%17 = ashr i32 %16, 2
%18 = call i32 @UINT64_C(i32 858993459)
%19 = and i32 %17, %18
%20 = or i32 %15, %19
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = call i32 @UINT64_C(i32 252645135)
%23 = and i32 %21, %22
%24 = shl i32 %23, 4
%25 = load i32, i32* %2
%26 = ashr i32 %25, 4
%27 = call i32 @UINT64_C(i32 252645135)
%28 = and i32 %26, %27
%29 = or i32 %24, %28
store i32 %29, i32* %2
%30 = load i32, i32* %2
%31 = call i32 @UINT64_C(i32 16711935)
%32 = and i32 %30, %31
%33 = call i32 @rorx(i32 %32, i32 8)
%34 = load i32, i32* %2
%35 = call i32 @rolx(i32 %34, i32 8)
%36 = call i32 @UINT64_C(i32 16711935)
%37 = and i32 %35, %36
%38 = or i32 %33, %37
store i32 %38, i32* %2
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
define i32 @mirror(i32 %0) {
%2 = tail call i32 @UINT64_C(i32 1431655765)
%3 = and i32 %2, %0
%4 = shl i32 %3, 1
%5 = ashr i32 %0, 1
%6 = tail call i32 @UINT64_C(i32 1431655765)
%7 = and i32 %6, %5
%8 = or i32 %4, %7
%9 = tail call i32 @UINT64_C(i32 858993459)
%10 = and i32 %8, %9
%11 = shl i32 %10, 2
%12 = ashr i32 %8, 2
%13 = tail call i32 @UINT64_C(i32 858993459)
%14 = and i32 %12, %13
%15 = or i32 %11, %14
%16 = tail call i32 @UINT64_C(i32 252645135)
%17 = and i32 %15, %16
%18 = shl i32 %17, 4
%19 = ashr i32 %15, 4
%20 = tail call i32 @UINT64_C(i32 252645135)
%21 = and i32 %19, %20
%22 = or i32 %18, %21
%23 = tail call i32 @UINT64_C(i32 16711935)
%24 = and i32 %22, %23
%25 = tail call i32 @rorx(i32 %24, i32 8)
%26 = tail call i32 @rolx(i32 %22, i32 8)
%27 = tail call i32 @UINT64_C(i32 16711935)
%28 = and i32 %27, %26
%29 = or i32 %28, %25
ret i32 %29
}