#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int sum2d(int, int, int **);
int main(int argc, char const *argv[]) {
  int i, j;
  int rs = 3;
  int cs = 10;
  int junk[3][4] = {{2, 4, 6, 8}, {3, 5, 7, 9}, {12, 10, 8, 6}};
  int morejunk[3 - 1][4 + 2] = {{20, 30, 40, 50, 60, 70}, {5, 6, 7, 8, 9, 10}};
  int varr[rs][cs];
  for (i = 0; i < rs; i++) {
    for (j = 0; j < cs; j++) {
      varr[i][j] = i * j + j;
    }
  }
  printf("3x5 array\n");
  printf("Sum of all elements = %d\n", sum2d(3, 4, junk));
  printf("2x6 array\n");
  printf("Sum of all elements = %d\n", sum2d(3 - 1, 4 + 2, morejunk));
  printf("3x10 VLA\n");
  printf("Sum of all elements = %d\n", sum2d(rs, cs, varr));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3,-0x1c(%rbp)
movl   $0xa,-0x20(%rbp)
movaps 0xed2(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
movaps 0xeb7(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
movaps 0xe9c(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
movaps 0xee1(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,-0x70(%rbp)
movaps 0xeab(%rip),%xmm0
movaps %xmm0,-0x80(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
mov    %rax,-0xa8(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x88(%rbp)
mov    %rcx,%rdx
imul   %rax,%rdx
lea    0xf(,%rdx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0xa0(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x90(%rbp)
mov    %rax,-0x98(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1248 <main+0x128>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1235 <main+0x115>
mov    -0xa0(%rbp),%rax
mov    -0xa8(%rbp),%rsi
mov    -0x14(%rbp),%edx
imul   -0x18(%rbp),%edx
add    -0x18(%rbp),%edx
movslq -0x14(%rbp),%rcx
imul   %rsi,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ed <main+0xcd>
jmp    123a <main+0x11a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11da <main+0xba>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdx
mov    $0x3,%edi
mov    $0x4,%esi
call   1030 <sum2d@plt>
mov    %eax,%esi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdx
mov    $0x2,%edi
mov    $0x6,%esi
call   1030 <sum2d@plt>
mov    %eax,%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xa0(%rbp),%rdx
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1030 <sum2d@plt>
mov    %eax,%esi
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x88(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xd8,%rsp
mov    %rsp,%r14
movaps 0xf4c(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xf30(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xf14(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xf58(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xf3c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xf20(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xe75(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe79(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe7d(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe7e(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xe7f(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xe80(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xe81(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movabs $0x1b00000018,%rax
mov    %rax,0xd0(%rsp)
lea    0xeea(%rip),%rdi
call   1040 <puts@plt>
lea    0x30(%rsp),%rdx
mov    $0x3,%edi
mov    $0x4,%esi
call   1030 <sum2d@plt>
lea    0xeb0(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec1(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rdx
mov    $0x2,%edi
mov    $0x6,%esi
call   1030 <sum2d@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea1(%rip),%rdi
call   1040 <puts@plt>
lea    0x60(%rsp),%rdx
mov    $0x3,%edi
mov    $0xa,%esi
call   1030 <sum2d@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rsp
xor    %eax,%eax
add    $0xd8,%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]]
@__const.main.morejunk = [2 x [6 x i32]] [[6 x i32] [i32 20, i32 30, i32 40, i32 50, i32 60, i32 70], [6 x i32] [i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]]
@.str = [11 x i8] c"3x5 array\0A\00"
@.str.1 = [26 x i8] c"Sum of all elements = %d\0A\00"
@.str.2 = [11 x i8] c"2x6 array\0A\00"
@.str.3 = [10 x i8] c"3x10 VLA\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [3 x [4 x i32]]
%11 = alloca [2 x [6 x i32]]
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 3, i32* %8
store i32 10, i32* %9
%15 = bitcast [3 x [4 x i32]]* %10 to i8*
%16 = bitcast [2 x [6 x i32]]* %11 to i8*
%17 = load i32, i32* %8
%18 = zext i32 %17 to i64
%19 = load i32, i32* %9
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %12
%22 = mul nuw i64 %18, %20
%23 = alloca i32, i64 %22
store i64 %18, i64* %13
store i64 %20, i64* %14
store i32 0, i32* %6
br label %24
24: ; preds = %50, %2
%25 = load i32, i32* %6
%26 = load i32, i32* %8
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %53
28: ; preds = %24
store i32 0, i32* %7
br label %29
29: ; preds = %46, %28
%30 = load i32, i32* %7
%31 = load i32, i32* %9
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %49
33: ; preds = %29
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = mul nsw i32 %34, %35
%37 = load i32, i32* %7
%38 = add nsw i32 %36, %37
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = mul nsw i64 %40, %20
%42 = getelementptr inbounds i32, i32* %23, i64 %41
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
store i32 %38, i32* %45
br label %46
46: ; preds = %33
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %29
49: ; preds = %29
br label %50
50: ; preds = %49
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %24
53: ; preds = %24
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%55 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %10, i64 0, i64 0
%56 = bitcast [4 x i32]* %55 to i32**
%57 = call i32 @sum2d(i32 3, i32 4, i32** %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%60 = getelementptr inbounds [2 x [6 x i32]], [2 x [6 x i32]]* %11, i64 0, i64 0
%61 = bitcast [6 x i32]* %60 to i32**
%62 = call i32 @sum2d(i32 2, i32 6, i32** %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %62)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%65 = load i32, i32* %8
%66 = load i32, i32* %9
%67 = bitcast i32* %23 to i32**
%68 = call i32 @sum2d(i32 %65, i32 %66, i32** %67)
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %68)
store i32 0, i32* %3
%70 = load i8*, i8** %12
%71 = load i32, i32* %3
ret i32 %71
}

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]]
@__const.main.morejunk = [2 x [6 x i32]] [[6 x i32] [i32 20, i32 30, i32 40, i32 50, i32 60, i32 70], [6 x i32] [i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]]
@.str.1 = [26 x i8] c"Sum of all elements = %d\0A\00"
@str = [10 x i8] c"3x5 array\00"
@str.4 = [10 x i8] c"2x6 array\00"
@str.5 = [9 x i8] c"3x10 VLA\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x [4 x i32]]
%4 = alloca [2 x [6 x i32]]
%5 = bitcast [3 x [4 x i32]]* %3 to i8*
%6 = bitcast [2 x [6 x i32]]* %4 to i8*
%7 = tail call i8* @llvm.stacksave()
%8 = alloca [30 x i32]
%9 = bitcast [30 x i32]* %8 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %9
%10 = getelementptr inbounds [30 x i32], [30 x i32]* %8, i64 0, i64 4
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, <4 x i32>* %11
%12 = getelementptr inbounds [30 x i32], [30 x i32]* %8, i64 0, i64 8
%13 = bitcast i32* %12 to <4 x i32>*
store <4 x i32> <i32 8, i32 9, i32 0, i32 2>, <4 x i32>* %13
%14 = getelementptr inbounds [30 x i32], [30 x i32]* %8, i64 0, i64 12
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> <i32 4, i32 6, i32 8, i32 10>, <4 x i32>* %15
%16 = getelementptr inbounds [30 x i32], [30 x i32]* %8, i64 0, i64 16
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> <i32 12, i32 14, i32 16, i32 18>, <4 x i32>* %17
%18 = getelementptr inbounds [30 x i32], [30 x i32]* %8, i64 0, i64 20
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> <i32 0, i32 3, i32 6, i32 9>, <4 x i32>* %19
%20 = getelementptr inbounds [30 x i32], [30 x i32]* %8, i64 0, i64 24
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> <i32 12, i32 15, i32 18, i32 21>, <4 x i32>* %21
%22 = getelementptr inbounds [30 x i32], [30 x i32]* %8, i64 0, i64 28
store i32 24, i32* %22
%23 = getelementptr inbounds [30 x i32], [30 x i32]* %8, i64 0, i64 29
store i32 27, i32* %23
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%25 = bitcast [3 x [4 x i32]]* %3 to i32**
%26 = call i32 @sum2d(i32 3, i32 4, i32** %25)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.4, i64 0, i64 0))
%29 = bitcast [2 x [6 x i32]]* %4 to i32**
%30 = call i32 @sum2d(i32 2, i32 6, i32** %29)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.5, i64 0, i64 0))
%33 = bitcast [30 x i32]* %8 to i32**
%34 = call i32 @sum2d(i32 3, i32 10, i32** %33)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %34)
ret i32 0
}