#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;
typedef int int64_t;

/* Variables and functions */
scalar_t__ printPrimitive(int);
int /*<<< orphan*/ printf(char *, ...);
int printHeapValue(uint64_t result) {
  if ((result & 0b00000111) == 0b00000001) {
    int64_t *car_addr = (uint64_t *)(result - 1);
    int64_t *cdr_addr = (uint64_t *)(result + 7);
    printf("(");
    if (printHeapValue(*car_addr)) {
      printf("Unknown value type %d", result);
      return 1;
    }
    printf(" ");
    printHeapValue(*cdr_addr);
    printf(")");
  } else {
    if (printPrimitive(result) != 0) {
      printf("Unknown value type %d", result);
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<printHeapValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x7,%eax
cmp    $0x1,%eax
jne    11cd <printHeapValue+0x9d>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x7,%eax
cltq
mov    %rax,-0x18(%rbp)
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <printHeapValue@plt>
cmp    $0x0,%eax
je     11a1 <printHeapValue+0x71>
mov    -0x8(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1208 <printHeapValue+0xd8>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <printHeapValue@plt>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1201 <printHeapValue+0xd1>
mov    -0x8(%rbp),%edi
call   1050 <printPrimitive@plt>
cmp    $0x0,%rax
je     11fc <printHeapValue+0xcc>
mov    -0x8(%rbp),%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1208 <printHeapValue+0xd8>
jmp    1201 <printHeapValue+0xd1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printHeapValue>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %edi,%eax
and    $0x7,%eax
cmp    $0x1,%eax
jne    1189 <printHeapValue+0x49>
movslq %ebx,%r14
mov    $0x28,%edi
call   1030 <putchar@plt>
mov    -0x1(%r14),%edi
call   1050 <printHeapValue@plt>
test   %eax,%eax
jne    1195 <printHeapValue+0x55>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    0x7(%r14),%edi
call   1050 <printHeapValue@plt>
mov    $0x29,%edi
call   1030 <putchar@plt>
jmp    11ac <printHeapValue+0x6c>
mov    %ebx,%edi
call   1060 <printPrimitive@plt>
test   %rax,%rax
je     11ac <printHeapValue+0x6c>
lea    0xe64(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
jmp    11ae <printHeapValue+0x6e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"(\00"
@.str.1 = [22 x i8] c"Unknown value type %d\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c")\00"
define i32 @printHeapValue(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = and i32 %6, 7
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %32
9: ; preds = %1
%10 = load i32, i32* %3
%11 = sub nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %4
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 7
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i32*
store i32* %17, i32** %5
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = load i32*, i32** %4
%20 = load i32, i32* %19
%21 = call i32 @printHeapValue(i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %9
%24 = load i32, i32* %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %24)
store i32 1, i32* %2
br label %41
26: ; preds = %9
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32*, i32** %5
%29 = load i32, i32* %28
%30 = call i32 @printHeapValue(i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %40
32: ; preds = %1
%33 = load i32, i32* %3
%34 = call i64 @printPrimitive(i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i32, i32* %3
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %37)
store i32 1, i32* %2
br label %41
39: ; preds = %32
br label %40
40: ; preds = %39, %26
store i32 0, i32* %2
br label %41
41: ; preds = %40, %36, %23
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"Unknown value type %d\00"
define i32 @printHeapValue(i32 %0) {
%2 = and i32 %0, 7
%3 = icmp eq i32 %2, 1
br i1 %3, label %4, label %24
4: ; preds = %1
%5 = add nsw i32 %0, -1
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i32*
%8 = tail call i32 @putchar(i32 40)
%9 = load i32, i32* %7
%10 = tail call i32 @printHeapValue(i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %22
12: ; preds = %27, %22, %24, %14
%13 = phi i32 [ 0, %14 ], [ 1, %22 ], [ 1, %27 ], [ 0, %24 ]
ret i32 %13
14: ; preds = %4
%15 = add nsw i32 %0, 7
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i32*
%18 = tail call i32 @putchar(i32 32)
%19 = load i32, i32* %17
%20 = tail call i32 @printHeapValue(i32 %19)
%21 = tail call i32 @putchar(i32 41)
br label %12
22: ; preds = %4
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %12
24: ; preds = %1
%25 = tail call i64 @printPrimitive(i32 %0)
%26 = icmp eq i64 %25, 0
br i1 %26, label %12, label %27
27: ; preds = %24
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %12
}