#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 */
int /*<<< orphan*/ printf(char *, ...);
void print_ptr(long val) {
  if (val == 47) {
    printf("()");
  } else if ((val & 3) == 0) {
    printf("%ld", val >> 2);
  } else if ((val & 255) == 15) {
    printf("%c", (int)(val >> 8));
  } else if ((val & 127) == 31) {
    if ((val >> 7) == 1) {
      printf("#t");
    } else if ((val >> 7) == 0) {
      printf("#f");
    } else {
      printf("bad bool: %d", val >> 7);
    }
  } else {
    printf("unkown type for value: %ld", val);
  }
}


x86 assembly (clang, -O0):
<print_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x2f,-0x8(%rbp)
jne    113a <print_ptr+0x2a>
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1235 <print_ptr+0x125>
mov    -0x8(%rbp),%rax
and    $0x3,%rax
cmp    $0x0,%rax
jne    1167 <print_ptr+0x57>
mov    -0x8(%rbp),%rsi
sar    $0x2,%rsi
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1230 <print_ptr+0x120>
mov    -0x8(%rbp),%rax
and    $0xff,%rax
cmp    $0xf,%rax
jne    1198 <print_ptr+0x88>
mov    -0x8(%rbp),%rax
sar    $0x8,%rax
mov    %eax,%esi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122b <print_ptr+0x11b>
mov    -0x8(%rbp),%rax
and    $0x7f,%rax
cmp    $0x1f,%rax
jne    1214 <print_ptr+0x104>
mov    -0x8(%rbp),%rax
sar    $0x7,%rax
cmp    $0x1,%rax
jne    11cf <print_ptr+0xbf>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120f <print_ptr+0xff>
mov    -0x8(%rbp),%rax
sar    $0x7,%rax
cmp    $0x0,%rax
jne    11f4 <print_ptr+0xe4>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120a <print_ptr+0xfa>
mov    -0x8(%rbp),%rsi
sar    $0x7,%rsi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120f <print_ptr+0xff>
jmp    1226 <print_ptr+0x116>
mov    -0x8(%rbp),%rsi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122b <print_ptr+0x11b>
jmp    1230 <print_ptr+0x120>
jmp    1235 <print_ptr+0x125>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ptr>:
cmp    $0x2f,%rdi
jne    1134 <print_ptr+0x14>
lea    0xed3(%rip),%rdi
xor    %eax,%eax
jmp    1040 <printf@plt>
mov    %rdi,%rax
test   $0x3,%al
je     114a <print_ptr+0x2a>
cmp    $0xf,%al
jne    1157 <print_ptr+0x37>
shr    $0x8,%rax
mov    %eax,%edi
jmp    1030 <putchar@plt>
sar    $0x2,%rax
lea    0xed8(%rip),%rdi
jmp    1183 <print_ptr+0x63>
mov    %eax,%ecx
and    $0x7f,%ecx
cmp    $0x1f,%ecx
jne    117c <print_ptr+0x5c>
mov    %rax,%rsi
sar    $0x7,%rsi
cmp    $0x1,%rsi
jne    118d <print_ptr+0x6d>
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
jmp    1040 <printf@plt>
lea    0xe93(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
jmp    1040 <printf@plt>
cmp    $0x7f,%rax
ja     11a1 <print_ptr+0x81>
lea    0xe6c(%rip),%rdi
xor    %eax,%eax
jmp    1040 <printf@plt>
lea    0xe61(%rip),%rdi
xor    %eax,%eax
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"()\00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [3 x i8] c"#t\00"
@.str.4 = [3 x i8] c"#f\00"
@.str.5 = [13 x i8] c"bad bool: %d\00"
@.str.6 = [27 x i8] c"unkown type for value: %ld\00"
define void @print_ptr(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = icmp eq i64 %3, 47
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %52
7: ; preds = %1
%8 = load i64, i64* %2
%9 = and i64 %8, 3
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i64, i64* %2
%13 = ashr i64 %12, 2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %13)
br label %51
15: ; preds = %7
%16 = load i64, i64* %2
%17 = and i64 %16, 255
%18 = icmp eq i64 %17, 15
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i64, i64* %2
%21 = ashr i64 %20, 8
%22 = trunc i64 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %50
24: ; preds = %15
%25 = load i64, i64* %2
%26 = and i64 %25, 127
%27 = icmp eq i64 %26, 31
br i1 %27, label %28, label %46
28: ; preds = %24
%29 = load i64, i64* %2
%30 = ashr i64 %29, 7
%31 = icmp eq i64 %30, 1
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %45
34: ; preds = %28
%35 = load i64, i64* %2
%36 = ashr i64 %35, 7
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %44
40: ; preds = %34
%41 = load i64, i64* %2
%42 = ashr i64 %41, 7
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i64 %42)
br label %44
44: ; preds = %40, %38
br label %45
45: ; preds = %44, %32
br label %49
46: ; preds = %24
%47 = load i64, i64* %2
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i64 %47)
br label %49
49: ; preds = %46, %45
br label %50
50: ; preds = %49, %19
br label %51
51: ; preds = %50, %11
br label %52
52: ; preds = %51, %5
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"()\00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.3 = [3 x i8] c"#t\00"
@.str.4 = [3 x i8] c"#f\00"
@.str.5 = [13 x i8] c"bad bool: %d\00"
@.str.6 = [27 x i8] c"unkown type for value: %ld\00"
define void @print_ptr(i64 %0) {
%2 = icmp eq i64 %0, 47
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %34
5: ; preds = %1
%6 = and i64 %0, 3
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = ashr i64 %0, 2
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %9)
br label %34
11: ; preds = %5
%12 = and i64 %0, 255
%13 = icmp eq i64 %12, 15
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = lshr i64 %0, 8
%16 = trunc i64 %15 to i32
%17 = tail call i32 @putchar(i32 %16)
br label %34
18: ; preds = %11
%19 = and i64 %0, 127
%20 = icmp eq i64 %19, 31
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = ashr i64 %0, 7
%23 = icmp eq i64 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %34
26: ; preds = %21
%27 = icmp ult i64 %0, 128
br i1 %27, label %28, label %30
28: ; preds = %26
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %34
30: ; preds = %26
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i64 %22)
br label %34
32: ; preds = %18
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i64 %0)
br label %34
34: ; preds = %8, %32, %28, %30, %24, %14, %3
ret void
}