#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 sum(int *a[]) {
  int i, j;
  int sum = 0;
  for (i = 0; i < 10; i++) {
    for (j = 0; j < 12; j++) {
      sum += a[i][j];
      printf("%4d", a[i][j]);
    }
    printf("\n");
  }
  return sum;
}


x86 assembly (clang, -O0):
<sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    11a9 <sum+0x99>
movl   $0x0,-0x10(%rbp)
cmpl   $0xc,-0x10(%rbp)
jge    118d <sum+0x7d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113b <sum+0x2b>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112a <sum+0x1a>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xecf(%rip),%r14
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15,%rbx,8),%rax
mov    (%rax),%esi
add    %esi,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0x4(%rax),%esi
add    %esi,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0x8(%rax),%esi
add    %esi,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0xc(%rax),%esi
add    %esi,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0x10(%rax),%esi
add    %esi,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0x14(%rax),%esi
add    %esi,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0x18(%rax),%esi
add    %esi,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0x1c(%rax),%esi
add    %esi,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0x20(%rax),%esi
add    %esi,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0x24(%rax),%esi
add    %esi,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0x28(%rax),%esi
add    %esi,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0x2c(%rax),%esi
add    %esi,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    $0xa,%rbx
jne    1140 <sum+0x20>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%4d\00"
define i32 @sum(i32** nocapture %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i64 [ 0, %1 ], [ %66, %2 ]
%4 = phi i32 [ 0, %1 ], [ %63, %2 ]
%5 = getelementptr inbounds i32*, i32** %0, i64 %3
%6 = load i32*, i32** %5
%7 = load i32, i32* %6
%8 = add nsw i32 %7, %4
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
%10 = load i32*, i32** %5
%11 = getelementptr inbounds i32, i32* %10, i64 1
%12 = load i32, i32* %11
%13 = add nsw i32 %12, %8
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
%15 = load i32*, i32** %5
%16 = getelementptr inbounds i32, i32* %15, i64 2
%17 = load i32, i32* %16
%18 = add nsw i32 %17, %13
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
%20 = load i32*, i32** %5
%21 = getelementptr inbounds i32, i32* %20, i64 3
%22 = load i32, i32* %21
%23 = add nsw i32 %22, %18
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %22)
%25 = load i32*, i32** %5
%26 = getelementptr inbounds i32, i32* %25, i64 4
%27 = load i32, i32* %26
%28 = add nsw i32 %27, %23
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %27)
%30 = load i32*, i32** %5
%31 = getelementptr inbounds i32, i32* %30, i64 5
%32 = load i32, i32* %31
%33 = add nsw i32 %32, %28
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %32)
%35 = load i32*, i32** %5
%36 = getelementptr inbounds i32, i32* %35, i64 6
%37 = load i32, i32* %36
%38 = add nsw i32 %37, %33
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %37)
%40 = load i32*, i32** %5
%41 = getelementptr inbounds i32, i32* %40, i64 7
%42 = load i32, i32* %41
%43 = add nsw i32 %42, %38
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %42)
%45 = load i32*, i32** %5
%46 = getelementptr inbounds i32, i32* %45, i64 8
%47 = load i32, i32* %46
%48 = add nsw i32 %47, %43
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %47)
%50 = load i32*, i32** %5
%51 = getelementptr inbounds i32, i32* %50, i64 9
%52 = load i32, i32* %51
%53 = add nsw i32 %52, %48
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %52)
%55 = load i32*, i32** %5
%56 = getelementptr inbounds i32, i32* %55, i64 10
%57 = load i32, i32* %56
%58 = add nsw i32 %57, %53
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %57)
%60 = load i32*, i32** %5
%61 = getelementptr inbounds i32, i32* %60, i64 11
%62 = load i32, i32* %61
%63 = add nsw i32 %62, %58
%64 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %62)
%65 = tail call i32 @putchar(i32 10)
%66 = add nuw nsw i64 %3, 1
%67 = icmp eq i64 %66, 10
br i1 %67, label %68, label %2
68: ; preds = %2
ret i32 %63
}