int main(void) {
  int *a = malloc(sizeof(int));
  *a = 5;
  printf("%d\n", *a);
  int *b = calloc(2, sizeof(int));
  b[0] = 'a';
  b[1] = 'b';
  printf("%c %c\n", b[0], b[1]);
  b = realloc(b, 3 * sizeof(int));
  b[2] = 'c';
  printf("%c %c %c\n", b[0], b[1], b[2]);
  char *c = strdup("test123");
  printf("%s\n", c);
  free(a);
  b = realloc(b, 0);
  free(c);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x5,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x61,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x62,0x4(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x63,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%ecx
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdea(%rip),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%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
lea    0xe95(%rip),%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
movabs $0x6200000061,%rax
mov    %rax,(%rbx)
lea    0xe6a(%rip),%rdi
mov    $0x61,%esi
mov    $0x62,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xc,%esi
mov    %rbx,%rdi
call   1070 <realloc@plt>
mov    %rax,%rbx
movl   $0x63,0x8(%rax)
mov    (%rax),%esi
mov    0x4(%rax),%edx
lea    0xe33(%rip),%rdi
mov    $0x63,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe2a(%rip),%rdi
call   1080 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <realloc@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [7 x i8] c"%c %c\0A\00"
@.str.2 = [10 x i8] c"%c %c %c\0A\00"
@.str.3 = [8 x i8] c"test123\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i8* @malloc(i64 4)
%6 = bitcast i8* %5 to i32*
store i32* %6, i32** %2
%7 = load i32*, i32** %2
store i32 5, i32* %7
%8 = load i32*, i32** %2
%9 = load i32, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i8* @calloc(i64 2, i64 4)
%12 = bitcast i8* %11 to i32*
store i32* %12, i32** %3
%13 = load i32*, i32** %3
%14 = getelementptr inbounds i32, i32* %13, i64 0
store i32 97, i32* %14
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 1
store i32 98, i32* %16
%17 = load i32*, i32** %3
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = load i32, i32* %18
%20 = load i32*, i32** %3
%21 = getelementptr inbounds i32, i32* %20, i64 1
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %22)
%24 = load i32*, i32** %3
%25 = bitcast i32* %24 to i8*
%26 = call i8* @realloc(i8* %25, i64 12)
%27 = bitcast i8* %26 to i32*
store i32* %27, i32** %3
%28 = load i32*, i32** %3
%29 = getelementptr inbounds i32, i32* %28, i64 2
store i32 99, i32* %29
%30 = load i32*, i32** %3
%31 = getelementptr inbounds i32, i32* %30, i64 0
%32 = load i32, i32* %31
%33 = load i32*, i32** %3
%34 = getelementptr inbounds i32, i32* %33, i64 1
%35 = load i32, i32* %34
%36 = load i32*, i32** %3
%37 = getelementptr inbounds i32, i32* %36, i64 2
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %32, i32 %35, i32 %38)
%40 = call i8* @strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i8* %40, i8** %4
%41 = load i8*, i8** %4
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %41)
%43 = load i32*, i32** %2
%44 = bitcast i32* %43 to i8*
%45 = load i32*, i32** %3
%46 = bitcast i32* %45 to i8*
%47 = call i8* @realloc(i8* %46, i64 0)
%48 = bitcast i8* %47 to i32*
store i32* %48, i32** %3
%49 = load i8*, i8** %4
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [7 x i8] c"%c %c\0A\00"
@.str.2 = [10 x i8] c"%c %c %c\0A\00"
@.str.3 = [8 x i8] c"test123\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 5)
%2 = tail call dereferenceable_or_null(8) i8* @calloc(i64 2, i64 4)
%3 = bitcast i8* %2 to i32*
store i32 97, i32* %3
%4 = getelementptr inbounds i32, i32* %3, i64 1
store i32 98, i32* %4
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 97, i32 98)
%6 = tail call dereferenceable_or_null(12) i8* @realloc(i8* %2, i64 12)
%7 = bitcast i8* %6 to i32*
%8 = getelementptr inbounds i32, i32* %7, i64 2
store i32 99, i32* %8
%9 = load i32, i32* %7
%10 = getelementptr inbounds i32, i32* %7, i64 1
%11 = load i32, i32* %10
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %9, i32 %11, i32 99)
%13 = tail call dereferenceable_or_null(8) i8* @strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) %13)
%15 = tail call i8* @realloc(i8* %6, i64 0)
tail call void @free(i8* %13)
ret i32 0
}