#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 */
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
char *makeStringInHeap() {
  char *myString = malloc(20);
  myString[0] = 'a';
  myString[1] = 'b';
  myString[2] = 'c';
  myString[3] = 'd';
  myString[4] = 'e';
  myString[5] = 0;
  printf("%p\n", myString);
  printf("%s\n", myString);
  return myString;
}


x86 assembly (clang, -O0):
<makeStringInHeap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x61,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x62,0x1(%rax)
mov    -0x8(%rbp),%rax
movb   $0x63,0x2(%rax)
mov    -0x8(%rbp),%rax
movb   $0x64,0x3(%rax)
mov    -0x8(%rbp),%rax
movb   $0x65,0x4(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x5(%rax)
mov    -0x8(%rbp),%rsi
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeStringInHeap>:
push   %rbx
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movl   $0x64636261,(%rax)
movw   $0x65,0x4(%rax)
lea    0xebf(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
lea    0xeb4(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%p\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i8* @makeStringInHeap() {
%1 = alloca i8*
%2 = call i8* @malloc(i32 20)
store i8* %2, i8** %1
%3 = load i8*, i8** %1
%4 = getelementptr inbounds i8, i8* %3, i64 0
store i8 97, i8* %4
%5 = load i8*, i8** %1
%6 = getelementptr inbounds i8, i8* %5, i64 1
store i8 98, i8* %6
%7 = load i8*, i8** %1
%8 = getelementptr inbounds i8, i8* %7, i64 2
store i8 99, i8* %8
%9 = load i8*, i8** %1
%10 = getelementptr inbounds i8, i8* %9, i64 3
store i8 100, i8* %10
%11 = load i8*, i8** %1
%12 = getelementptr inbounds i8, i8* %11, i64 4
store i8 101, i8* %12
%13 = load i8*, i8** %1
%14 = getelementptr inbounds i8, i8* %13, i64 5
store i8 0, i8* %14
%15 = load i8*, i8** %1
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %1
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %1
ret i8* %19
}

LLVM IR (-O2):
@.str = [4 x i8] c"%p\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i8* @makeStringInHeap() {
%1 = tail call dereferenceable_or_null(20) i8* @malloc(i32 20)
store i8 97, i8* %1
%2 = getelementptr inbounds i8, i8* %1, i64 1
store i8 98, i8* %2
%3 = getelementptr inbounds i8, i8* %1, i64 2
store i8 99, i8* %3
%4 = getelementptr inbounds i8, i8* %1, i64 3
store i8 100, i8* %4
%5 = getelementptr inbounds i8, i8* %1, i64 4
store i8 101, i8* %5
%6 = getelementptr inbounds i8, i8* %1, i64 5
store i8 0, i8* %6
%7 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %1)
ret i8* %1
}