#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*/ bfree(char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ myfree(char *);
scalar_t__ mymalloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  char *p = (char *)mymalloc(32 * sizeof(char));
  memset(p, 'a', 32);
  *(p + 32) = '\0';
  printf("p is:\n'%s'\n", p);
  myfree(p);
  char str[32];
  strcpy(str, p);
  bfree(str, 32);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x20,%edi
call   1070 <mymalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x61,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x20(%rax)
mov    -0x18(%rbp),%rsi
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <myfree@plt>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rdi
mov    $0x20,%esi
call   1060 <bfree@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    $0x20,%edi
call   1070 <mymalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x61,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
movb   $0x0,0x20(%rbx)
lea    0xe6f(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1080 <myfree@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    $0x20,%esi
call   1060 <bfree@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"p is:\0A'%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [32 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 @mymalloc(i32 32)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = call i32 @memset(i8* %10, i8 signext 97, i32 32)
%12 = load i8*, i8** %6
%13 = getelementptr inbounds i8, i8* %12, i64 32
store i8 0, i8* %13
%14 = load i8*, i8** %6
%15 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %6
%17 = call i32 @myfree(i8* %16)
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%19 = load i8*, i8** %6
%20 = call i32 @strcpy(i8* %18, i8* %19)
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%22 = call i32 @bfree(i8* %21, i32 32)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"p is:\0A'%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32 x i8]
%4 = tail call i64 @mymalloc(i32 32)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @memset(i8* %5, i8 signext 97, i32 32)
%7 = getelementptr inbounds i8, i8* %5, i64 32
store i8 0, i8* %7
%8 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %5)
%9 = tail call i32 @myfree(i8* %5)
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%11 = call i32 @strcpy(i8* %10, i8* %5)
%12 = call i32 @bfree(i8* %10, i32 32)
ret i32 0
}