#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*/ build_array_positions(int **);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int sum(int **);
main() {
  int **arrays;
  int i, j;
  arrays = (int **)malloc(10 * sizeof(int *));
  for (i = 0; i < 10; i++)
    arrays[i] = (int *)malloc(12 * sizeof(int));
  for (i = 0; i < 10; i++)
    for (j = 0; j < 12; j++)
      arrays[i][j] = i * j;
  printf("sum = %d\n\n\n", sum(arrays));
  printf("========= check array positions below: ==========\n\n");
  build_array_positions(arrays);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x50,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1195 <main+0x55>
mov    $0x30,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <main+0x24>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11f2 <main+0xb2>
movl   $0x0,-0x18(%rbp)
cmpl   $0xc,-0x18(%rbp)
jge    11df <main+0x9f>
mov    -0x14(%rbp),%edx
imul   -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ad <main+0x6d>
jmp    11e4 <main+0xa4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119c <main+0x5c>
mov    -0x10(%rbp),%rdi
call   1050 <sum@plt>
mov    %eax,%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <build_array_positions@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x50,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    $0x30,%edi
call   1070 <malloc@plt>
mov    %rax,(%rbx)
mov    $0x30,%edi
call   1070 <malloc@plt>
mov    %rax,0x8(%rbx)
mov    $0x30,%edi
call   1070 <malloc@plt>
mov    %rax,0x10(%rbx)
mov    $0x30,%edi
call   1070 <malloc@plt>
mov    %rax,0x18(%rbx)
mov    $0x30,%edi
call   1070 <malloc@plt>
mov    %rax,0x20(%rbx)
mov    $0x30,%edi
call   1070 <malloc@plt>
mov    %rax,0x28(%rbx)
mov    $0x30,%edi
call   1070 <malloc@plt>
mov    %rax,0x30(%rbx)
mov    $0x30,%edi
call   1070 <malloc@plt>
mov    %rax,0x38(%rbx)
mov    $0x30,%edi
call   1070 <malloc@plt>
mov    %rax,0x40(%rbx)
mov    $0x30,%edi
call   1070 <malloc@plt>
mov    %rax,0x48(%rbx)
mov    (%rbx),%rax
xorps  %xmm0,%xmm0
movups %xmm0,0x20(%rax)
movups %xmm0,0x10(%rax)
movups %xmm0,(%rax)
mov    0x8(%rbx),%rax
movaps 0xdfb(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe01(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xe06(%rip),%xmm0
movups %xmm0,0x20(%rax)
mov    0x10(%rbx),%rax
movaps 0xe07(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe0d(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xe12(%rip),%xmm0
movups %xmm0,0x20(%rax)
mov    0x18(%rbx),%rax
movaps 0xe13(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe19(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xe1e(%rip),%xmm0
movups %xmm0,0x20(%rax)
mov    0x20(%rbx),%rax
movaps 0xe1f(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe25(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xe2a(%rip),%xmm0
movups %xmm0,0x20(%rax)
mov    0x28(%rbx),%rax
movaps 0xe2b(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe31(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xe36(%rip),%xmm0
movups %xmm0,0x20(%rax)
mov    0x30(%rbx),%rax
movaps 0xe37(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe3d(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xe42(%rip),%xmm0
movups %xmm0,0x20(%rax)
mov    0x38(%rbx),%rax
movaps 0xe43(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe49(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xe4e(%rip),%xmm0
movups %xmm0,0x20(%rax)
mov    0x40(%rbx),%rax
movaps 0xe4f(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe55(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xe5a(%rip),%xmm0
movups %xmm0,0x20(%rax)
mov    0x48(%rbx),%rax
movaps 0xe5b(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe61(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xe66(%rip),%xmm0
movups %xmm0,0x20(%rax)
mov    %rbx,%rdi
call   1060 <sum@plt>
lea    0xe63(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <build_array_positions@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"sum = %d\0A\0A\0A\00"
@str = [51 x i8] c"========= check array positions below: ==========\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 80)
%2 = inttoptr i64 %1 to i32**
%3 = tail call i64 @malloc(i32 48)
%4 = inttoptr i64 %3 to i32*
store i32* %4, i32** %2
%5 = tail call i64 @malloc(i32 48)
%6 = inttoptr i64 %5 to i32*
%7 = getelementptr inbounds i32*, i32** %2, i64 1
store i32* %6, i32** %7
%8 = tail call i64 @malloc(i32 48)
%9 = inttoptr i64 %8 to i32*
%10 = getelementptr inbounds i32*, i32** %2, i64 2
store i32* %9, i32** %10
%11 = tail call i64 @malloc(i32 48)
%12 = inttoptr i64 %11 to i32*
%13 = getelementptr inbounds i32*, i32** %2, i64 3
store i32* %12, i32** %13
%14 = tail call i64 @malloc(i32 48)
%15 = inttoptr i64 %14 to i32*
%16 = getelementptr inbounds i32*, i32** %2, i64 4
store i32* %15, i32** %16
%17 = tail call i64 @malloc(i32 48)
%18 = inttoptr i64 %17 to i32*
%19 = getelementptr inbounds i32*, i32** %2, i64 5
store i32* %18, i32** %19
%20 = tail call i64 @malloc(i32 48)
%21 = inttoptr i64 %20 to i32*
%22 = getelementptr inbounds i32*, i32** %2, i64 6
store i32* %21, i32** %22
%23 = tail call i64 @malloc(i32 48)
%24 = inttoptr i64 %23 to i32*
%25 = getelementptr inbounds i32*, i32** %2, i64 7
store i32* %24, i32** %25
%26 = tail call i64 @malloc(i32 48)
%27 = inttoptr i64 %26 to i32*
%28 = getelementptr inbounds i32*, i32** %2, i64 8
store i32* %27, i32** %28
%29 = tail call i64 @malloc(i32 48)
%30 = inttoptr i64 %29 to i32*
%31 = getelementptr inbounds i32*, i32** %2, i64 9
store i32* %30, i32** %31
%32 = inttoptr i64 %1 to i8**
%33 = load i8*, i8** %32
%34 = load i32*, i32** %7
%35 = bitcast i32* %34 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %35
%36 = getelementptr inbounds i32, i32* %34, i64 4
%37 = bitcast i32* %36 to <4 x i32>*
store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, <4 x i32>* %37
%38 = getelementptr inbounds i32, i32* %34, i64 8
%39 = bitcast i32* %38 to <4 x i32>*
store <4 x i32> <i32 8, i32 9, i32 10, i32 11>, <4 x i32>* %39
%40 = load i32*, i32** %10
%41 = bitcast i32* %40 to <4 x i32>*
store <4 x i32> <i32 0, i32 2, i32 4, i32 6>, <4 x i32>* %41
%42 = getelementptr inbounds i32, i32* %40, i64 4
%43 = bitcast i32* %42 to <4 x i32>*
store <4 x i32> <i32 8, i32 10, i32 12, i32 14>, <4 x i32>* %43
%44 = getelementptr inbounds i32, i32* %40, i64 8
%45 = bitcast i32* %44 to <4 x i32>*
store <4 x i32> <i32 16, i32 18, i32 20, i32 22>, <4 x i32>* %45
%46 = load i32*, i32** %13
%47 = bitcast i32* %46 to <4 x i32>*
store <4 x i32> <i32 0, i32 3, i32 6, i32 9>, <4 x i32>* %47
%48 = getelementptr inbounds i32, i32* %46, i64 4
%49 = bitcast i32* %48 to <4 x i32>*
store <4 x i32> <i32 12, i32 15, i32 18, i32 21>, <4 x i32>* %49
%50 = getelementptr inbounds i32, i32* %46, i64 8
%51 = bitcast i32* %50 to <4 x i32>*
store <4 x i32> <i32 24, i32 27, i32 30, i32 33>, <4 x i32>* %51
%52 = load i32*, i32** %16
%53 = bitcast i32* %52 to <4 x i32>*
store <4 x i32> <i32 0, i32 4, i32 8, i32 12>, <4 x i32>* %53
%54 = getelementptr inbounds i32, i32* %52, i64 4
%55 = bitcast i32* %54 to <4 x i32>*
store <4 x i32> <i32 16, i32 20, i32 24, i32 28>, <4 x i32>* %55
%56 = getelementptr inbounds i32, i32* %52, i64 8
%57 = bitcast i32* %56 to <4 x i32>*
store <4 x i32> <i32 32, i32 36, i32 40, i32 44>, <4 x i32>* %57
%58 = load i32*, i32** %19
%59 = bitcast i32* %58 to <4 x i32>*
store <4 x i32> <i32 0, i32 5, i32 10, i32 15>, <4 x i32>* %59
%60 = getelementptr inbounds i32, i32* %58, i64 4
%61 = bitcast i32* %60 to <4 x i32>*
store <4 x i32> <i32 20, i32 25, i32 30, i32 35>, <4 x i32>* %61
%62 = getelementptr inbounds i32, i32* %58, i64 8
%63 = bitcast i32* %62 to <4 x i32>*
store <4 x i32> <i32 40, i32 45, i32 50, i32 55>, <4 x i32>* %63
%64 = load i32*, i32** %22
%65 = bitcast i32* %64 to <4 x i32>*
store <4 x i32> <i32 0, i32 6, i32 12, i32 18>, <4 x i32>* %65
%66 = getelementptr inbounds i32, i32* %64, i64 4
%67 = bitcast i32* %66 to <4 x i32>*
store <4 x i32> <i32 24, i32 30, i32 36, i32 42>, <4 x i32>* %67
%68 = getelementptr inbounds i32, i32* %64, i64 8
%69 = bitcast i32* %68 to <4 x i32>*
store <4 x i32> <i32 48, i32 54, i32 60, i32 66>, <4 x i32>* %69
%70 = load i32*, i32** %25
%71 = bitcast i32* %70 to <4 x i32>*
store <4 x i32> <i32 0, i32 7, i32 14, i32 21>, <4 x i32>* %71
%72 = getelementptr inbounds i32, i32* %70, i64 4
%73 = bitcast i32* %72 to <4 x i32>*
store <4 x i32> <i32 28, i32 35, i32 42, i32 49>, <4 x i32>* %73
%74 = getelementptr inbounds i32, i32* %70, i64 8
%75 = bitcast i32* %74 to <4 x i32>*
store <4 x i32> <i32 56, i32 63, i32 70, i32 77>, <4 x i32>* %75
%76 = load i32*, i32** %28
%77 = bitcast i32* %76 to <4 x i32>*
store <4 x i32> <i32 0, i32 8, i32 16, i32 24>, <4 x i32>* %77
%78 = getelementptr inbounds i32, i32* %76, i64 4
%79 = bitcast i32* %78 to <4 x i32>*
store <4 x i32> <i32 32, i32 40, i32 48, i32 56>, <4 x i32>* %79
%80 = getelementptr inbounds i32, i32* %76, i64 8
%81 = bitcast i32* %80 to <4 x i32>*
store <4 x i32> <i32 64, i32 72, i32 80, i32 88>, <4 x i32>* %81
%82 = load i32*, i32** %31
%83 = bitcast i32* %82 to <4 x i32>*
store <4 x i32> <i32 0, i32 9, i32 18, i32 27>, <4 x i32>* %83
%84 = getelementptr inbounds i32, i32* %82, i64 4
%85 = bitcast i32* %84 to <4 x i32>*
store <4 x i32> <i32 36, i32 45, i32 54, i32 63>, <4 x i32>* %85
%86 = getelementptr inbounds i32, i32* %82, i64 8
%87 = bitcast i32* %86 to <4 x i32>*
store <4 x i32> <i32 72, i32 81, i32 90, i32 99>, <4 x i32>* %87
%88 = tail call i32 @sum(i32** %2)
%89 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %88)
%90 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%91 = tail call i32 @build_array_positions(i32** %2)
ret i32 0
}