#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 /*<<< orphan*/ basic_test(int);
int /*<<< orphan*/ cleanup_test();
size_t get_free_memory();
int /*<<< orphan*/ init_test();
int /*<<< orphan*/ log_write_start(int);
void memory_is_freed(void) {
  size_t mem_used_before, mem_used_after;
  size_t i;
  init_test();
  mem_used_before = get_free_memory();
  for (i = 0; i < 5; i++)
    log_write_start(1048576);
  mem_used_after = get_free_memory();
  basic_test(mem_used_after < mem_used_before + 3072 &&
             mem_used_before < mem_used_after + 3072);
  cleanup_test();
}


x86 assembly (clang, -O0):
<memory_is_freed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1070 <init_test@plt>
mov    $0x0,%al
call   1030 <get_free_memory@plt>
mov    %rax,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x5,-0x18(%rbp)
jae    1198 <memory_is_freed+0x48>
mov    $0x100000,%edi
call   1060 <log_write_start@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1172 <memory_is_freed+0x22>
mov    $0x0,%al
call   1030 <get_free_memory@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rdx
add    $0xc00,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x19(%rbp)
jae    11d8 <memory_is_freed+0x88>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0xc00,%rcx
cmp    %rcx,%rax
setb   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <basic_test@plt>
mov    $0x0,%al
call   1050 <cleanup_test@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memory_is_freed>:
push   %rbx
xor    %eax,%eax
call   1070 <init_test@plt>
xor    %eax,%eax
call   1030 <get_free_memory@plt>
mov    %rax,%rbx
mov    $0x100000,%edi
call   1060 <log_write_start@plt>
mov    $0x100000,%edi
call   1060 <log_write_start@plt>
mov    $0x100000,%edi
call   1060 <log_write_start@plt>
mov    $0x100000,%edi
call   1060 <log_write_start@plt>
mov    $0x100000,%edi
call   1060 <log_write_start@plt>
xor    %eax,%eax
call   1030 <get_free_memory@plt>
lea    0xc00(%rbx),%rcx
cmp    %rcx,%rax
setb   %cl
add    $0xc00,%rax
cmp    %rax,%rbx
setb   %al
and    %cl,%al
movzbl %al,%edi
call   1040 <basic_test@plt>
xor    %eax,%eax
pop    %rbx
jmp    1050 <cleanup_test@plt>

LLVM IR (-O0):
define void @memory_is_freed() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = call i32 (...) @init_test()
%5 = call i64 (...) @get_free_memory()
store i64 %5, i64* %1
store i64 0, i64* %3
br label %6
6: ; preds = %11, %0
%7 = load i64, i64* %3
%8 = icmp ult i64 %7, 5
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = call i32 @log_write_start(i32 1048576)
br label %11
11: ; preds = %9
%12 = load i64, i64* %3
%13 = add i64 %12, 1
store i64 %13, i64* %3
br label %6
14: ; preds = %6
%15 = call i64 (...) @get_free_memory()
store i64 %15, i64* %2
%16 = load i64, i64* %2
%17 = load i64, i64* %1
%18 = add i64 %17, 3072
%19 = icmp ult i64 %16, %18
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i64, i64* %1
%22 = load i64, i64* %2
%23 = add i64 %22, 3072
%24 = icmp ult i64 %21, %23
br label %25
25: ; preds = %20, %14
%26 = phi i1 [ false, %14 ], [ %24, %20 ]
%27 = zext i1 %26 to i32
%28 = call i32 @basic_test(i32 %27)
%29 = call i32 (...) @cleanup_test()
ret void
}

LLVM IR (-O2):
define void @memory_is_freed() {
%1 = tail call i32 (...) @init_test()
%2 = tail call i64 (...) @get_free_memory()
%3 = tail call i32 @log_write_start(i32 1048576)
%4 = tail call i32 @log_write_start(i32 1048576)
%5 = tail call i32 @log_write_start(i32 1048576)
%6 = tail call i32 @log_write_start(i32 1048576)
%7 = tail call i32 @log_write_start(i32 1048576)
%8 = tail call i64 (...) @get_free_memory()
%9 = add i64 %2, 3072
%10 = icmp ult i64 %8, %9
%11 = add i64 %8, 3072
%12 = icmp ult i64 %2, %11
%13 = and i1 %10, %12
%14 = zext i1 %13 to i32
%15 = tail call i32 @basic_test(i32 %14)
%16 = tail call i32 (...) @cleanup_test()
ret void
}