#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);
int sum2d(int **, int);
int /*<<< orphan*/ sum_cols(int **, int);
int /*<<< orphan*/ sum_rows(int **, int);
int main(void) {
  int junk[3][4] = {{2, 4, 6, 8}, {3, 5, 7, 9}, {12, 10, 8, 6}};
  sum_rows(junk, 3);
  sum_cols(junk, 3);
  printf("Sum of all elements = %d\n", sum2d(junk, 3));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x30,%edx
call   1050 <memcpy@plt>
lea    -0x40(%rbp),%rdi
mov    $0x3,%esi
call   1070 <sum_rows@plt>
lea    -0x40(%rbp),%rdi
mov    $0x3,%esi
call   1060 <sum_cols@plt>
lea    -0x40(%rbp),%rdi
mov    $0x3,%esi
call   1030 <sum2d@plt>
mov    %eax,%esi
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movaps 0xed4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeb8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe9c(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3,%esi
call   1060 <sum_rows@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1050 <sum_cols@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1030 <sum2d@plt>
lea    0xe97(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
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]]
@.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]]
store i32 0, i32* %1
%3 = bitcast [3 x [4 x i32]]* %2 to i8*
%4 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %2, i64 0, i64 0
%5 = bitcast [4 x i32]* %4 to i32**
%6 = call i32 @sum_rows(i32** %5, i32 3)
%7 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %2, i64 0, i64 0
%8 = bitcast [4 x i32]* %7 to i32**
%9 = call i32 @sum_cols(i32** %8, i32 3)
%10 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %2, i64 0, i64 0
%11 = bitcast [4 x i32]* %10 to i32**
%12 = call i32 @sum2d(i32** %11, i32 3)
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %12)
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]]
@.str = [26 x i8] c"Sum of all elements = %d\0A\00"
define i32 @main() {
%1 = alloca [3 x [4 x i32]]
%2 = bitcast [3 x [4 x i32]]* %1 to i8*
%3 = bitcast [3 x [4 x i32]]* %1 to i32**
%4 = call i32 @sum_rows(i32** %3, i32 3)
%5 = call i32 @sum_cols(i32** %3, i32 3)
%6 = call i32 @sum2d(i32** %3, i32 3)
%7 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %6)
ret i32 0
}