#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 ar[][4], int rows) {
  int r, c, tot;
  for (r = 0; r < rows; r++) {
    tot = 0;
    for (c = 0; c < 4; c++)
      tot += ar[r][c];
    printf("row %d: sum = %d\n", r, tot);
  }
}


x86 assembly (clang, -O0):
<sum_rows>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1194 <sum_rows+0x84>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    1174 <sum_rows+0x64>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1140 <sum_rows+0x30>
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <sum_rows+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_rows>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1162 <sum_rows+0x52>
mov    %rdi,%r14
mov    %esi,%r12d
xor    %ebx,%ebx
lea    0xed5(%rip),%r15
nopl   0x0(%rax,%rax,1)
movdqu (%r14),%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%edx
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%rbx
add    $0x10,%r14
cmp    %rbx,%r12
jne    1130 <sum_rows+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [18 x i8] c"row %d: sum = %d\0A\00"
define void @sum_rows([4 x i32]* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %16
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %14, %6 ]
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 %7, i64 0
%9 = bitcast i32* %8 to <4 x i32>*
%10 = load <4 x i32>, <4 x i32>* %9
%11 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %10)
%12 = trunc i64 %7 to i32
%13 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %11)
%14 = add nuw nsw i64 %7, 1
%15 = icmp eq i64 %14, %5
br i1 %15, label %16, label %6
16: ; preds = %6, %2
ret void
}