#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; 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)
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    121b <main+0xfb>
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    11d3 <main+0xb3>
lea    0xe3e(%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    0xe26(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe32(%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    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe0c(%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    0xdc5(%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):
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() {
%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 = %37, %0
%21 = load i32, i32* %2
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %40
24: ; preds = %20
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = mul nsw i32 %25, %26
%28 = load i32, i32* %3
%29 = add nsw i32 %27, %28
%30 = load i32, i32* %2
%31 = sext i32 %30 to i64
%32 = mul nsw i64 %31, %16
%33 = getelementptr inbounds i32, i32* %19, i64 %32
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
store i32 %29, i32* %36
br label %37
37: ; preds = %24
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %20
40: ; preds = %20
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%42 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %6, i64 0, i64 0
%43 = bitcast [4 x i32]* %42 to i32**
%44 = call i32 @sum2d(i32 3, i32 4, i32** %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%47 = getelementptr inbounds [2 x [6 x i32]], [2 x [6 x i32]]* %7, i64 0, i64 0
%48 = bitcast [6 x i32]* %47 to i32**
%49 = call i32 @sum2d(i32 2, i32 6, i32** %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%52 = load i32, i32* %4
%53 = load i32, i32* %5
%54 = bitcast i32* %19 to i32**
%55 = call i32 @sum2d(i32 %52, i32 %53, i32** %54)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %55)
store i32 0, i32* %1
%57 = load i8*, i8** %8
%58 = load i32, i32* %1
ret i32 %58
}

LLVM IR (-O2):