#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 /*<<< orphan*/ variable_length_array(int, int);
int main() {
  int i, j;
  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 rs = 5, cs = 2;
  variable_length_array(rs, cs);
  int varr[rs][cs];
  for (i = 0; i < rs; i++)
    for (j = 0; j < cs; j++)
      varr[i][j] = i * j + j;
  printf("3 * 5 array\n");
  printf("sum of all elemts = %d\n", sum2d(3, 4, junk));
  printf("2 * 6 array\n");
  printf("sum of all elemts = %d\n", sum2d(3 - 1, 4 + 2, morejunk));
  printf("3 * 10 array\n");
  printf("sum of all elemts = %d\n", sum2d(rs, cs, varr));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movaps 0xed7(%rip),%xmm0
movaps %xmm0,-0x20(%rbp)
movaps 0xebc(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
movaps 0xea1(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
movaps 0xee6(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
movaps 0xecb(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
movaps 0xeb0(%rip),%xmm0
movaps %xmm0,-0x70(%rbp)
movl   $0x5,-0x74(%rbp)
movl   $0x2,-0x78(%rbp)
mov    -0x74(%rbp),%edi
mov    -0x78(%rbp),%esi
call   1040 <variable_length_array@plt>
mov    -0x74(%rbp),%eax
mov    %eax,%ecx
mov    -0x78(%rbp),%eax
mov    %rax,-0xa0(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x80(%rbp)
mov    %rcx,%rdx
imul   %rax,%rdx
lea    0xf(,%rdx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x98(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x88(%rbp)
mov    %rax,-0x90(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x74(%rbp),%eax
jge    1259 <main+0x129>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x78(%rbp),%eax
jge    1246 <main+0x116>
mov    -0x98(%rbp),%rax
mov    -0xa0(%rbp),%rsi
mov    -0x8(%rbp),%edx
imul   -0xc(%rbp),%edx
add    -0xc(%rbp),%edx
movslq -0x8(%rbp),%rcx
imul   %rsi,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11fe <main+0xce>
jmp    124b <main+0x11b>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11eb <main+0xbb>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdx
mov    $0x3,%edi
mov    $0x4,%esi
call   1030 <sum2d@plt>
mov    %eax,%esi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdx
mov    $0x2,%edi
mov    $0x6,%esi
call   1030 <sum2d@plt>
mov    %eax,%esi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x98(%rbp),%rdx
mov    -0x74(%rbp),%edi
mov    -0x78(%rbp),%esi
call   1030 <sum2d@plt>
mov    %eax,%esi
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x80(%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    $0x98,%rsp
movaps 0xeef(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xed0(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xeb4(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xef8(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xedc(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xec0(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
mov    $0x5,%edi
mov    $0x2,%esi
call   1050 <variable_length_array@plt>
mov    %rsp,%r14
movaps 0xe52(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xe57(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x500000000,%rax
mov    %rax,0x20(%rsp)
lea    0xec4(%rip),%rdi
call   1040 <puts@plt>
lea    0x60(%rsp),%rdx
mov    $0x3,%edi
mov    $0x4,%esi
call   1030 <sum2d@plt>
lea    0xe8c(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe9d(%rip),%rdi
call   1040 <puts@plt>
lea    0x30(%rsp),%rdx
mov    $0x2,%edi
mov    $0x6,%esi
call   1030 <sum2d@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe7d(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rdx
mov    $0x5,%edi
mov    $0x2,%esi
call   1030 <sum2d@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rsp
xor    %eax,%eax
add    $0x98,%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 = [13 x i8] c"3 * 5 array\0A\00"
@.str.1 = [24 x i8] c"sum of all elemts = %d\0A\00"
@.str.2 = [13 x i8] c"2 * 6 array\0A\00"
@.str.3 = [14 x i8] c"3 * 10 array\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [3 x [4 x i32]]
%5 = alloca [2 x [6 x i32]]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %1
%11 = bitcast [3 x [4 x i32]]* %4 to i8*
%12 = bitcast [2 x [6 x i32]]* %5 to i8*
store i32 5, i32* %6
store i32 2, i32* %7
%13 = load i32, i32* %6
%14 = load i32, i32* %7
%15 = call i32 @variable_length_array(i32 %13, i32 %14)
%16 = load i32, i32* %6
%17 = zext i32 %16 to i64
%18 = load i32, i32* %7
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %8
%21 = mul nuw i64 %17, %19
%22 = alloca i32, i64 %21
store i64 %17, i64* %9
store i64 %19, i64* %10
store i32 0, i32* %2
br label %23
23: ; preds = %49, %0
%24 = load i32, i32* %2
%25 = load i32, i32* %6
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %52
27: ; preds = %23
store i32 0, i32* %3
br label %28
28: ; preds = %45, %27
%29 = load i32, i32* %3
%30 = load i32, i32* %7
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %48
32: ; preds = %28
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = mul nsw i32 %33, %34
%36 = load i32, i32* %3
%37 = add nsw i32 %35, %36
%38 = load i32, i32* %2
%39 = sext i32 %38 to i64
%40 = mul nsw i64 %39, %19
%41 = getelementptr inbounds i32, i32* %22, i64 %40
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
store i32 %37, i32* %44
br label %45
45: ; preds = %32
%46 = load i32, i32* %3
%47 = add nsw i32 %46, 1
store i32 %47, i32* %3
br label %28
48: ; preds = %28
br label %49
49: ; preds = %48
%50 = load i32, i32* %2
%51 = add nsw i32 %50, 1
store i32 %51, i32* %2
br label %23
52: ; preds = %23
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%54 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %4, i64 0, i64 0
%55 = bitcast [4 x i32]* %54 to i32**
%56 = call i32 @sum2d(i32 3, i32 4, i32** %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%59 = getelementptr inbounds [2 x [6 x i32]], [2 x [6 x i32]]* %5, i64 0, i64 0
%60 = bitcast [6 x i32]* %59 to i32**
%61 = call i32 @sum2d(i32 2, i32 6, i32** %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%64 = load i32, i32* %6
%65 = load i32, i32* %7
%66 = bitcast i32* %22 to i32**
%67 = call i32 @sum2d(i32 %64, i32 %65, i32** %66)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %67)
store i32 0, i32* %1
%69 = load i8*, i8** %8
%70 = load i32, i32* %1
ret i32 %70
}

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 = [24 x i8] c"sum of all elemts = %d\0A\00"
@str = [12 x i8] c"3 * 5 array\00"
@str.4 = [12 x i8] c"2 * 6 array\00"
@str.5 = [13 x i8] c"3 * 10 array\00"
define i32 @main() {
%1 = alloca [3 x [4 x i32]]
%2 = alloca [2 x [6 x i32]]
%3 = bitcast [3 x [4 x i32]]* %1 to i8*
%4 = bitcast [2 x [6 x i32]]* %2 to i8*
%5 = tail call i32 @variable_length_array(i32 5, i32 2)
%6 = tail call i8* @llvm.stacksave()
%7 = alloca [10 x i32]
%8 = bitcast [10 x i32]* %7 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 0, i32 2>, <4 x i32>* %8
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 4
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> <i32 0, i32 3, i32 0, i32 4>, <4 x i32>* %10
%11 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 8
store i32 0, i32* %11
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 9
store i32 5, i32* %12
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%14 = bitcast [3 x [4 x i32]]* %1 to i32**
%15 = call i32 @sum2d(i32 3, i32 4, i32** %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.4, i64 0, i64 0))
%18 = bitcast [2 x [6 x i32]]* %2 to i32**
%19 = call i32 @sum2d(i32 2, i32 6, i32** %18)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.5, i64 0, i64 0))
%22 = bitcast [10 x i32]* %7 to i32**
%23 = call i32 @sum2d(i32 5, i32 2, i32** %22)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %23)
ret i32 0
}