#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(void) {
  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 emelents = %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)
movl   $0x3,-0x10(%rbp)
movl   $0xa,-0x14(%rbp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
movaps 0xebe(%rip),%xmm0
movaps %xmm0,-0x40(%rbp)
movaps 0xea3(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
movaps 0xee8(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
movaps 0xecd(%rip),%xmm0
movaps %xmm0,-0x70(%rbp)
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,-0x80(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
mov    -0x14(%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,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1241 <main+0x121>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    122e <main+0x10e>
mov    -0xa0(%rbp),%rax
mov    -0xa8(%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    11e6 <main+0xc6>
jmp    1233 <main+0x113>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d3 <main+0xb3>
lea    0xe18(%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    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe0c(%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    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xa0(%rbp),%rdx
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <sum2d@plt>
mov    %eax,%esi
lea    0xdce(%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    0xf04(%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    0xedb(%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    0xebb(%rip),%rdi
call   1040 <puts@plt>
lea    0x60(%rsp),%rdx
mov    $0x3,%edi
mov    $0xa,%esi
call   1030 <sum2d@plt>
lea    0xe6d(%rip),%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"
@.str.4 = [26 x i8] c"Sum of all emelents = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [3 x [4 x i32]]
%7 = alloca [2 x [6 x i32]]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %1
store i32 3, i32* %4
store i32 10, i32* %5
%11 = bitcast [3 x [4 x i32]]* %6 to i8*
%12 = bitcast [2 x [6 x i32]]* %7 to i8*
%13 = load i32, i32* %4
%14 = zext i32 %13 to i64
%15 = load i32, i32* %5
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = mul nuw i64 %14, %16
%19 = alloca i32, i64 %18
store i64 %14, i64* %9
store i64 %16, i64* %10
store i32 0, i32* %2
br label %20
20: ; preds = %46, %0
%21 = load i32, i32* %2
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %49
24: ; preds = %20
store i32 0, i32* %3
br label %25
25: ; preds = %42, %24
%26 = load i32, i32* %3
%27 = load i32, i32* %5
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %45
29: ; preds = %25
%30 = load i32, i32* %2
%31 = load i32, i32* %3
%32 = mul nsw i32 %30, %31
%33 = load i32, i32* %3
%34 = add nsw i32 %32, %33
%35 = load i32, i32* %2
%36 = sext i32 %35 to i64
%37 = mul nsw i64 %36, %16
%38 = getelementptr inbounds i32, i32* %19, i64 %37
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
store i32 %34, i32* %41
br label %42
42: ; preds = %29
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 1
store i32 %44, i32* %3
br label %25
45: ; preds = %25
br label %46
46: ; preds = %45
%47 = load i32, i32* %2
%48 = add nsw i32 %47, 1
store i32 %48, i32* %2
br label %20
49: ; preds = %20
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%51 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %6, i64 0, i64 0
%52 = bitcast [4 x i32]* %51 to i32**
%53 = call i32 @sum2d(i32 3, i32 4, i32** %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%56 = getelementptr inbounds [2 x [6 x i32]], [2 x [6 x i32]]* %7, i64 0, i64 0
%57 = bitcast [6 x i32]* %56 to i32**
%58 = call i32 @sum2d(i32 2, i32 6, i32** %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%61 = load i32, i32* %4
%62 = load i32, i32* %5
%63 = bitcast i32* %19 to i32**
%64 = call i32 @sum2d(i32 %61, i32 %62, i32** %63)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %64)
store i32 0, i32* %1
%66 = load i8*, i8** %8
%67 = load i32, i32* %1
ret i32 %67
}

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