#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 */
void *get_previous_free_block(void *);
void *last_free_block();
size_t read_size(void *);
int /*<<< orphan*/ sbrk(int);
int /*<<< orphan*/ set_next_free_block(void *, int /*<<< orphan*/ *);
void check_footprint() {
  void *last = last_free_block(), *prev = get_previous_free_block(last);
  size_t last_size = read_size(last);
  if (last_size >= (128 * 1024)) {
    if (prev)
      set_next_free_block(prev, NULL);
    sbrk(-1 * (last_size + (sizeof(size_t))));
  }
}


x86 assembly (clang, -O0):
<check_footprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <last_free_block@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <get_previous_free_block@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <read_size@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x20000,-0x18(%rbp)
jb     11b6 <check_footprint+0x66>
cmpq   $0x0,-0x10(%rbp)
je     11a3 <check_footprint+0x53>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <set_next_free_block@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
imul   $0xffffffffffffffff,%rax,%rax
mov    %eax,%edi
call   1060 <sbrk@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_footprint>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <last_free_block@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <get_previous_free_block@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <read_size@plt>
cmp    $0x20000,%rax
jb     119e <check_footprint+0x4e>
mov    %rax,%rbx
test   %r14,%r14
je     118b <check_footprint+0x3b>
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <set_next_free_block@plt>
mov    $0xfffffff8,%edi
sub    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <sbrk@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @check_footprint() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i64
%4 = call i8* (...) @last_free_block()
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = call i8* @get_previous_free_block(i8* %5)
store i8* %6, i8** %2
%7 = load i8*, i8** %1
%8 = call i64 @read_size(i8* %7)
store i64 %8, i64* %3
%9 = load i64, i64* %3
%10 = icmp uge i64 %9, 131072
br i1 %10, label %11, label %23
11: ; preds = %0
%12 = load i8*, i8** %2
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i8*, i8** %2
%16 = call i32 @set_next_free_block(i8* %15, i32* null)
br label %17
17: ; preds = %14, %11
%18 = load i64, i64* %3
%19 = add i64 %18, 8
%20 = mul i64 -1, %19
%21 = trunc i64 %20 to i32
%22 = call i32 @sbrk(i32 %21)
br label %23
23: ; preds = %17, %0
ret void
}

LLVM IR (-O2):
define void @check_footprint() {
%1 = tail call i8* (...) @last_free_block()
%2 = tail call i8* @get_previous_free_block(i8* %1)
%3 = tail call i64 @read_size(i8* %1)
%4 = icmp ugt i64 %3, 131071
br i1 %4, label %5, label %13
5: ; preds = %0
%6 = icmp eq i8* %2, null
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = tail call i32 @set_next_free_block(i8* %2, i32* null)
br label %9
9: ; preds = %7, %5
%10 = trunc i64 %3 to i32
%11 = sub i32 -8, %10
%12 = tail call i32 @sbrk(i32 %11)
br label %13
13: ; preds = %9, %0
ret void
}