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


x86 assembly (clang, -O0):
<sum_cols>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    118f <sum_cols+0x7f>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    116f <sum_cols+0x5f>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x10(%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_cols+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_cols+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_cols>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x10(%rdi),%edx
add    (%rdi),%edx
add    0x20(%rdi),%edx
lea    0xeda(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    0x14(%rbx),%edx
add    0x4(%rbx),%edx
add    0x24(%rbx),%edx
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    0x18(%rbx),%edx
add    0x8(%rbx),%edx
add    0x28(%rbx),%edx
mov    %r14,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    0x1c(%rbx),%edx
add    0xc(%rbx),%edx
add    0x2c(%rbx),%edx
mov    %r14,%rdi
mov    $0x3,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

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