#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*/ customFree(int *, char *, int);
scalar_t__ customMalloc(int, char *, int);
int /*<<< orphan*/ printf(char *, ...);
void valid_free() {
  int *z = (int *)customMalloc(
      200,
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/felixinfinite/Rutgers_CS_214_Fall_2015/refs/"
      "heads/master/EnhancedMalloc/src/main.c",
      25);
  ;
  customFree(z,
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/felixinfinite/Rutgers_CS_214_Fall_2015/"
             "refs/heads/master/EnhancedMalloc/src/main.c",
             26);
  ;
  int *x = z;
  z = (int *)customMalloc(
      200,
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/felixinfinite/Rutgers_CS_214_Fall_2015/refs/"
      "heads/master/EnhancedMalloc/src/main.c",
      28);
  ;
  customFree(z,
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/felixinfinite/Rutgers_CS_214_Fall_2015/"
             "refs/heads/master/EnhancedMalloc/src/main.c",
             29);
  ;
  if (x == z) {
    printf("x = z = %p. New malloced address is the same as the old one.\n", x);
  }
  printf("Perfectly Valid Free().\n");
}


x86 assembly (clang, -O0):
<valid_free>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0xc8,%edi
lea    0xebc(%rip),%rsi
mov    $0x19,%edx
call   1040 <customMalloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea3(%rip),%rsi
mov    $0x1a,%edx
call   1050 <customFree@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0xc8,%edi
lea    0xe85(%rip),%rsi
mov    $0x1c,%edx
call   1040 <customMalloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6c(%rip),%rsi
mov    $0x1d,%edx
call   1050 <customFree@plt>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    11be <valid_free+0x8e>
mov    -0x10(%rbp),%rsi
lea    0xef6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<valid_free>:
push   %r15
push   %r14
push   %rbx
lea    0xeb4(%rip),%r14
mov    $0xc8,%edi
mov    %r14,%rsi
mov    $0x19,%edx
call   1050 <customMalloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    $0x1a,%edx
call   1060 <customFree@plt>
mov    $0xc8,%edi
mov    %r14,%rsi
mov    $0x1c,%edx
call   1050 <customMalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    $0x1d,%edx
call   1060 <customFree@plt>
cmp    %rbx,%r15
jne    11ac <valid_free+0x6c>
lea    0xf0b(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf38(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/felixinfinite/Rutgers_CS_214_Fall_2015/refs/heads/master/EnhancedMalloc/src/main.c\00"
@.str.1 = [62 x i8] c"x = z = %p. New malloced address is the same as the old one.\0A\00"
@.str.2 = [25 x i8] c"Perfectly Valid Free().\0A\00"
define void @valid_free() {
%1 = alloca i32*
%2 = alloca i32*
%3 = call i64 @customMalloc(i32 200, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0), i32 25)
%4 = inttoptr i64 %3 to i32*
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = call i32 @customFree(i32* %5, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0), i32 26)
%7 = load i32*, i32** %1
store i32* %7, i32** %2
%8 = call i64 @customMalloc(i32 200, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0), i32 28)
%9 = inttoptr i64 %8 to i32*
store i32* %9, i32** %1
%10 = load i32*, i32** %1
%11 = call i32 @customFree(i32* %10, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0), i32 29)
%12 = load i32*, i32** %2
%13 = load i32*, i32** %1
%14 = icmp eq i32* %12, %13
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = load i32*, i32** %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i32* %16)
br label %18
18: ; preds = %15, %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/felixinfinite/Rutgers_CS_214_Fall_2015/refs/heads/master/EnhancedMalloc/src/main.c\00"
@.str.1 = [62 x i8] c"x = z = %p. New malloced address is the same as the old one.\0A\00"
@str = [24 x i8] c"Perfectly Valid Free().\00"
define void @valid_free() {
%1 = tail call i64 @customMalloc(i32 200, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0), i32 25)
%2 = inttoptr i64 %1 to i32*
%3 = tail call i32 @customFree(i32* %2, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0), i32 26)
%4 = tail call i64 @customMalloc(i32 200, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0), i32 28)
%5 = inttoptr i64 %4 to i32*
%6 = tail call i32 @customFree(i32* %5, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0), i32 29)
%7 = icmp eq i32* %2, %5
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %10
10: ; preds = %8, %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
ret void
}