#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 *__mlib_calloc(int, int);
int /*<<< orphan*/ __mlib_free(int *);
int *__mlib_malloc(int);
int *__mlib_realloc(int *, int);
char *__mlib_strdup(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int *a = __mlib_malloc(sizeof(int));
  *a = 5;
  printf("%d\n", *a);
  int *b = __mlib_calloc(2, sizeof(int));
  b[0] = 'a';
  b[1] = 'b';
  printf("%c %c\n", b[0], b[1]);
  b = __mlib_realloc(b, 3 * sizeof(int));
  b[2] = 'c';
  printf("%c %c %c\n", b[0], b[1], b[2]);
  char *c = __mlib_strdup("test123");
  printf("%s\n", c);
  __mlib_free(a);
  b = __mlib_realloc(b, 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1080 <__mlib_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   1050 <printf@plt>
mov    $0x2,%edi
mov    $0x4,%esi
call   1070 <__mlib_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   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   1060 <__mlib_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   1050 <printf@plt>
lea    0xdea(%rip),%rdi
call   1040 <__mlib_strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <__mlib_free@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1060 <__mlib_realloc@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x4,%edi
call   1090 <__mlib_malloc@plt>
mov    %rax,%r14
movl   $0x5,(%rax)
lea    0xe72(%rip),%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x2,%edi
mov    $0x4,%esi
call   1080 <__mlib_calloc@plt>
mov    %rax,%rbx
movabs $0x6200000061,%rax
mov    %rax,(%rbx)
lea    0xe47(%rip),%rdi
mov    $0x61,%esi
mov    $0x62,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
call   1070 <__mlib_realloc@plt>
mov    %rax,%rbx
movl   $0x63,0x8(%rax)
mov    (%rax),%esi
mov    0x4(%rax),%edx
lea    0xe10(%rip),%rdi
mov    $0x63,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe07(%rip),%rdi
call   1050 <__mlib_strdup@plt>
mov    %rax,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <__mlib_free@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <__mlib_realloc@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 i32* @__mlib_malloc(i32 4)
store i32* %5, i32** %2
%6 = load i32*, i32** %2
store i32 5, i32* %6
%7 = load i32*, i32** %2
%8 = load i32, i32* %7
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32* @__mlib_calloc(i32 2, i32 4)
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = getelementptr inbounds i32, i32* %11, i64 0
store i32 97, i32* %12
%13 = load i32*, i32** %3
%14 = getelementptr inbounds i32, i32* %13, i64 1
store i32 98, i32* %14
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 0
%17 = load i32, i32* %16
%18 = load i32*, i32** %3
%19 = getelementptr inbounds i32, i32* %18, i64 1
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %20)
%22 = load i32*, i32** %3
%23 = call i32* @__mlib_realloc(i32* %22, i32 12)
store i32* %23, i32** %3
%24 = load i32*, i32** %3
%25 = getelementptr inbounds i32, i32* %24, i64 2
store i32 99, i32* %25
%26 = load i32*, i32** %3
%27 = getelementptr inbounds i32, i32* %26, i64 0
%28 = load i32, i32* %27
%29 = load i32*, i32** %3
%30 = getelementptr inbounds i32, i32* %29, i64 1
%31 = load i32, i32* %30
%32 = load i32*, i32** %3
%33 = getelementptr inbounds i32, i32* %32, i64 2
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %31, i32 %34)
%36 = call i8* @__mlib_strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i8* %36, i8** %4
%37 = load i8*, i8** %4
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%39 = load i32*, i32** %2
%40 = call i32 @__mlib_free(i32* %39)
%41 = load i32*, i32** %3
%42 = call i32* @__mlib_realloc(i32* %41, i32 0)
store i32* %42, i32** %3
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* @__mlib_malloc(i32 4)
store i32 5, i32* %1
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 5)
%3 = tail call i32* @__mlib_calloc(i32 2, i32 4)
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 i32* @__mlib_realloc(i32* %3, i32 12)
%7 = getelementptr inbounds i32, i32* %6, i64 2
store i32 99, i32* %7
%8 = load i32, i32* %6
%9 = getelementptr inbounds i32, i32* %6, i64 1
%10 = load i32, i32* %9
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %8, i32 %10, i32 99)
%12 = tail call i8* @__mlib_strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) %12)
%14 = tail call i32 @__mlib_free(i32* %1)
%15 = tail call i32* @__mlib_realloc(i32* %6, i32 0)
ret i32 0
}