int main(void) {
  int junk[3][4] = {
      {2, 4, 6, 8},
      {3, 5, 7, 9},
      {12, 10, 8, 6},
  };
  int(*pt1)[4];
  pt1 = (int[][4]){{1, 2, 3, -9}, {4, 5, 6, -8}};
  sum_rows(junk, 3);
  sum_cols(junk, 3);
  printf("Sum of all elements = %d\n", sum2d(junk, 3));
  printf("Sum of all elements = %d\n", vla_sum2d(3, 4, junk));
  printf("Sum of all elements = %d\n", vla_sum2d(2, 4, pt1));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x30,%edx
call   1060 <memcpy@plt>
mov    0x2ec5(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    0x2ec2(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0x2ebf(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0x2ebc(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    -0x68(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x3,%esi
mov    $0x0,%al
call   1080 <sum_rows@plt>
lea    -0x40(%rbp),%rdi
mov    $0x3,%esi
mov    $0x0,%al
call   1070 <sum_cols@plt>
lea    -0x40(%rbp),%rdi
mov    $0x3,%esi
mov    $0x0,%al
call   1030 <sum2d@plt>
mov    %eax,%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdx
mov    $0x3,%edi
mov    $0x4,%esi
mov    $0x0,%al
call   1050 <vla_sum2d@plt>
mov    %eax,%esi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%rdx
mov    $0x2,%edi
mov    $0x4,%esi
mov    $0x0,%al
call   1050 <vla_sum2d@plt>
mov    %eax,%esi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xea6(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe8a(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movups 0xeae(%rip),%xmm0
movaps %xmm0,(%rsp)
movups 0xeb3(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1070 <sum_rows@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1060 <sum_cols@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1030 <sum2d@plt>
lea    0xe85(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x3,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <vla_sum2d@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rdx
mov    $0x2,%edi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <vla_sum2d@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.junk = [3 x [4 x i32]] [[4 x i32] [i32 2, i32 4, i32 6, i32 8], [4 x i32] [i32 3, i32 5, i32 7, i32 9], [4 x i32] [i32 12, i32 10, i32 8, i32 6]]
@constinit = private global [2 x [4 x i32]] [[4 x i32] [i32 1, i32 2, i32 3, i32 -9], [4 x i32] [i32 4, i32 5, i32 6, i32 -8]]
@.str = [26 x i8] c"Sum of all elements = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x [4 x i32]]
%3 = alloca [4 x i32]*
%4 = alloca [2 x [4 x i32]]
store i32 0, i32* %1
%5 = bitcast [3 x [4 x i32]]* %2 to i8*
%6 = getelementptr inbounds [2 x [4 x i32]], [2 x [4 x i32]]* %4, i64 0, i64 0
%7 = bitcast [2 x [4 x i32]]* %4 to i8*
%8 = getelementptr inbounds [2 x [4 x i32]], [2 x [4 x i32]]* %4, i64 0, i64 0
store [4 x i32]* %8, [4 x i32]** %3
%9 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %2, i64 0, i64 0
%10 = call i32 ([4 x i32]*, i32, ...) bitcast (i32 (...)* @sum_rows to i32 ([4 x i32]*, i32, ...)*)([4 x i32]* %9, i32 3)
%11 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %2, i64 0, i64 0
%12 = call i32 ([4 x i32]*, i32, ...) bitcast (i32 (...)* @sum_cols to i32 ([4 x i32]*, i32, ...)*)([4 x i32]* %11, i32 3)
%13 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %2, i64 0, i64 0
%14 = call i32 ([4 x i32]*, i32, ...) bitcast (i32 (...)* @sum2d to i32 ([4 x i32]*, i32, ...)*)([4 x i32]* %13, i32 3)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %2, i64 0, i64 0
%17 = call i32 (i32, i32, [4 x i32]*, ...) bitcast (i32 (...)* @vla_sum2d to i32 (i32, i32, [4 x i32]*, ...)*)(i32 3, i32 4, [4 x i32]* %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load [4 x i32]*, [4 x i32]** %3
%20 = call i32 (i32, i32, [4 x i32]*, ...) bitcast (i32 (...)* @vla_sum2d to i32 (i32, i32, [4 x i32]*, ...)*)(i32 2, i32 4, [4 x i32]* %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %20)
ret i32 0
}

LLVM IR (-O2):
@__const.main.junk = [3 x [4 x i32]] [[4 x i32] [i32 2, i32 4, i32 6, i32 8], [4 x i32] [i32 3, i32 5, i32 7, i32 9], [4 x i32] [i32 12, i32 10, i32 8, i32 6]]
@constinit = [2 x [4 x i32]] [[4 x i32] [i32 1, i32 2, i32 3, i32 -9], [4 x i32] [i32 4, i32 5, i32 6, i32 -8]]
@.str = [26 x i8] c"Sum of all elements = %d\0A\00"
define i32 @main() {
%1 = alloca [3 x [4 x i32]]
%2 = alloca [2 x [4 x i32]]
%3 = bitcast [3 x [4 x i32]]* %1 to i8*
%4 = bitcast [2 x [4 x i32]]* %2 to i8*
%5 = getelementptr inbounds [2 x [4 x i32]], [2 x [4 x i32]]* %2, i64 0, i64 0
%6 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 0, i64 0
%7 = call i32 ([4 x i32]*, i32, ...) bitcast (i32 (...)* @sum_rows to i32 ([4 x i32]*, i32, ...)*)([4 x i32]* %6, i32 3)
%8 = call i32 ([4 x i32]*, i32, ...) bitcast (i32 (...)* @sum_cols to i32 ([4 x i32]*, i32, ...)*)([4 x i32]* %6, i32 3)
%9 = call i32 ([4 x i32]*, i32, ...) bitcast (i32 (...)* @sum2d to i32 ([4 x i32]*, i32, ...)*)([4 x i32]* %6, i32 3)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 (i32, i32, [4 x i32]*, ...) bitcast (i32 (...)* @vla_sum2d to i32 (i32, i32, [4 x i32]*, ...)*)(i32 3, i32 4, [4 x i32]* %6)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 (i32, i32, [4 x i32]*, ...) bitcast (i32 (...)* @vla_sum2d to i32 (i32, i32, [4 x i32]*, ...)*)(i32 2, i32 4, [4 x i32]* %5)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %13)
ret i32 0
}