#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 get_preuse_bit(int const);
int get_size(int const);
int get_use_bit(int const);
int /*<<< orphan*/ printf(char *, int const, int const, ...);
void print_free_blocks(const int *mem) {
  int i, k;
  int current_size = 0;
  printf("Block #0 (indices 0-3): Sentinel Block | F_LINK = %d | B_LINK = %d\n",
         mem[1], mem[2]);
  i = 1;
  k = 4;
  current_size = get_size(mem[k]);
  while (current_size != 0) {
    if (!get_use_bit(mem[k])) {
      printf("Block #%d (indices %d-%d): ", i, k, k + current_size - 1);
      printf("Block Size  %d >> Use Bit %d >> Preuse Bit %d ", current_size,
             get_use_bit(mem[k]), get_preuse_bit(mem[k]));
      printf(">> F Link %d >> B Link %d\n", mem[k + 1], mem[k + 2]);
    }
    i++;
    k += current_size;
    current_size = get_size(mem[k]);
  }
  return;
}


x86 assembly (clang, -O0):
<print_free_blocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edx
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0xc(%rbp)
movl   $0x4,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <get_size@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1267 <print_free_blocks+0x127>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1060 <get_use_bit@plt>
cmp    $0x0,%eax
jne    123d <print_free_blocks+0xfd>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
sub    $0x1,%ecx
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1060 <get_use_bit@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1050 <get_preuse_bit@plt>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    %eax,%ecx
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <get_size@plt>
mov    %eax,-0x14(%rbp)
jmp    1190 <print_free_blocks+0x50>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_free_blocks>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
mov    0x4(%rdi),%esi
mov    0x8(%rdi),%edx
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r13),%edi
call   1030 <get_size@plt>
test   %eax,%eax
je     121c <print_free_blocks+0xdc>
mov    %eax,%ebx
mov    $0x1,%ebp
mov    $0x4,%r12d
jmp    11a6 <print_free_blocks+0x66>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebp
movslq %r12d,%rax
mov    0x0(%r13,%rax,4),%edi
call   1030 <get_size@plt>
mov    %eax,%ebx
test   %eax,%eax
je     121c <print_free_blocks+0xdc>
movslq %r12d,%r14
mov    0x0(%r13,%r14,4),%edi
call   1060 <get_use_bit@plt>
lea    (%r14,%rbx,1),%r12d
test   %eax,%eax
jne    1190 <print_free_blocks+0x50>
lea    -0x1(%r12),%ecx
lea    0xe7d(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13,%r14,4),%edi
call   1060 <get_use_bit@plt>
mov    %eax,%r15d
mov    0x0(%r13,%r14,4),%edi
call   1050 <get_preuse_bit@plt>
lea    0xe6f(%rip),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%r13,%r14,4),%esi
mov    0x8(%r13,%r14,4),%edx
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1190 <print_free_blocks+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [68 x i8] c"Block (indices 0-3): Sentinel Block | F_LINK = %d | B_LINK = %d\0A\00"
@.str.1 = [28 x i8] c"Block #%d (indices %d-%d): \00"
@.str.2 = [47 x i8] c"Block Size %d >> Use Bit %d >> Preuse Bit %d \00"
@.str.3 = [27 x i8] c">> F Link %d >> B Link %d\0A\00"
define void @print_free_blocks(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %5
%6 = load i32*, i32** %2
%7 = getelementptr inbounds i32, i32* %6, i64 1
%8 = load i32, i32* %7
%9 = load i32*, i32** %2
%10 = getelementptr inbounds i32, i32* %9, i64 2
%11 = load i32, i32* %10
%12 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11)
store i32 1, i32* %3
store i32 4, i32* %4
%13 = load i32*, i32** %2
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = load i32, i32* %16
%18 = call i32 @get_size(i32 %17)
store i32 %18, i32* %5
br label %19
19: ; preds = %65, %1
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %77
22: ; preds = %19
%23 = load i32*, i32** %2
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = call i32 @get_use_bit(i32 %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %65, label %30
30: ; preds = %22
%31 = load i32, i32* %3
%32 = load i32, i32* %4
%33 = load i32, i32* %4
%34 = load i32, i32* %5
%35 = add nsw i32 %33, %34
%36 = sub nsw i32 %35, 1
%37 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %32, i32 %36)
%38 = load i32, i32* %5
%39 = load i32*, i32** %2
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = call i32 @get_use_bit(i32 %43)
%45 = load i32*, i32** %2
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
%49 = load i32, i32* %48
%50 = call i32 @get_preuse_bit(i32 %49)
%51 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %38, i32 %44, i32 %50)
%52 = load i32*, i32** %2
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %52, i64 %55
%57 = load i32, i32* %56
%58 = load i32*, i32** %2
%59 = load i32, i32* %4
%60 = add nsw i32 %59, 2
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %58, i64 %61
%63 = load i32, i32* %62
%64 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %57, i32 %63)
br label %65
65: ; preds = %30, %22
%66 = load i32, i32* %3
%67 = add nsw i32 %66, 1
store i32 %67, i32* %3
%68 = load i32, i32* %5
%69 = load i32, i32* %4
%70 = add nsw i32 %69, %68
store i32 %70, i32* %4
%71 = load i32*, i32** %2
%72 = load i32, i32* %4
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32, i32* %71, i64 %73
%75 = load i32, i32* %74
%76 = call i32 @get_size(i32 %75)
store i32 %76, i32* %5
br label %19
77: ; preds = %19
ret void
}

LLVM IR (-O2):
@.str = [68 x i8] c"Block (indices 0-3): Sentinel Block | F_LINK = %d | B_LINK = %d\0A\00"
@.str.1 = [28 x i8] c"Block #%d (indices %d-%d): \00"
@.str.2 = [47 x i8] c"Block Size %d >> Use Bit %d >> Preuse Bit %d \00"
@.str.3 = [27 x i8] c">> F Link %d >> B Link %d\0A\00"
define void @print_free_blocks(i32* nocapture %0) {
%2 = getelementptr inbounds i32, i32* %0, i64 1
%3 = load i32, i32* %2
%4 = getelementptr inbounds i32, i32* %0, i64 2
%5 = load i32, i32* %4
%6 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %5)
%7 = getelementptr inbounds i32, i32* %0, i64 4
%8 = load i32, i32* %7
%9 = tail call i32 @get_size(i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %45, label %11
11: ; preds = %1, %38
%12 = phi i32 [ %43, %38 ], [ %9, %1 ]
%13 = phi i32 [ %20, %38 ], [ 4, %1 ]
%14 = phi i32 [ %39, %38 ], [ 1, %1 ]
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
%18 = tail call i32 @get_use_bit(i32 %17)
%19 = icmp eq i32 %18, 0
%20 = add nsw i32 %12, %13
br i1 %19, label %21, label %38
21: ; preds = %11
%22 = add nsw i32 %20, -1
%23 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %13, i32 %22)
%24 = load i32, i32* %16
%25 = tail call i32 @get_use_bit(i32 %24)
%26 = load i32, i32* %16
%27 = tail call i32 @get_preuse_bit(i32 %26)
%28 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %25, i32 %27)
%29 = add nsw i32 %13, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %0, i64 %30
%32 = load i32, i32* %31
%33 = add nsw i32 %13, 2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %0, i64 %34
%36 = load i32, i32* %35
%37 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %36)
br label %38
38: ; preds = %11, %21
%39 = add nuw nsw i32 %14, 1
%40 = sext i32 %20 to i64
%41 = getelementptr inbounds i32, i32* %0, i64 %40
%42 = load i32, i32* %41
%43 = tail call i32 @get_size(i32 %42)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %11
45: ; preds = %38, %1
ret void
}