#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);
void sum_rows(int arr[][4]) {
  int tot_rows;
  for (int r = 0; r < 3; r++) {
    tot_rows = 0;
    for (int c = 0; c < 4; c++)
      tot_rows += arr[r][c];
    printf("%2d row: %2d total\n", r, tot_rows);
  }
}


x86 assembly (clang, -O0):
<sum_rows>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jge    118f <sum_rows+0x7f>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    116f <sum_rows+0x5f>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113b <sum_rows+0x2b>
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1123 <sum_rows+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_rows>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movdqu (%rdi),%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%edx
lea    0xec8(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
movdqu 0x10(%rbx),%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%edx
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
movdqu 0x20(%rbx),%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%edx
mov    %r14,%rdi
mov    $0x2,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"%2d row: %2d total\0A\00"
define void @sum_rows([4 x i32]* %0) {
%2 = alloca [4 x i32]*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store [4 x i32]* %0, [4 x i32]** %2
store i32 0, i32* %4
br label %6
6: ; preds = %31, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %34
9: ; preds = %6
store i32 0, i32* %3
store i32 0, i32* %5
br label %10
10: ; preds = %24, %9
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %27
13: ; preds = %10
%14 = load [4 x i32]*, [4 x i32]** %2
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %14, i64 %16
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %17, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = load i32, i32* %3
%23 = add nsw i32 %22, %21
store i32 %23, i32* %3
br label %24
24: ; preds = %13
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %10
27: ; preds = %10
%28 = load i32, i32* %4
%29 = load i32, i32* %3
%30 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %29)
br label %31
31: ; preds = %27
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %6
34: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"%2d row: %2d total\0A\00"
define void @sum_rows([4 x i32]* nocapture %0) {
%2 = bitcast [4 x i32]* %0 to <4 x i32>*
%3 = load <4 x i32>, <4 x i32>* %2
%4 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %3)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 0, i32 %4)
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 1, i64 0
%7 = bitcast i32* %6 to <4 x i32>*
%8 = load <4 x i32>, <4 x i32>* %7
%9 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 1, i32 %9)
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 2, i64 0
%12 = bitcast i32* %11 to <4 x i32>*
%13 = load <4 x i32>, <4 x i32>* %12
%14 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %13)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 2, i32 %14)
ret void
}