int main() {
  int ***m;
  int i, j, k;
  m = (int ***)malloc(3 * sizeof(int **));
  for (i = 0; i < 3; i++) {
    m[i] = (int **)malloc(4 * sizeof(int *));
    for (j = 0; j < 4; j++) {
      m[i][j] = (int *)malloc(5 * sizeof(int));
      for (k = 0; k < 5; k++) {
        m[i][j][k] = 7;
      }
    }
  }
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 4; j++) {
      free(m[i][j]);
    }
    free(m[i]);
  }
  free(m);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x18,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11fd <main+0xdd>
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    11ea <main+0xca>
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jge    11d7 <main+0xb7>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x7,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a0 <main+0x80>
jmp    11dc <main+0xbc>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116e <main+0x4e>
jmp    11ef <main+0xcf>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1144 <main+0x24>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    1265 <main+0x145>
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    1246 <main+0x126>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1215 <main+0xf5>
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    1204 <main+0xe4>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x18,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,(%r14)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx)
movaps 0xeaa(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x7,0x10(%rax)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,0x8(%rbx)
movaps 0xe8b(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x7,0x10(%rax)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,0x10(%rbx)
movaps 0xe6c(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x7,0x10(%rax)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,0x18(%rbx)
movaps 0xe4d(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x7,0x10(%rax)
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x8(%r14)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx)
movaps 0xe1e(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x7,0x10(%rax)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,0x8(%rbx)
movaps 0xdff(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x7,0x10(%rax)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,0x10(%rbx)
movaps 0xde0(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x7,0x10(%rax)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,0x18(%rbx)
movaps 0xdc1(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x7,0x10(%rax)
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    %rax,0x10(%r14)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,(%r15)
movaps 0xd92(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x7,0x10(%rax)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,0x8(%r15)
movaps 0xd73(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x7,0x10(%rax)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,0x10(%r15)
movaps 0xd54(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x7,0x10(%rax)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,0x18(%r15)
movaps 0xd35(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x7,0x10(%rax)
mov    (%r14),%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    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%r14),%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    %rbx,%rdi
call   1030 <free@plt>
mov    (%r15),%rdi
call   1030 <free@plt>
mov    0x8(%r15),%rdi
call   1030 <free@plt>
mov    0x10(%r15),%rdi
call   1030 <free@plt>
mov    0x18(%r15),%rdi
call   1030 <free@plt>
mov    0x10(%r14),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32***
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i8* @malloc(i64 24)
%7 = bitcast i8* %6 to i32***
store i32*** %7, i32**** %2
store i32 0, i32* %3
br label %8
8: ; preds = %56, %0
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %59
11: ; preds = %8
%12 = call i8* @malloc(i64 32)
%13 = bitcast i8* %12 to i32**
%14 = load i32***, i32**** %2
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32**, i32*** %14, i64 %16
store i32** %13, i32*** %17
store i32 0, i32* %4
br label %18
18: ; preds = %52, %11
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 4
br i1 %20, label %21, label %55
21: ; preds = %18
%22 = call i8* @malloc(i64 20)
%23 = bitcast i8* %22 to i32*
%24 = load i32***, i32**** %2
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32**, i32*** %24, i64 %26
%28 = load i32**, i32*** %27
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32*, i32** %28, i64 %30
store i32* %23, i32** %31
store i32 0, i32* %5
br label %32
32: ; preds = %48, %21
%33 = load i32, i32* %5
%34 = icmp slt i32 %33, 5
br i1 %34, label %35, label %51
35: ; preds = %32
%36 = load i32***, i32**** %2
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32**, i32*** %36, i64 %38
%40 = load i32**, i32*** %39
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32*, i32** %40, i64 %42
%44 = load i32*, i32** %43
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
store i32 7, i32* %47
br label %48
48: ; preds = %35
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %32
51: ; preds = %32
br label %52
52: ; preds = %51
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %18
55: ; preds = %18
br label %56
56: ; preds = %55
%57 = load i32, i32* %3
%58 = add nsw i32 %57, 1
store i32 %58, i32* %3
br label %8
59: ; preds = %8
store i32 0, i32* %3
br label %60
60: ; preds = %88, %59
%61 = load i32, i32* %3
%62 = icmp slt i32 %61, 3
br i1 %62, label %63, label %91
63: ; preds = %60
store i32 0, i32* %4
br label %64
64: ; preds = %78, %63
%65 = load i32, i32* %4
%66 = icmp slt i32 %65, 4
br i1 %66, label %67, label %81
67: ; preds = %64
%68 = load i32***, i32**** %2
%69 = load i32, i32* %3
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32**, i32*** %68, i64 %70
%72 = load i32**, i32*** %71
%73 = load i32, i32* %4
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32*, i32** %72, i64 %74
%76 = load i32*, i32** %75
%77 = bitcast i32* %76 to i8*
br label %78
78: ; preds = %67
%79 = load i32, i32* %4
%80 = add nsw i32 %79, 1
store i32 %80, i32* %4
br label %64
81: ; preds = %64
%82 = load i32***, i32**** %2
%83 = load i32, i32* %3
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i32**, i32*** %82, i64 %84
%86 = load i32**, i32*** %85
%87 = bitcast i32** %86 to i8*
br label %88
88: ; preds = %81
%89 = load i32, i32* %3
%90 = add nsw i32 %89, 1
store i32 %90, i32* %3
br label %60
91: ; preds = %60
%92 = load i32***, i32**** %2
%93 = bitcast i32*** %92 to i8*
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call dereferenceable_or_null(24) i8* @malloc(i64 24)
%2 = bitcast i8* %1 to i32***
%3 = tail call dereferenceable_or_null(32) i8* @malloc(i64 32)
%4 = bitcast i8* %1 to i8**
store i8* %3, i8** %4
%5 = bitcast i8* %3 to i32**
%6 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%7 = bitcast i8* %3 to i8**
store i8* %6, i8** %7
%8 = bitcast i8* %6 to i32*
%9 = bitcast i8* %6 to <4 x i32>*
store <4 x i32> <i32 7, i32 7, i32 7, i32 7>, <4 x i32>* %9
%10 = getelementptr inbounds i32, i32* %8, i64 4
store i32 7, i32* %10
%11 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%12 = getelementptr inbounds i32*, i32** %5, i64 1
%13 = bitcast i32** %12 to i8**
store i8* %11, i8** %13
%14 = bitcast i8* %11 to i32*
%15 = bitcast i8* %11 to <4 x i32>*
store <4 x i32> <i32 7, i32 7, i32 7, i32 7>, <4 x i32>* %15
%16 = getelementptr inbounds i32, i32* %14, i64 4
store i32 7, i32* %16
%17 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%18 = getelementptr inbounds i32*, i32** %5, i64 2
%19 = bitcast i32** %18 to i8**
store i8* %17, i8** %19
%20 = bitcast i8* %17 to i32*
%21 = bitcast i8* %17 to <4 x i32>*
store <4 x i32> <i32 7, i32 7, i32 7, i32 7>, <4 x i32>* %21
%22 = getelementptr inbounds i32, i32* %20, i64 4
store i32 7, i32* %22
%23 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%24 = getelementptr inbounds i32*, i32** %5, i64 3
%25 = bitcast i32** %24 to i8**
store i8* %23, i8** %25
%26 = bitcast i8* %23 to i32*
%27 = bitcast i8* %23 to <4 x i32>*
store <4 x i32> <i32 7, i32 7, i32 7, i32 7>, <4 x i32>* %27
%28 = getelementptr inbounds i32, i32* %26, i64 4
store i32 7, i32* %28
%29 = tail call dereferenceable_or_null(32) i8* @malloc(i64 32)
%30 = getelementptr inbounds i32**, i32*** %2, i64 1
%31 = bitcast i32*** %30 to i8**
store i8* %29, i8** %31
%32 = bitcast i8* %29 to i32**
%33 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%34 = bitcast i8* %29 to i8**
store i8* %33, i8** %34
%35 = bitcast i8* %33 to i32*
%36 = bitcast i8* %33 to <4 x i32>*
store <4 x i32> <i32 7, i32 7, i32 7, i32 7>, <4 x i32>* %36
%37 = getelementptr inbounds i32, i32* %35, i64 4
store i32 7, i32* %37
%38 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%39 = getelementptr inbounds i32*, i32** %32, i64 1
%40 = bitcast i32** %39 to i8**
store i8* %38, i8** %40
%41 = bitcast i8* %38 to i32*
%42 = bitcast i8* %38 to <4 x i32>*
store <4 x i32> <i32 7, i32 7, i32 7, i32 7>, <4 x i32>* %42
%43 = getelementptr inbounds i32, i32* %41, i64 4
store i32 7, i32* %43
%44 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%45 = getelementptr inbounds i32*, i32** %32, i64 2
%46 = bitcast i32** %45 to i8**
store i8* %44, i8** %46
%47 = bitcast i8* %44 to i32*
%48 = bitcast i8* %44 to <4 x i32>*
store <4 x i32> <i32 7, i32 7, i32 7, i32 7>, <4 x i32>* %48
%49 = getelementptr inbounds i32, i32* %47, i64 4
store i32 7, i32* %49
%50 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%51 = getelementptr inbounds i32*, i32** %32, i64 3
%52 = bitcast i32** %51 to i8**
store i8* %50, i8** %52
%53 = bitcast i8* %50 to i32*
%54 = bitcast i8* %50 to <4 x i32>*
store <4 x i32> <i32 7, i32 7, i32 7, i32 7>, <4 x i32>* %54
%55 = getelementptr inbounds i32, i32* %53, i64 4
store i32 7, i32* %55
%56 = tail call dereferenceable_or_null(32) i8* @malloc(i64 32)
%57 = getelementptr inbounds i32**, i32*** %2, i64 2
%58 = bitcast i32*** %57 to i8**
store i8* %56, i8** %58
%59 = bitcast i8* %56 to i32**
%60 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%61 = bitcast i8* %56 to i8**
store i8* %60, i8** %61
%62 = bitcast i8* %60 to i32*
%63 = bitcast i8* %60 to <4 x i32>*
store <4 x i32> <i32 7, i32 7, i32 7, i32 7>, <4 x i32>* %63
%64 = getelementptr inbounds i32, i32* %62, i64 4
store i32 7, i32* %64
%65 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%66 = getelementptr inbounds i32*, i32** %59, i64 1
%67 = bitcast i32** %66 to i8**
store i8* %65, i8** %67
%68 = bitcast i8* %65 to i32*
%69 = bitcast i8* %65 to <4 x i32>*
store <4 x i32> <i32 7, i32 7, i32 7, i32 7>, <4 x i32>* %69
%70 = getelementptr inbounds i32, i32* %68, i64 4
store i32 7, i32* %70
%71 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%72 = getelementptr inbounds i32*, i32** %59, i64 2
%73 = bitcast i32** %72 to i8**
store i8* %71, i8** %73
%74 = bitcast i8* %71 to i32*
%75 = bitcast i8* %71 to <4 x i32>*
store <4 x i32> <i32 7, i32 7, i32 7, i32 7>, <4 x i32>* %75
%76 = getelementptr inbounds i32, i32* %74, i64 4
store i32 7, i32* %76
%77 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%78 = getelementptr inbounds i32*, i32** %59, i64 3
%79 = bitcast i32** %78 to i8**
store i8* %77, i8** %79
%80 = bitcast i8* %77 to i32*
%81 = bitcast i8* %77 to <4 x i32>*
store <4 x i32> <i32 7, i32 7, i32 7, i32 7>, <4 x i32>* %81
%82 = getelementptr inbounds i32, i32* %80, i64 4
store i32 7, i32* %82
%83 = load i32**, i32*** %2
%84 = bitcast i32** %83 to i8**
%85 = load i8*, i8** %84
tail call void @free(i8* %85)
%86 = getelementptr inbounds i32*, i32** %83, i64 1
%87 = bitcast i32** %86 to i8**
%88 = load i8*, i8** %87
tail call void @free(i8* %88)
%89 = getelementptr inbounds i32*, i32** %83, i64 2
%90 = bitcast i32** %89 to i8**
%91 = load i8*, i8** %90
tail call void @free(i8* %91)
%92 = getelementptr inbounds i32*, i32** %83, i64 3
%93 = bitcast i32** %92 to i8**
%94 = load i8*, i8** %93
tail call void @free(i8* %94)
%95 = bitcast i32** %83 to i8*
tail call void @free(i8* %95)
%96 = load i32**, i32*** %30
%97 = bitcast i32** %96 to i8**
%98 = load i8*, i8** %97
tail call void @free(i8* %98)
%99 = getelementptr inbounds i32*, i32** %96, i64 1
%100 = bitcast i32** %99 to i8**
%101 = load i8*, i8** %100
tail call void @free(i8* %101)
%102 = getelementptr inbounds i32*, i32** %96, i64 2
%103 = bitcast i32** %102 to i8**
%104 = load i8*, i8** %103
tail call void @free(i8* %104)
%105 = getelementptr inbounds i32*, i32** %96, i64 3
%106 = bitcast i32** %105 to i8**
%107 = load i8*, i8** %106
tail call void @free(i8* %107)
%108 = bitcast i32** %96 to i8*
tail call void @free(i8* %108)
%109 = load i8*, i8** %61
tail call void @free(i8* %109)
%110 = load i8*, i8** %67
tail call void @free(i8* %110)
%111 = load i8*, i8** %73
tail call void @free(i8* %111)
%112 = load i8*, i8** %79
tail call void @free(i8* %112)
%113 = load i8*, i8** %58
tail call void @free(i8* %113)
tail call void @free(i8* %1)
ret i32 0
}