#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
void testmalloc() {
  printf("*********************************************\n");
  printf("testing  malloc() and free() API \n");
  char *c = (char *)malloc(10);
  strcpy(c, "shashi");
  printf("%s \n", c);
  char *d = (char *)malloc(10);
  strcpy(d, "rajnjan");
  printf("%s \n", d);
  free(d);
  char *e = (char *)malloc(5);
  strcpy(e, "rohan");
  printf("%s \n", e);
  printf("malloc API succesfull \n");
  printf("free API open succesfull \n");
  printf("\n\n");
}


x86 assembly (clang, -O0):
<testmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xed5(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rsi
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rsi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rsi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testmalloc>:
push   %r14
push   %rbx
push   %rax
lea    0xebf(%rip),%rdi
call   1050 <puts@plt>
lea    0xee1(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe80(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
lea    0xe78(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe5c(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x5,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe33(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6d(%rip),%rdi
call   1050 <puts@plt>
lea    0xe78(%rip),%rdi
call   1050 <puts@plt>
lea    0xdf5(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <puts@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"*********************************************\0A\00"
@.str.1 = [35 x i8] c"testing malloc() and free() API \0A\00"
@.str.2 = [7 x i8] c"shashi\00"
@.str.3 = [5 x i8] c"%s \0A\00"
@.str.4 = [8 x i8] c"rajnjan\00"
@.str.5 = [6 x i8] c"rohan\00"
@.str.6 = [24 x i8] c"malloc API succesfull \0A\00"
@.str.7 = [27 x i8] c"free API open succesfull \0A\00"
@.str.8 = [3 x i8] c"\0A\0A\00"
define void @testmalloc() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%6 = call i64 @malloc(i32 10)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %1
%8 = load i8*, i8** %1
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%10 = load i8*, i8** %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%12 = call i64 @malloc(i32 10)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %2
%14 = load i8*, i8** %2
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%16 = load i8*, i8** %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %2
%19 = call i32 @free(i8* %18)
%20 = call i64 @malloc(i32 5)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %3
%22 = load i8*, i8** %3
%23 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%24 = load i8*, i8** %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.2 = [7 x i8] c"shashi\00"
@.str.3 = [5 x i8] c"%s \0A\00"
@.str.4 = [8 x i8] c"rajnjan\00"
@.str.5 = [6 x i8] c"rohan\00"
@str = [46 x i8] c"*********************************************\00"
@str.9 = [34 x i8] c"testing malloc() and free() API \00"
@str.10 = [23 x i8] c"malloc API succesfull \00"
@str.11 = [26 x i8] c"free API open succesfull \00"
@str.12 = [2 x i8] c"\0A\00"
define void @testmalloc() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.9, i64 0, i64 0))
%3 = tail call i64 @malloc(i32 10)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%7 = tail call i64 @malloc(i32 10)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%11 = tail call i32 @free(i8* %8)
%12 = tail call i64 @malloc(i32 5)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.10, i64 0, i64 0))
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.11, i64 0, i64 0))
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.12, i64 0, i64 0))
ret void
}