#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 */
unsigned long long horizontal_mirror(unsigned long long);
unsigned long long transpose(unsigned long long);
unsigned long long vertical_mirror(unsigned long long);
unsigned long long shape_unique(unsigned long long shape) {
  unsigned long long sym, unique;
  int i;
  unique = shape;
  for (i = 1; i < 8; ++i) {
    sym = shape;
    if (i & 1)
      sym = horizontal_mirror(sym);
    if (i & 2)
      sym = vertical_mirror(sym);
    if (i & 4)
      sym = transpose(sym);
    if (unique > sym)
      unique = sym;
  }
  return unique;
}


x86 assembly (clang, -O0):
<shape_unique>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    11da <shape_unique+0xaa>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1179 <shape_unique+0x49>
mov    -0x10(%rbp),%rdi
call   1040 <horizontal_mirror@plt>
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1195 <shape_unique+0x65>
mov    -0x10(%rbp),%rdi
call   1050 <vertical_mirror@plt>
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11b1 <shape_unique+0x81>
mov    -0x10(%rbp),%rdi
call   1030 <transpose@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    11c7 <shape_unique+0x97>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11cc <shape_unique+0x9c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114b <shape_unique+0x1b>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shape_unique>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <horizontal_mirror@plt>
mov    %rax,%rbx
cmp    %r14,%rax
cmovae %r14,%rbx
mov    %r14,%rdi
call   1050 <vertical_mirror@plt>
mov    %rax,%r15
cmp    %rax,%rbx
cmovbe %rbx,%r15
mov    %r14,%rdi
call   1040 <horizontal_mirror@plt>
mov    %rax,%rdi
call   1050 <vertical_mirror@plt>
mov    %rax,%rbx
cmp    %rax,%r15
cmovbe %r15,%rbx
mov    %r14,%rdi
call   1030 <transpose@plt>
mov    %rax,%r15
cmp    %rax,%rbx
cmovbe %rbx,%r15
mov    %r14,%rdi
call   1040 <horizontal_mirror@plt>
mov    %rax,%rdi
call   1030 <transpose@plt>
mov    %rax,%rbx
cmp    %rax,%r15
cmovbe %r15,%rbx
mov    %r14,%rdi
call   1050 <vertical_mirror@plt>
mov    %rax,%rdi
call   1030 <transpose@plt>
mov    %rax,%r15
cmp    %rax,%rbx
cmovbe %rbx,%r15
mov    %r14,%rdi
call   1040 <horizontal_mirror@plt>
mov    %rax,%rdi
call   1050 <vertical_mirror@plt>
mov    %rax,%rdi
call   1030 <transpose@plt>
cmp    %rax,%r15
cmovbe %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @shape_unique(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
store i64 %0, i64* %2
%6 = load i64, i64* %2
store i64 %6, i64* %4
store i32 1, i32* %5
br label %7
7: ; preds = %39, %1
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 8
br i1 %9, label %10, label %42
10: ; preds = %7
%11 = load i64, i64* %2
store i64 %11, i64* %3
%12 = load i32, i32* %5
%13 = and i32 %12, 1
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i64, i64* %3
%17 = call i64 @horizontal_mirror(i64 %16)
store i64 %17, i64* %3
br label %18
18: ; preds = %15, %10
%19 = load i32, i32* %5
%20 = and i32 %19, 2
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i64, i64* %3
%24 = call i64 @vertical_mirror(i64 %23)
store i64 %24, i64* %3
br label %25
25: ; preds = %22, %18
%26 = load i32, i32* %5
%27 = and i32 %26, 4
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i64, i64* %3
%31 = call i64 @transpose(i64 %30)
store i64 %31, i64* %3
br label %32
32: ; preds = %29, %25
%33 = load i64, i64* %4
%34 = load i64, i64* %3
%35 = icmp ugt i64 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = load i64, i64* %3
store i64 %37, i64* %4
br label %38
38: ; preds = %36, %32
br label %39
39: ; preds = %38
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %7
42: ; preds = %7
%43 = load i64, i64* %4
ret i64 %43
}

LLVM IR (-O2):
define i64 @shape_unique(i64 %0) {
%2 = tail call i64 @horizontal_mirror(i64 %0)
%3 = icmp ult i64 %2, %0
%4 = select i1 %3, i64 %2, i64 %0
%5 = tail call i64 @vertical_mirror(i64 %0)
%6 = icmp ugt i64 %4, %5
%7 = select i1 %6, i64 %5, i64 %4
%8 = tail call i64 @horizontal_mirror(i64 %0)
%9 = tail call i64 @vertical_mirror(i64 %8)
%10 = icmp ugt i64 %7, %9
%11 = select i1 %10, i64 %9, i64 %7
%12 = tail call i64 @transpose(i64 %0)
%13 = icmp ugt i64 %11, %12
%14 = select i1 %13, i64 %12, i64 %11
%15 = tail call i64 @horizontal_mirror(i64 %0)
%16 = tail call i64 @transpose(i64 %15)
%17 = icmp ugt i64 %14, %16
%18 = select i1 %17, i64 %16, i64 %14
%19 = tail call i64 @vertical_mirror(i64 %0)
%20 = tail call i64 @transpose(i64 %19)
%21 = icmp ugt i64 %18, %20
%22 = select i1 %21, i64 %20, i64 %18
%23 = tail call i64 @horizontal_mirror(i64 %0)
%24 = tail call i64 @vertical_mirror(i64 %23)
%25 = tail call i64 @transpose(i64 %24)
%26 = icmp ugt i64 %22, %25
%27 = select i1 %26, i64 %25, i64 %22
ret i64 %27
}