#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 *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main() {
  char *buffer1 = (char *)malloc(128 * 1024);
  strcpy(buffer1, "Hello");
  free(buffer1);
  char *buffer2 = (char *)malloc(128 * 1024);
  printf("buffer1 = %p\n", buffer1);
  printf("buffer2 = %p\n", buffer2);
  strcpy(buffer1, "bye");
  free(buffer2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x20000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe98(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x20000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe77(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe75(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x20000,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xea8(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x20000,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xe8a(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
lea    0xe89(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Hello\00"
@.str.1 = [14 x i8] c"buffer1 = %p\0A\00"
@.str.2 = [14 x i8] c"buffer2 = %p\0A\00"
@.str.3 = [4 x i8] c"bye\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i64 @malloc(i32 131072)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %2
%9 = call i32 @free(i8* %8)
%10 = call i64 @malloc(i32 131072)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %3
%12 = load i8*, i8** %2
%13 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %3
%15 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %2
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%18 = load i8*, i8** %3
%19 = call i32 @free(i8* %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"Hello\00"
@.str.1 = [14 x i8] c"buffer1 = %p\0A\00"
@.str.2 = [14 x i8] c"buffer2 = %p\0A\00"
@.str.3 = [4 x i8] c"bye\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 131072)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @free(i8* %2)
%5 = tail call i64 @malloc(i32 131072)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%9 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%10 = tail call i32 @free(i8* %6)
ret i32 0
}