#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*/ clear_memory(int *, char *);
int /*<<< orphan*/ give_me(char *, int *, int);
int how_many_free(int *);
int is_there_free(int *);
int /*<<< orphan*/ memory_dump(int *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int helper[1024];
  char memory[1024];
  clear_memory(helper, memory);
  memory_dump(helper);
  printf("Free = %d\n", how_many_free(helper));
  printf("Is there free = %d\n", is_there_free(helper));
  give_me(memory, helper, 1);
  give_me(memory, helper, 1);
  give_me(memory, helper, 1);
  give_me(memory, helper, 1);
  printf("Free = %d\n", how_many_free(helper));
  memory_dump(helper);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1410,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x1010(%rbp),%rdi
lea    -0x1410(%rbp),%rsi
call   1060 <clear_memory@plt>
lea    -0x1010(%rbp),%rdi
call   1070 <memory_dump@plt>
lea    -0x1010(%rbp),%rdi
call   1040 <how_many_free@plt>
mov    %eax,%esi
lea    0xe5a(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1010(%rbp),%rdi
call   1030 <is_there_free@plt>
mov    %eax,%esi
lea    0xe4b(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1410(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
mov    $0x1,%edx
call   1080 <give_me@plt>
lea    -0x1410(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
mov    $0x1,%edx
call   1080 <give_me@plt>
lea    -0x1410(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
mov    $0x1,%edx
call   1080 <give_me@plt>
lea    -0x1410(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
mov    $0x1,%edx
call   1080 <give_me@plt>
lea    -0x1010(%rbp),%rdi
call   1040 <how_many_free@plt>
mov    %eax,%esi
lea    0xdc6(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1010(%rbp),%rdi
call   1070 <memory_dump@plt>
xor    %eax,%eax
add    $0x1410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1400,%rsp
lea    0x400(%rsp),%rbx
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <clear_memory@plt>
mov    %rbx,%rdi
call   1070 <memory_dump@plt>
mov    %rbx,%rdi
call   1040 <how_many_free@plt>
lea    0xe67(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <is_there_free@plt>
lea    0xe59(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1080 <give_me@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1080 <give_me@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1080 <give_me@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1080 <give_me@plt>
mov    %rbx,%rdi
call   1040 <how_many_free@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <memory_dump@plt>
xor    %eax,%eax
add    $0x1400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Free = %d\0A\00"
@.str.1 = [20 x i8] c"Is there free = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i32]
%3 = alloca [1024 x i8]
store i32 0, i32* %1
%4 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i32 @clear_memory(i32* %4, i8* %5)
%7 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 0
%8 = call i32 @memory_dump(i32* %7)
%9 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 0
%10 = call i32 @how_many_free(i32* %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 0
%13 = call i32 @is_there_free(i32* %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%16 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 0
%17 = call i32 @give_me(i8* %15, i32* %16, i32 1)
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%19 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 0
%20 = call i32 @give_me(i8* %18, i32* %19, i32 1)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%22 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 0
%23 = call i32 @give_me(i8* %21, i32* %22, i32 1)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%25 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 0
%26 = call i32 @give_me(i8* %24, i32* %25, i32 1)
%27 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 0
%28 = call i32 @how_many_free(i32* %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 0, i64 0
%31 = call i32 @memory_dump(i32* %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"Free = %d\0A\00"
@.str.1 = [20 x i8] c"Is there free = %d\0A\00"
define i32 @main() {
%1 = alloca [1024 x i32]
%2 = alloca [1024 x i8]
%3 = bitcast [1024 x i32]* %1 to i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i32], [1024 x i32]* %1, i64 0, i64 0
%6 = call i32 @clear_memory(i32* %5, i8* %4)
%7 = call i32 @memory_dump(i32* %5)
%8 = call i32 @how_many_free(i32* %5)
%9 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @is_there_free(i32* %5)
%11 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32 @give_me(i8* %4, i32* %5, i32 1)
%13 = call i32 @give_me(i8* %4, i32* %5, i32 1)
%14 = call i32 @give_me(i8* %4, i32* %5, i32 1)
%15 = call i32 @give_me(i8* %4, i32* %5, i32 1)
%16 = call i32 @how_many_free(i32* %5)
%17 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = call i32 @memory_dump(i32* %5)
ret i32 0
}