#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*/ my_free(char *, char *, int);
scalar_t__ my_malloc(int, char *, int);
int /*<<< orphan*/ printf(char *);
void redundant_freeing_of_the_same_pointer() {
  printf("\n--------------------------------");
  printf("\nBegin **redundant freeing** test. \n\n");
  printf("You should expect to see an allocation, a free,");
  printf("and then a denied free.\n\n");
  char *p = (char *)my_malloc(
      200,
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/PLJNS/Rutgers-Systems-Programming-Fall-2013/"
      "refs/heads/master/Malloc/testcases.c",
      44);
  my_free(
      p,
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/PLJNS/Rutgers-Systems-Programming-Fall-2013/"
      "refs/heads/master/Malloc/testcases.c",
      45);
  my_free(
      p,
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/PLJNS/Rutgers-Systems-Programming-Fall-2013/"
      "refs/heads/master/Malloc/testcases.c",
      46);
  printf("\nEnd **redundant freeing** test.");
  printf("\n------------------------------\n\n");
}


x86 assembly (clang, -O0):
<redundant_freeing_of_the_same_pointer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1040 <printf@plt>
lea    0xed7(%rip),%rdi
call   1040 <printf@plt>
lea    0xef1(%rip),%rdi
call   1040 <printf@plt>
lea    0xf15(%rip),%rdi
call   1040 <printf@plt>
mov    $0xc8,%edi
lea    0xf1e(%rip),%rsi
mov    $0x2c,%edx
call   1030 <my_malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xf05(%rip),%rsi
mov    $0x2d,%edx
call   1050 <my_free@plt>
mov    -0x8(%rbp),%rdi
lea    0xef0(%rip),%rsi
mov    $0x2e,%edx
call   1050 <my_free@plt>
lea    0xf8a(%rip),%rdi
call   1040 <printf@plt>
lea    0xf9f(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<redundant_freeing_of_the_same_pointer>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
call   1050 <printf@plt>
lea    0xfc7(%rip),%rdi
call   1040 <puts@plt>
lea    0xebf(%rip),%rdi
call   1050 <printf@plt>
lea    0xfd4(%rip),%rdi
call   1040 <puts@plt>
lea    0xed7(%rip),%r14
mov    $0xc8,%edi
mov    %r14,%rsi
mov    $0x2c,%edx
call   1030 <my_malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    $0x2d,%edx
call   1060 <my_free@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2e,%edx
call   1060 <my_free@plt>
lea    0xf46(%rip),%rdi
call   1050 <printf@plt>
lea    0xf99(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"\0A--------------------------------\00"
@.str.1 = [38 x i8] c"\0ABegin **redundant freeing** test. \0A\0A\00"
@.str.2 = [48 x i8] c"You should expect to see an allocation, a free,\00"
@.str.3 = [26 x i8] c"and then a denied free.\0A\0A\00"
@.str.4 = [171 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/PLJNS/Rutgers-Systems-Programming-Fall-2013/refs/heads/master/Malloc/testcases.c\00"
@.str.5 = [33 x i8] c"\0AEnd **redundant freeing** test.\00"
@.str.6 = [34 x i8] c"\0A------------------------------\0A\0A\00"
define void @redundant_freeing_of_the_same_pointer() {
%1 = alloca i8*
%2 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%3 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%6 = call i64 @my_malloc(i32 200, i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.4, i64 0, i64 0), i32 44)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %1
%8 = load i8*, i8** %1
%9 = call i32 @my_free(i8* %8, i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.4, i64 0, i64 0), i32 45)
%10 = load i8*, i8** %1
%11 = call i32 @my_free(i8* %10, i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.4, i64 0, i64 0), i32 46)
%12 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"\0A--------------------------------\00"
@.str.2 = [48 x i8] c"You should expect to see an allocation, a free,\00"
@.str.4 = [171 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/PLJNS/Rutgers-Systems-Programming-Fall-2013/refs/heads/master/Malloc/testcases.c\00"
@.str.5 = [33 x i8] c"\0AEnd **redundant freeing** test.\00"
@str = [37 x i8] c"\0ABegin **redundant freeing** test. \0A\00"
@str.7 = [25 x i8] c"and then a denied free.\0A\00"
@str.8 = [33 x i8] c"\0A------------------------------\0A\00"
define void @redundant_freeing_of_the_same_pointer() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
%5 = tail call i64 @my_malloc(i32 200, i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.4, i64 0, i64 0), i32 44)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @my_free(i8* %6, i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.4, i64 0, i64 0), i32 45)
%8 = tail call i32 @my_free(i8* %6, i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.4, i64 0, i64 0), i32 46)
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.8, i64 0, i64 0))
ret void
}