int main() {
  char *str;
  str = (char *)malloc(15);
  strcpy(str, "Linkerist");
  printf("String = %s,  Address = %u\n", str, str);
  str = (char *)realloc(str, 25);
  strcat(str, ".com");
  printf("String = %s,  Address = %u\n", str, str);
  free(str);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xf,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x19,%esi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0xf,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movabs $0x736972656b6e694c,%rax
72 69 73
mov    %rax,(%rbx)
movw   $0x74,0x8(%rbx)
lea    0xe8f(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x19,%esi
mov    %rbx,%rdi
call   1070 <realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
movl   $0x6d6f632e,(%rbx,%rax,1)
movb   $0x0,0x4(%rbx,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Linkerist\00"
@.str.1 = [28 x i8] c"String = %s, Address = %u\0A\00"
@.str.2 = [5 x i8] c".com\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i8* @malloc(i64 15)
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = call i8* @strcpy(i8* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%6 = load i8*, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %7)
%9 = load i8*, i8** %2
%10 = call i8* @realloc(i8* %9, i64 25)
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = call i8* @strcat(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%13 = load i8*, i8** %2
%14 = load i8*, i8** %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* %14)
%16 = load i8*, i8** %2
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"Linkerist\00"
@.str.1 = [28 x i8] c"String = %s, Address = %u\0A\00"
@.str.2 = [5 x i8] c".com\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(15) i8* @malloc(i64 15)
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(10) %1, i8* align 1 dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 10, i1 false)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %1)
%3 = tail call dereferenceable_or_null(25) i8* @realloc(i8* %1, i64 25)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = getelementptr i8, i8* %3, i64 %4
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %5, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 5, i1 false)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %3)
tail call void @free(i8* %3)
ret i32 0
}