#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 scalar_t__ bp;

/* Variables and functions */
int /*<<< orphan*/ checkheap(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, void *, ...);
void printblock(void *bp) {
  size_t hsize, halloc, fsize, falloc;
  checkheap(0);
  hsize = ((*(unsigned int *)(((char *)(bp)-4))) & ~0x7);
  halloc = ((*(unsigned int *)(((char *)(bp)-4))) & 0x1);
  fsize = ((*(unsigned int *)(((char *)(bp) +
                               ((*(unsigned int *)(((char *)(bp)-4))) & ~0x7) -
                               8))) &
           ~0x7);
  falloc = ((*(unsigned int *)(((char *)(bp) +
                                ((*(unsigned int *)(((char *)(bp)-4))) & ~0x7) -
                                8))) &
            0x1);
  if (hsize == 0) {
    printf("%p: EOL\n", bp);
    return;
  }
  printf("%p: header: [%ld:%c] footer: [%ld:%c]\n", bp, hsize,
         (halloc ? 'a' : 'f'), fsize, (falloc ? 'a' : 'f'));
}


x86 assembly (clang, -O0):
<printblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
xor    %edi,%edi
call   1040 <checkheap@plt>
mov    -0x8(%rbp),%rax
mov    -0x4(%rax),%eax
and    $0xfffffff8,%eax
mov    %eax,%eax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x4(%rax),%eax
and    $0x1,%eax
mov    %eax,%eax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x4(%rcx),%ecx
and    $0xfffffff8,%ecx
mov    %ecx,%ecx
mov    -0x8(%rax,%rcx,1),%eax
and    $0xfffffff8,%eax
mov    %eax,%eax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x4(%rcx),%ecx
and    $0xfffffff8,%ecx
mov    %ecx,%ecx
mov    -0x8(%rax,%rcx,1),%eax
and    $0x1,%eax
mov    %eax,%eax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11af <printblock+0x8f>
mov    -0x8(%rbp),%rsi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f5 <printblock+0xd5>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rdi
mov    $0x66,%ecx
mov    $0x61,%eax
cmp    $0x0,%rdi
cmovne %eax,%ecx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%rdi
mov    $0x66,%r9d
mov    $0x61,%eax
cmp    $0x0,%rdi
cmovne %eax,%r9d
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printblock>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
call   1040 <checkheap@plt>
mov    -0x4(%rbx),%eax
mov    %eax,%edx
and    $0xfffffff8,%edx
test   %rdx,%rdx
je     1173 <printblock+0x53>
mov    -0x8(%rbx,%rdx,1),%esi
mov    %esi,%r8d
and    $0xfffffff8,%r8d
xor    %ecx,%ecx
test   $0x1,%al
sete   %cl
lea    (%rcx,%rcx,4),%ecx
add    $0x61,%ecx
xor    %eax,%eax
test   $0x1,%sil
sete   %al
lea    (%rax,%rax,4),%r9d
add    $0x61,%r9d
lea    0xea1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>
lea    0xe86(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%p: EOL\0A\00"
@.str.1 = [39 x i8] c"%p: header: [%ld:%c] footer: [%ld:%c]\0A\00"
define void @printblock(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %2
%7 = call i32 @checkheap(i32 0)
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 -4
%10 = bitcast i8* %9 to i32*
%11 = load i32, i32* %10
%12 = and i32 %11, -8
%13 = zext i32 %12 to i64
store i64 %13, i64* %3
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 -4
%16 = bitcast i8* %15 to i32*
%17 = load i32, i32* %16
%18 = and i32 %17, 1
%19 = zext i32 %18 to i64
store i64 %19, i64* %4
%20 = load i8*, i8** %2
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i64 -4
%23 = bitcast i8* %22 to i32*
%24 = load i32, i32* %23
%25 = and i32 %24, -8
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %20, i64 %26
%28 = getelementptr inbounds i8, i8* %27, i64 -8
%29 = bitcast i8* %28 to i32*
%30 = load i32, i32* %29
%31 = and i32 %30, -8
%32 = zext i32 %31 to i64
store i64 %32, i64* %5
%33 = load i8*, i8** %2
%34 = load i8*, i8** %2
%35 = getelementptr inbounds i8, i8* %34, i64 -4
%36 = bitcast i8* %35 to i32*
%37 = load i32, i32* %36
%38 = and i32 %37, -8
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %33, i64 %39
%41 = getelementptr inbounds i8, i8* %40, i64 -8
%42 = bitcast i8* %41 to i32*
%43 = load i32, i32* %42
%44 = and i32 %43, 1
%45 = zext i32 %44 to i64
store i64 %45, i64* %6
%46 = load i64, i64* %3
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %1
%49 = load i8*, i8** %2
%50 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %49)
br label %64
51: ; preds = %1
%52 = load i8*, i8** %2
%53 = load i64, i64* %3
%54 = load i64, i64* %4
%55 = icmp ne i64 %54, 0
%56 = zext i1 %55 to i64
%57 = select i1 %55, i32 97, i32 102
%58 = load i64, i64* %5
%59 = load i64, i64* %6
%60 = icmp ne i64 %59, 0
%61 = zext i1 %60 to i64
%62 = select i1 %60, i32 97, i32 102
%63 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %52, i64 %53, i32 %57, i64 %58, i32 %62)
br label %64
64: ; preds = %51, %48
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%p: EOL\0A\00"
@.str.1 = [39 x i8] c"%p: header: [%ld:%c] footer: [%ld:%c]\0A\00"
define void @printblock(i8* %0) {
%2 = tail call i32 @checkheap(i32 0)
%3 = getelementptr inbounds i8, i8* %0, i64 -4
%4 = bitcast i8* %3 to i32*
%5 = load i32, i32* %4
%6 = and i32 %5, -8
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 -8
%10 = bitcast i8* %9 to i32*
%11 = load i32, i32* %10
%12 = icmp eq i32 %6, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %25
15: ; preds = %1
%16 = and i32 %11, 1
%17 = and i32 %11, -8
%18 = zext i32 %17 to i64
%19 = and i32 %5, 1
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i32 102, i32 97
%22 = icmp eq i32 %16, 0
%23 = select i1 %22, i32 102, i32 97
%24 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %0, i64 %7, i32 %21, i64 %18, i32 %23)
br label %25
25: ; preds = %15, %13
ret void
}