#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*/ memset(char *, char, int);
int /*<<< orphan*/ myfree(char *);
scalar_t__ mymalloc(int);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  char *p = (char *)mymalloc((-64));
  if (p == NULL) {
    return 0;
  }
  memset(p, 'a', (-64));
  *(p + (-64)) = '\0';
  printf("p is:\n'%s'\n", p);
  myfree(p);
  printf("after free: p is '%s'\n", (p == NULL) ? "NULL" : "Not empty");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xffffffc0,%edi
call   1050 <mymalloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117b <main+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    11dc <main+0x9c>
mov    -0x18(%rbp),%rdi
mov    $0x61,%esi
mov    $0xffffffc0,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,-0x40(%rax)
mov    -0x18(%rbp),%rsi
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <myfree@plt>
mov    -0x18(%rbp),%rcx
lea    0xe6e(%rip),%rsi
lea    0xe62(%rip),%rax
cmp    $0x0,%rcx
cmove  %rax,%rsi
lea    0xe3c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0xffffffc0,%edi
call   1050 <mymalloc@plt>
test   %rax,%rax
je     1193 <main+0x53>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x61,%esi
mov    $0xffffffc0,%edx
call   1040 <memset@plt>
movb   $0x0,-0x40(%rbx)
lea    0xe90(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1060 <myfree@plt>
lea    0xe85(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"p is:\0A'%s'\0A\00"
@.str.1 = [23 x i8] c"after free: p is '%s'\0A\00"
@.str.2 = [5 x i8] c"NULL\00"
@.str.3 = [10 x i8] c"Not empty\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i64 @mymalloc(i32 -64)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %26
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = call i32 @memset(i8* %13, i8 signext 97, i32 -64)
%15 = load i8*, i8** %6
%16 = getelementptr inbounds i8, i8* %15, i64 -64
store i8 0, i8* %16
%17 = load i8*, i8** %6
%18 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %6
%20 = call i32 @myfree(i8* %19)
%21 = load i8*, i8** %6
%22 = icmp eq i8* %21, null
%23 = zext i1 %22 to i64
%24 = select i1 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0)
%25 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %24)
store i32 0, i32* %3
br label %26
26: ; preds = %12, %11
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [12 x i8] c"p is:\0A'%s'\0A\00"
@.str.1 = [23 x i8] c"after free: p is '%s'\0A\00"
@.str.3 = [10 x i8] c"Not empty\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @mymalloc(i32 -64)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = tail call i32 @memset(i8* %4, i8 signext 97, i32 -64)
%8 = getelementptr inbounds i8, i8* %4, i64 -64
store i8 0, i8* %8
%9 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %4)
%10 = tail call i32 @myfree(i8* %4)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %2, %6
ret i32 0
}