int main() {
  int **matrix = alloc2d(10, 10);
  int i = 0;
  for (; i < 10; i++)
    free(matrix[i]);
  free(matrix);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa,%esi
mov    %esi,%edi
mov    $0x0,%al
call   1040 <alloc2d@plt>
cltq
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1173 <main+0x53>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114a <main+0x2a>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0xa,%edi
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <alloc2d@plt>
movslq %eax,%rbx
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    0x8(%rbx),%rdi
call   1030 <free@plt>
mov    0x10(%rbx),%rdi
call   1030 <free@plt>
mov    0x18(%rbx),%rdi
call   1030 <free@plt>
mov    0x20(%rbx),%rdi
call   1030 <free@plt>
mov    0x28(%rbx),%rdi
call   1030 <free@plt>
mov    0x30(%rbx),%rdi
call   1030 <free@plt>
mov    0x38(%rbx),%rdi
call   1030 <free@plt>
mov    0x40(%rbx),%rdi
call   1030 <free@plt>
mov    0x48(%rbx),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32**
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (i32, i32, ...) bitcast (i32 (...)* @alloc2d to i32 (i32, i32, ...)*)(i32 10, i32 10)
%5 = sext i32 %4 to i64
%6 = inttoptr i64 %5 to i32**
store i32** %6, i32*** %2
store i32 0, i32* %3
br label %7
7: ; preds = %17, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = load i32**, i32*** %2
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32*, i32** %11, i64 %13
%15 = load i32*, i32** %14
%16 = bitcast i32* %15 to i8*
br label %17
17: ; preds = %10
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %7
20: ; preds = %7
%21 = load i32**, i32*** %2
%22 = bitcast i32** %21 to i8*
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @alloc2d to i32 (i32, i32, ...)*)(i32 10, i32 10)
%2 = sext i32 %1 to i64
%3 = inttoptr i64 %2 to i32**
%4 = inttoptr i64 %2 to i8**
%5 = load i8*, i8** %4
tail call void @free(i8* %5)
%6 = getelementptr inbounds i32*, i32** %3, i64 1
%7 = bitcast i32** %6 to i8**
%8 = load i8*, i8** %7
tail call void @free(i8* %8)
%9 = getelementptr inbounds i32*, i32** %3, i64 2
%10 = bitcast i32** %9 to i8**
%11 = load i8*, i8** %10
tail call void @free(i8* %11)
%12 = getelementptr inbounds i32*, i32** %3, i64 3
%13 = bitcast i32** %12 to i8**
%14 = load i8*, i8** %13
tail call void @free(i8* %14)
%15 = getelementptr inbounds i32*, i32** %3, i64 4
%16 = bitcast i32** %15 to i8**
%17 = load i8*, i8** %16
tail call void @free(i8* %17)
%18 = getelementptr inbounds i32*, i32** %3, i64 5
%19 = bitcast i32** %18 to i8**
%20 = load i8*, i8** %19
tail call void @free(i8* %20)
%21 = getelementptr inbounds i32*, i32** %3, i64 6
%22 = bitcast i32** %21 to i8**
%23 = load i8*, i8** %22
tail call void @free(i8* %23)
%24 = getelementptr inbounds i32*, i32** %3, i64 7
%25 = bitcast i32** %24 to i8**
%26 = load i8*, i8** %25
tail call void @free(i8* %26)
%27 = getelementptr inbounds i32*, i32** %3, i64 8
%28 = bitcast i32** %27 to i8**
%29 = load i8*, i8** %28
tail call void @free(i8* %29)
%30 = getelementptr inbounds i32*, i32** %3, i64 9
%31 = bitcast i32** %30 to i8**
%32 = load i8*, i8** %31
tail call void @free(i8* %32)
%33 = inttoptr i64 %2 to i8*
tail call void @free(i8* %33)
ret i32 0
}