#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 EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int sum_all(int **);
int /*<<< orphan*/ sum_cols(int **);
int /*<<< orphan*/ sum_rows(int **);
int main(void) {
  int tot;
  int mdarr[3][4] = {{1, 3, 5, 7}, {2, 4, 6, 8}, {0, 1, 2, 3}};
  puts("sum each row element");
  sum_rows(mdarr);
  puts("sum each col element");
  sum_cols(mdarr);
  tot = sum_all(mdarr);
  printf("Total rows and cols: %d\n", tot);
  return (EXIT_SUCCESS);
}


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

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movaps 0xec4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xea8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe8c(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <sum_rows@plt>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1060 <sum_cols@plt>
mov    %rbx,%rdi
call   1050 <sum_all@plt>
lea    0xea8(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.mdarr = [3 x [4 x i32]] [[4 x i32] [i32 1, i32 3, i32 5, i32 7], [4 x i32] [i32 2, i32 4, i32 6, i32 8], [4 x i32] [i32 0, i32 1, i32 2, i32 3]]
@.str = [21 x i8] c"sum each row element\00"
@.str.1 = [21 x i8] c"sum each col element\00"
@.str.2 = [25 x i8] c"Total rows and cols: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [3 x [4 x i32]]
store i32 0, i32* %1
%4 = bitcast [3 x [4 x i32]]* %3 to i8*
%5 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %3, i64 0, i64 0
%7 = bitcast [4 x i32]* %6 to i32**
%8 = call i32 @sum_rows(i32** %7)
%9 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %3, i64 0, i64 0
%11 = bitcast [4 x i32]* %10 to i32**
%12 = call i32 @sum_cols(i32** %11)
%13 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %3, i64 0, i64 0
%14 = bitcast [4 x i32]* %13 to i32**
%15 = call i32 @sum_all(i32** %14)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* @EXIT_SUCCESS
ret i32 %18
}

LLVM IR (-O2):
@__const.main.mdarr = [3 x [4 x i32]] [[4 x i32] [i32 1, i32 3, i32 5, i32 7], [4 x i32] [i32 2, i32 4, i32 6, i32 8], [4 x i32] [i32 0, i32 1, i32 2, i32 3]]
@.str = [21 x i8] c"sum each row element\00"
@.str.1 = [21 x i8] c"sum each col element\00"
@.str.2 = [25 x i8] c"Total rows and cols: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [3 x [4 x i32]]
%2 = bitcast [3 x [4 x i32]]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = bitcast [3 x [4 x i32]]* %1 to i32**
%5 = call i32 @sum_rows(i32** %4)
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @sum_cols(i32** %4)
%8 = call i32 @sum_all(i32** %4)
%9 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @EXIT_SUCCESS
ret i32 %10
}