#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 uint32_t;
typedef int uint16_t;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void printRef(uint32_t ref) {
  if ((ref & 0x00000003) == 0x0) {
    int32_t theInt = ref >> 2;
    printf("  Integer: 0x%08X (%d)", theInt, theInt);
  } else if ((ref & 0x00000003) == 0x1) {
    printf("  Pointer: 0x%08X", ref >> 2);
  } else if ((ref & 0xfff0000f) == 0xa) {
    uint16_t wc = (ref >> 4);
    printf("  Character: 0x%04x", wc);
  } else if ((ref & 0x00000003) == 0x2) {
    printf("  Special: 0x%08X", ref >> 2);
  } else if ((ref & 0x00000003) == 0x3) {
    uint32_t table = (ref & 0xffff0000) >> 16;
    uint32_t index = (ref & 0x0000ffff) >> 2;
    printf("  MagicPtr: table %u, index %u", table, index);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<printRef>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
jne    114c <printRef+0x3c>
mov    -0x4(%rbp),%eax
sar    $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121f <printRef+0x10f>
mov    -0x4(%rbp),%eax
and    $0x3,%eax
cmp    $0x1,%eax
jne    1174 <printRef+0x64>
mov    -0x4(%rbp),%esi
sar    $0x2,%esi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121a <printRef+0x10a>
mov    -0x4(%rbp),%eax
and    $0xfff0000f,%eax
cmp    $0xa,%eax
jne    11a4 <printRef+0x94>
mov    -0x4(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1215 <printRef+0x105>
mov    -0x4(%rbp),%eax
and    $0x3,%eax
cmp    $0x2,%eax
jne    11cc <printRef+0xbc>
mov    -0x4(%rbp),%esi
sar    $0x2,%esi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1210 <printRef+0x100>
mov    -0x4(%rbp),%eax
and    $0x3,%eax
cmp    $0x3,%eax
jne    120b <printRef+0xfb>
mov    -0x4(%rbp),%eax
and    $0xffff0000,%eax
shr    $0x10,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
and    $0xffff,%eax
sar    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1210 <printRef+0x100>
jmp    1215 <printRef+0x105>
jmp    121a <printRef+0x10a>
jmp    121f <printRef+0x10f>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printRef>:
push   %rax
mov    %edi,%edx
mov    %edi,%eax
and    $0x3,%eax
cmp    $0x1,%eax
je     113f <printRef+0x1f>
test   %eax,%eax
jne    114b <printRef+0x2b>
sar    $0x2,%edx
lea    0xec5(%rip),%rdi
mov    %edx,%esi
jmp    1193 <printRef+0x73>
sar    $0x2,%edx
lea    0xece(%rip),%rdi
jmp    1173 <printRef+0x53>
mov    %edx,%ecx
and    $0xfff0000f,%ecx
cmp    $0xa,%ecx
jne    1164 <printRef+0x44>
shr    $0x4,%edx
lea    0xec7(%rip),%rdi
jmp    1173 <printRef+0x53>
cmp    $0x2,%eax
jne    117e <printRef+0x5e>
sar    $0x2,%edx
lea    0xeca(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    119a <printRef+0x7a>
mov    %edx,%esi
shr    $0x10,%esi
shr    $0x2,%edx
and    $0x3fff,%edx
lea    0xebc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
pop    %rax
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [23 x i8] c" Integer: 0x%08X (%d)\00"
@.str.1 = [18 x i8] c" Pointer: 0x%08X\00"
@.str.2 = [20 x i8] c" Character: 0x%04x\00"
@.str.3 = [18 x i8] c" Special: 0x%08X\00"
@.str.4 = [31 x i8] c" MagicPtr: table %u, index %u\00"
@.str.5 = [2 x i8] c"\0A\00"
define void @printRef(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = and i32 %7, 3
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = load i32, i32* %2
%12 = ashr i32 %11, 2
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
br label %59
16: ; preds = %1
%17 = load i32, i32* %2
%18 = and i32 %17, 3
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* %2
%22 = ashr i32 %21, 2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %58
24: ; preds = %16
%25 = load i32, i32* %2
%26 = and i32 %25, -1048561
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i32, i32* %2
%30 = ashr i32 %29, 4
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %57
33: ; preds = %24
%34 = load i32, i32* %2
%35 = and i32 %34, 3
%36 = icmp eq i32 %35, 2
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i32, i32* %2
%39 = ashr i32 %38, 2
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %39)
br label %56
41: ; preds = %33
%42 = load i32, i32* %2
%43 = and i32 %42, 3
%44 = icmp eq i32 %43, 3
br i1 %44, label %45, label %55
45: ; preds = %41
%46 = load i32, i32* %2
%47 = and i32 %46, -65536
%48 = lshr i32 %47, 16
store i32 %48, i32* %5
%49 = load i32, i32* %2
%50 = and i32 %49, 65535
%51 = ashr i32 %50, 2
store i32 %51, i32* %6
%52 = load i32, i32* %5
%53 = load i32, i32* %6
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %52, i32 %53)
br label %55
55: ; preds = %45, %41
br label %56
56: ; preds = %55, %37
br label %57
57: ; preds = %56, %28
br label %58
58: ; preds = %57, %20
br label %59
59: ; preds = %58, %10
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c" Integer: 0x%08X (%d)\00"
@.str.1 = [18 x i8] c" Pointer: 0x%08X\00"
@.str.2 = [20 x i8] c" Character: 0x%04x\00"
@.str.3 = [18 x i8] c" Special: 0x%08X\00"
@.str.4 = [31 x i8] c" MagicPtr: table %u, index %u\00"
define void @printRef(i32 %0) {
%2 = and i32 %0, 3
switch i32 %2, label %9 [
i32 0, label %3
i32 1, label %6
]
3: ; preds = %1
%4 = ashr i32 %0, 2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %4)
br label %25
6: ; preds = %1
%7 = ashr i32 %0, 2
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %25
9: ; preds = %1
%10 = and i32 %0, -1048561
%11 = icmp eq i32 %10, 10
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = lshr i32 %0, 4
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %25
15: ; preds = %9
%16 = icmp eq i32 %2, 2
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = ashr i32 %0, 2
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %25
20: ; preds = %15
%21 = lshr i32 %0, 16
%22 = lshr i32 %0, 2
%23 = and i32 %22, 16383
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %21, i32 %23)
br label %25
25: ; preds = %6, %17, %20, %12, %3
%26 = tail call i32 @putchar(i32 10)
ret void
}