#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);
  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    $0x40,%edi
call   1050 <mymalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x61,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x40(%rax)
mov    -0x18(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <myfree@plt>
mov    -0x18(%rbp),%rcx
lea    0xe85(%rip),%rsi
lea    0xe79(%rip),%rax
cmp    $0x0,%rcx
cmove  %rax,%rsi
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x40,%edi
call   1050 <mymalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x61,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
movb   $0x0,0x40(%rbx)
lea    0xe95(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1060 <myfree@plt>
test   %rbx,%rbx
lea    0xe9e(%rip),%rax
lea    0xe9c(%rip),%rsi
cmove  %rax,%rsi
lea    0xe75(%rip),%rdi
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 = call i32 @memset(i8* %9, i8 signext 97, i32 64)
%11 = load i8*, i8** %6
%12 = getelementptr inbounds i8, i8* %11, i64 64
store i8 0, i8* %12
%13 = load i8*, i8** %6
%14 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %6
%16 = call i32 @myfree(i8* %15)
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
%19 = zext i1 %18 to i64
%20 = select i1 %18, 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)
%21 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %20)
ret i32 0
}

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.2 = [5 x i8] c"NULL\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 = tail call i32 @memset(i8* %4, i8 signext 97, i32 64)
%6 = getelementptr inbounds i8, i8* %4, i64 64
store i8 0, i8* %6
%7 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %4)
%8 = tail call i32 @myfree(i8* %4)
%9 = icmp eq i64 %3, 0
%10 = select i1 %9, 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)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %10)
ret i32 0
}