#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 *, ...);
void print_memory(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) {
    printf("Block #%d (indices %d-%d): ", i, k, k + current_size - 1);
    printf("SIZE = %d | USE = %d | PREUSE = %d ", current_size,
           get_use_bit(mem[k]), get_preuse_bit(mem[k]));
    if (!get_use_bit(mem[k])) {
      printf("| F_LINK = %d | B_LINK = %d\n", mem[k + 1], mem[k + 2]);
    } else {
      printf("| F_LINK = * | B_LINK = *\n");
    }
    i++;
    k += current_size;
    current_size = get_size(mem[k]);
  }
  return;
}


x86 assembly (clang, -O0):
<print_memory>:
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     127a <print_memory+0x13a>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
sub    $0x1,%ecx
lea    0xe94(%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    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1060 <get_use_bit@plt>
cmp    $0x0,%eax
jne    1242 <print_memory+0x102>
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    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1250 <print_memory+0x110>
lea    0xe3b(%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_memory+0x50>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_memory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x4(%rdi),%esi
mov    0x8(%rdi),%edx
lea    0xe95(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r14),%edi
call   1030 <get_size@plt>
test   %eax,%eax
je     123b <print_memory+0xeb>
mov    %eax,%r12d
mov    $0x1,%ebp
mov    $0x4,%r15d
jmp    11c2 <print_memory+0x72>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xedd(%rip),%rdi
call   1040 <puts@plt>
add    $0x1,%ebp
movslq %r15d,%rax
mov    (%r14,%rax,4),%edi
call   1030 <get_size@plt>
mov    %eax,%r12d
test   %eax,%eax
je     123b <print_memory+0xeb>
mov    %r15d,%r13d
lea    (%r12,%r13,1),%r15d
lea    (%r12,%r13,1),%ecx
add    $0xffffffff,%ecx
lea    0xe6d(%rip),%rdi
mov    %ebp,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
movslq %r13d,%rbx
mov    (%r14,%rbx,4),%edi
call   1070 <get_use_bit@plt>
mov    %eax,%r13d
mov    (%r14,%rbx,4),%edi
call   1060 <get_preuse_bit@plt>
lea    0xe5e(%rip),%rdi
mov    %r12d,%esi
mov    %r13d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14,%rbx,4),%edi
call   1070 <get_use_bit@plt>
test   %eax,%eax
jne    11a0 <print_memory+0x50>
mov    0x4(%r14,%rbx,4),%esi
mov    0x8(%r14,%rbx,4),%edx
lea    0xdf8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11ac <print_memory+0x5c>
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 = [36 x i8] c"SIZE = %d | USE = %d | PREUSE = %d \00"
@.str.3 = [29 x i8] c"| F_LINK = %d | B_LINK = %d\0A\00"
@.str.4 = [27 x i8] c"| F_LINK = * | B_LINK = *\0A\00"
define void @print_memory(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*, ...) @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 = %67, %1
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %79
22: ; preds = %19
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = add nsw i32 %25, %26
%28 = sub nsw i32 %27, 1
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %24, i32 %28)
%30 = load i32, i32* %5
%31 = load i32*, i32** %2
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = call i32 @get_use_bit(i32 %35)
%37 = load i32*, i32** %2
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = call i32 @get_preuse_bit(i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %36, i32 %42)
%44 = load i32*, i32** %2
%45 = load i32, i32* %4
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32, i32* %47
%49 = call i32 @get_use_bit(i32 %48)
%50 = icmp ne i32 %49, 0
br i1 %50, label %65, label %51
51: ; preds = %22
%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*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %57, i32 %63)
br label %67
65: ; preds = %22
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %67
67: ; preds = %65, %51
%68 = load i32, i32* %3
%69 = add nsw i32 %68, 1
store i32 %69, i32* %3
%70 = load i32, i32* %5
%71 = load i32, i32* %4
%72 = add nsw i32 %71, %70
store i32 %72, i32* %4
%73 = load i32*, i32** %2
%74 = load i32, i32* %4
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i32, i32* %73, i64 %75
%77 = load i32, i32* %76
%78 = call i32 @get_size(i32 %77)
store i32 %78, i32* %5
br label %19
79: ; 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 = [36 x i8] c"SIZE = %d | USE = %d | PREUSE = %d \00"
@.str.3 = [29 x i8] c"| F_LINK = %d | B_LINK = %d\0A\00"
@str = [26 x i8] c"| F_LINK = * | B_LINK = *\00"
define void @print_memory(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*, ...) @printf(i8* dereferenceable(1) 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 %47, label %11
11: ; preds = %1, %40
%12 = phi i32 [ %45, %40 ], [ %9, %1 ]
%13 = phi i32 [ %15, %40 ], [ 4, %1 ]
%14 = phi i32 [ %41, %40 ], [ 1, %1 ]
%15 = add nsw i32 %12, %13
%16 = add nsw i32 %15, -1
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %13, i32 %16)
%18 = sext i32 %13 to i64
%19 = getelementptr inbounds i32, i32* %0, i64 %18
%20 = load i32, i32* %19
%21 = tail call i32 @get_use_bit(i32 %20)
%22 = load i32, i32* %19
%23 = tail call i32 @get_preuse_bit(i32 %22)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %21, i32 %23)
%25 = load i32, i32* %19
%26 = tail call i32 @get_use_bit(i32 %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %11
%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*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %36)
br label %40
38: ; preds = %11
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %40
40: ; preds = %38, %28
%41 = add nuw nsw i32 %14, 1
%42 = sext i32 %15 to i64
%43 = getelementptr inbounds i32, i32* %0, i64 %42
%44 = load i32, i32* %43
%45 = tail call i32 @get_size(i32 %44)
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %11
47: ; preds = %40, %1
ret void
}