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

/* Variables and functions */
int morton(int);
int /*<<< orphan*/ printf(char *, ...);
void generate_morton(char a) {
  int i;
  printf("static const word_t morton_table%c[256] = \n{\n ", a ? '1' : '0');
  for (i = 0; i < 256; i++) {
    if (i % 8 == 0 && i > 0)
      printf("\n ");
    uint16_t m = morton(i);
    if (a)
      m <<= 1;
    printf(" 0x%04X%c", m, i == 255 ? '\n' : ',');
  }
  printf("};\n\n");
}


x86 assembly (clang, -O0):
<generate_morton>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%ecx
mov    $0x30,%esi
mov    $0x31,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x100,-0x8(%rbp)
jge    11e3 <generate_morton+0xc3>
mov    -0x8(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1190 <generate_morton+0x70>
cmpl   $0x0,-0x8(%rbp)
jle    1190 <generate_morton+0x70>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <morton@plt>
mov    %eax,-0xc(%rbp)
cmpb   $0x0,-0x1(%rbp)
je     11ae <generate_morton+0x8e>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%ecx
mov    $0x2c,%edx
mov    $0xa,%eax
cmp    $0xff,%ecx
cmove  %eax,%edx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1157 <generate_morton+0x37>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_morton>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %esi,%esi
test   %dil,%dil
setne  %bl
sete   %sil
xor    $0x31,%esi
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed0(%rip),%r14
mov    $0xa,%r12d
lea    0xec6(%rip),%r15
xor    %ebp,%ebp
jmp    11a1 <generate_morton+0x71>
nopl   (%rax)
mov    %ebp,%edi
call   1050 <morton@plt>
mov    %ebx,%ecx
shl    %cl,%eax
cmp    $0xff,%ebp
mov    $0x2c,%edx
cmove  %r12d,%edx
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    $0x100,%ebp
je     11b8 <generate_morton+0x88>
test   %ebp,%ebp
je     1170 <generate_morton+0x40>
mov    %ebp,%eax
and    $0x7,%eax
jne    1170 <generate_morton+0x40>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1170 <generate_morton+0x40>
lea    0xe7a(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"static const word_t morton_table%c[256] = \0A{\0A \00"
@.str.1 = [3 x i8] c"\0A \00"
@.str.2 = [10 x i8] c" 0x%04X%c\00"
@.str.3 = [5 x i8] c"};\0A\0A\00"
define void @generate_morton(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
store i8 %0, i8* %2
%5 = load i8, i8* %2
%6 = sext i8 %5 to i32
%7 = icmp ne i32 %6, 0
%8 = zext i1 %7 to i64
%9 = select i1 %7, i32 49, i32 48
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 0, i32* %3
br label %11
11: ; preds = %38, %1
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 256
br i1 %13, label %14, label %41
14: ; preds = %11
%15 = load i32, i32* %3
%16 = srem i32 %15, 8
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* %3
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %18, %14
%24 = load i32, i32* %3
%25 = call i32 @morton(i32 %24)
store i32 %25, i32* %4
%26 = load i8, i8* %2
%27 = icmp ne i8 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i32, i32* %4
%30 = shl i32 %29, 1
store i32 %30, i32* %4
br label %31
31: ; preds = %28, %23
%32 = load i32, i32* %4
%33 = load i32, i32* %3
%34 = icmp eq i32 %33, 255
%35 = zext i1 %34 to i64
%36 = select i1 %34, i32 10, i32 44
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %32, i32 %36)
br label %38
38: ; preds = %31
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %11
41: ; preds = %11
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [47 x i8] c"static const word_t morton_table%c[256] = \0A{\0A \00"
@.str.1 = [3 x i8] c"\0A \00"
@.str.2 = [10 x i8] c" 0x%04X%c\00"
@str = [4 x i8] c"};\0A\00"
define void @generate_morton(i8 signext %0) {
%2 = icmp eq i8 %0, 0
%3 = select i1 %2, i32 48, i32 49
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = xor i1 %2, true
%6 = zext i1 %5 to i32
br label %7
7: ; preds = %1, %15
%8 = phi i32 [ 0, %1 ], [ %21, %15 ]
%9 = and i32 %8, 7
%10 = icmp eq i32 %9, 0
%11 = icmp ne i32 %8, 0
%12 = and i1 %11, %10
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %7
%16 = tail call i32 @morton(i32 %8)
%17 = shl i32 %16, %6
%18 = icmp eq i32 %8, 255
%19 = select i1 %18, i32 10, i32 44
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %19)
%21 = add nuw nsw i32 %8, 1
%22 = icmp eq i32 %21, 256
br i1 %22, label %23, label %7
23: ; preds = %15
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
ret void
}