int main(void) {
  int *i = nm_malloc(sizeof *i * 10);
  printf("%p\n", (void *)i);
  i[3] = 3;
  printf("%d\n", i[3]);
  nm_free(i);
  i = nm_malloc(sizeof *i * 30);
  printf("%p\n", (void *)i);
  i[29] = 42;
  printf("%d\n", i[29]);
  char *c = nm_malloc(10);
  char *c2 = nm_malloc(10);
  printf("%p\n%p\n", (void *)c, (void *)c2);
  c[9] = 'h';
  c2[9] = 'i';
  printf("%c\n%c\n", c[9], c2[9]);
  nm_free(c);
  nm_free(c2);
  nm_free(i);
  c = nm_malloc(60);
  printf("%p\n", (void *)c);
  c = "hello, world!";
  printf("%s\n", c);
  nm_free(c);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x28,%edi
mov    $0x0,%al
call   1040 <nm_malloc@plt>
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movl   $0x3,0xc(%rax)
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%esi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1050 <nm_free@plt>
mov    $0x78,%edi
mov    $0x0,%al
call   1040 <nm_malloc@plt>
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movl   $0x2a,0x74(%rax)
mov    -0x8(%rbp),%rax
mov    0x74(%rax),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xa,%edi
mov    $0x0,%al
call   1040 <nm_malloc@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    $0xa,%edi
mov    $0x0,%al
call   1040 <nm_malloc@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movb   $0x68,0x9(%rax)
mov    -0x18(%rbp),%rax
movb   $0x69,0x9(%rax)
mov    -0x10(%rbp),%rax
movsbl 0x9(%rax),%esi
mov    -0x18(%rbp),%rax
movsbl 0x9(%rax),%edx
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1050 <nm_free@plt>
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1050 <nm_free@plt>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1050 <nm_free@plt>
mov    $0x3c,%edi
mov    $0x0,%al
call   1040 <nm_malloc@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd93(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1050 <nm_free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x28,%edi
xor    %eax,%eax
call   1050 <nm_malloc@plt>
movslq %eax,%rbx
lea    0xea9(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x3,0xc(%rbx)
lea    0xe87(%rip),%r15
mov    %r15,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <nm_free@plt>
mov    $0x78,%edi
xor    %eax,%eax
call   1050 <nm_malloc@plt>
movslq %eax,%r12
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x2a,0x74(%r12)
mov    %r15,%rdi
mov    $0x2a,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
xor    %eax,%eax
call   1050 <nm_malloc@plt>
movslq %eax,%rbx
mov    $0xa,%edi
xor    %eax,%eax
call   1050 <nm_malloc@plt>
movslq %eax,%r15
lea    0xe19(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
movb   $0x68,0x9(%rbx)
movb   $0x69,0x9(%r15)
movsbl 0x9(%rbx),%esi
lea    0xdff(%rip),%rdi
mov    $0x69,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <nm_free@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <nm_free@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <nm_free@plt>
mov    $0x3c,%edi
xor    %eax,%eax
call   1050 <nm_malloc@plt>
movslq %eax,%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdbc(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <nm_free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%p\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [7 x i8] c"%p\0A%p\0A\00"
@.str.3 = [7 x i8] c"%c\0A%c\0A\00"
@.str.4 = [14 x i8] c"hello, world!\00"
@.str.5 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i32 (i64, ...) bitcast (i32 (...)* @nm_malloc to i32 (i64, ...)*)(i64 40)
%5 = sext i32 %4 to i64
%6 = inttoptr i64 %5 to i32*
store i32* %6, i32** %1
%7 = load i32*, i32** %1
%8 = bitcast i32* %7 to i8*
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32*, i32** %1
%11 = getelementptr inbounds i32, i32* %10, i64 3
store i32 3, i32* %11
%12 = load i32*, i32** %1
%13 = getelementptr inbounds i32, i32* %12, i64 3
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32*, i32** %1
%17 = call i32 (i32*, ...) bitcast (i32 (...)* @nm_free to i32 (i32*, ...)*)(i32* %16)
%18 = call i32 (i64, ...) bitcast (i32 (...)* @nm_malloc to i32 (i64, ...)*)(i64 120)
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i32*
store i32* %20, i32** %1
%21 = load i32*, i32** %1
%22 = bitcast i32* %21 to i8*
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load i32*, i32** %1
%25 = getelementptr inbounds i32, i32* %24, i64 29
store i32 42, i32* %25
%26 = load i32*, i32** %1
%27 = getelementptr inbounds i32, i32* %26, i64 29
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = call i32 (i32, ...) bitcast (i32 (...)* @nm_malloc to i32 (i32, ...)*)(i32 10)
%31 = sext i32 %30 to i64
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %2
%33 = call i32 (i32, ...) bitcast (i32 (...)* @nm_malloc to i32 (i32, ...)*)(i32 10)
%34 = sext i32 %33 to i64
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %3
%36 = load i8*, i8** %2
%37 = load i8*, i8** %3
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %36, i8* %37)
%39 = load i8*, i8** %2
%40 = getelementptr inbounds i8, i8* %39, i64 9
store i8 104, i8* %40
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 9
store i8 105, i8* %42
%43 = load i8*, i8** %2
%44 = getelementptr inbounds i8, i8* %43, i64 9
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = load i8*, i8** %3
%48 = getelementptr inbounds i8, i8* %47, i64 9
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %46, i32 %50)
%52 = load i8*, i8** %2
%53 = call i32 (i8*, ...) bitcast (i32 (...)* @nm_free to i32 (i8*, ...)*)(i8* %52)
%54 = load i8*, i8** %3
%55 = call i32 (i8*, ...) bitcast (i32 (...)* @nm_free to i32 (i8*, ...)*)(i8* %54)
%56 = load i32*, i32** %1
%57 = call i32 (i32*, ...) bitcast (i32 (...)* @nm_free to i32 (i32*, ...)*)(i32* %56)
%58 = call i32 (i32, ...) bitcast (i32 (...)* @nm_malloc to i32 (i32, ...)*)(i32 60)
%59 = sext i32 %58 to i64
%60 = inttoptr i64 %59 to i8*
store i8* %60, i8** %2
%61 = load i8*, i8** %2
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %61)
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8** %2
%63 = load i8*, i8** %2
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %63)
%65 = load i8*, i8** %2
%66 = call i32 (i8*, ...) bitcast (i32 (...)* @nm_free to i32 (i8*, ...)*)(i8* %65)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%p\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [7 x i8] c"%p\0A%p\0A\00"
@.str.3 = [7 x i8] c"%c\0A%c\0A\00"
@.str.4 = [14 x i8] c"hello, world!\00"
define i32 @main() {
%1 = tail call i32 (i64, ...) bitcast (i32 (...)* @nm_malloc to i32 (i64, ...)*)(i64 40)
%2 = sext i32 %1 to i64
%3 = inttoptr i64 %2 to i32*
%4 = inttoptr i64 %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = getelementptr inbounds i32, i32* %3, i64 3
store i32 3, i32* %6
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%8 = tail call i32 (i32*, ...) bitcast (i32 (...)* @nm_free to i32 (i32*, ...)*)(i32* %3)
%9 = tail call i32 (i64, ...) bitcast (i32 (...)* @nm_malloc to i32 (i64, ...)*)(i64 120)
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i32*
%12 = inttoptr i64 %10 to i8*
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds i32, i32* %11, i64 29
store i32 42, i32* %14
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 42)
%16 = tail call i32 (i32, ...) bitcast (i32 (...)* @nm_malloc to i32 (i32, ...)*)(i32 10)
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i8*
%19 = tail call i32 (i32, ...) bitcast (i32 (...)* @nm_malloc to i32 (i32, ...)*)(i32 10)
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i8*
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %18, i8* %21)
%23 = getelementptr inbounds i8, i8* %18, i64 9
store i8 104, i8* %23
%24 = getelementptr inbounds i8, i8* %21, i64 9
store i8 105, i8* %24
%25 = load i8, i8* %23
%26 = sext i8 %25 to i32
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 105)
%28 = tail call i32 (i8*, ...) bitcast (i32 (...)* @nm_free to i32 (i8*, ...)*)(i8* %18)
%29 = tail call i32 (i8*, ...) bitcast (i32 (...)* @nm_free to i32 (i8*, ...)*)(i8* %21)
%30 = tail call i32 (i32*, ...) bitcast (i32 (...)* @nm_free to i32 (i32*, ...)*)(i32* %11)
%31 = tail call i32 (i32, ...) bitcast (i32 (...)* @nm_malloc to i32 (i32, ...)*)(i32 60)
%32 = sext i32 %31 to i64
%33 = inttoptr i64 %32 to i8*
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%36 = tail call i32 (i8*, ...) bitcast (i32 (...)* @nm_free to i32 (i8*, ...)*)(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}