int main() {
  int *buffer1, *buffer2, *buffer3;
  buffer1 = (int *)malloc(100 * sizeof(int));
  buffer2 = (int *)calloc(100, sizeof(int));
  buffer3 = (int *)realloc(buffer2, 500 * sizeof(int));
  char *string = (char *)malloc(sizeof(char) * 100);
  memset(buffer1, 0, sizeof(int));
  char src[] = "Hello World";
  memcpy(string, src, sizeof(src));
  free(buffer1);
  free(buffer3);
  free(string);
  printf("%d\n", *buffer1);
  printf("%s\n", string);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x190,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x64,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x7d0,%esi
call   1080 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0xe39(%rip),%rax
mov    %rax,-0x34(%rbp)
mov    0xe37(%rip),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x2c(%rbp),%ecx
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@__const.main.src = [12 x i8] c"Hello World\00"
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [12 x i8]
store i32 0, i32* %1
%7 = call i8* @malloc(i64 400)
%8 = bitcast i8* %7 to i32*
store i32* %8, i32** %2
%9 = call i8* @calloc(i64 100, i64 4)
%10 = bitcast i8* %9 to i32*
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = bitcast i32* %11 to i8*
%13 = call i8* @realloc(i8* %12, i64 2000)
%14 = bitcast i8* %13 to i32*
store i32* %14, i32** %4
%15 = call i8* @malloc(i64 100)
store i8* %15, i8** %5
%16 = load i32*, i32** %2
%17 = bitcast i32* %16 to i8*
%18 = bitcast [12 x i8]* %6 to i8*
%19 = load i8*, i8** %5
%20 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%21 = load i32*, i32** %2
%22 = bitcast i32* %21 to i8*
%23 = load i32*, i32** %4
%24 = bitcast i32* %23 to i8*
%25 = load i8*, i8** %5
%26 = load i32*, i32** %2
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i8*, i8** %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(400) i8* @malloc(i64 400)
%2 = bitcast i8* %1 to i32*
%3 = tail call dereferenceable_or_null(100) i8* @malloc(i64 100)
tail call void @free(i8* %1)
tail call void @free(i8* %3)
%4 = load i32, i32* %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i32 @puts(i8* dereferenceable(1) %3)
ret i32 0
}