void matrix_dyna(void) {
  int x, y, lx = 3, ly = 3;
  int **matrix;
  matrix = (int **)malloc(lx * sizeof(int));
  for (x = 0; x < lx; x++)
    matrix[x] = (int *)malloc(ly * sizeof(int));
  printf("Size: %d byte\n", sizeof(matrix));
  for (x = 0; x < lx; x++)
    free(matrix[x]);
  free(matrix);
}


x86 assembly (clang, -O0):
<matrix_dyna>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x3,-0xc(%rbp)
movl   $0x3,-0x10(%rbp)
movslq -0xc(%rbp),%rdi
shl    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1194 <matrix_dyna+0x64>
movslq -0x10(%rbp),%rdi
shl    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    115e <matrix_dyna+0x2e>
lea    0xe65(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d9 <matrix_dyna+0xa9>
mov    -0x18(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <matrix_dyna+0x7e>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix_dyna>:
lea    0xee9(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"Size: %d byte\0A\00"
define void @matrix_dyna() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32**
store i32 3, i32* %3
store i32 3, i32* %4
%6 = load i32, i32* %3
%7 = sext i32 %6 to i64
%8 = mul i64 %7, 4
%9 = call i8* @malloc(i64 %8)
%10 = bitcast i8* %9 to i32**
store i32** %10, i32*** %5
store i32 0, i32* %1
br label %11
11: ; preds = %25, %0
%12 = load i32, i32* %1
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 4
%19 = call i8* @malloc(i64 %18)
%20 = bitcast i8* %19 to i32*
%21 = load i32**, i32*** %5
%22 = load i32, i32* %1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32*, i32** %21, i64 %23
store i32* %20, i32** %24
br label %25
25: ; preds = %15
%26 = load i32, i32* %1
%27 = add nsw i32 %26, 1
store i32 %27, i32* %1
br label %11
28: ; preds = %11
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 8)
store i32 0, i32* %1
br label %30
30: ; preds = %41, %28
%31 = load i32, i32* %1
%32 = load i32, i32* %3
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %44
34: ; preds = %30
%35 = load i32**, i32*** %5
%36 = load i32, i32* %1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32*, i32** %35, i64 %37
%39 = load i32*, i32** %38
%40 = bitcast i32* %39 to i8*
br label %41
41: ; preds = %34
%42 = load i32, i32* %1
%43 = add nsw i32 %42, 1
store i32 %43, i32* %1
br label %30
44: ; preds = %30
%45 = load i32**, i32*** %5
%46 = bitcast i32** %45 to i8*
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"Size: %d byte\0A\00"
define void @matrix_dyna() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 8)
ret void
}