#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 **buildMat(int *, int, int);
int **buildTriangularMat(int, int *);
int /*<<< orphan*/ deleteMat(int **, int);
int /*<<< orphan*/ outMat(int **, int, int);
int /*<<< orphan*/ outTriangularMat(int **, int);
void testMat() {
  int size = 4;
  int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
  int **xs = buildMat(elems, size, size);
  outMat(xs, size, size);
  int **ys = buildTriangularMat(size, elems);
  outTriangularMat(ys, size);
  deleteMat(xs, size);
  deleteMat(ys, size);
}


x86 assembly (clang, -O0):
<testMat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x4,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x40,%edx
call   1040 <memcpy@plt>
lea    -0x50(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1070 <buildMat@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1030 <outMat@plt>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1050 <buildTriangularMat@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1080 <outTriangularMat@plt>
mov    -0x58(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1060 <deleteMat@plt>
mov    -0x60(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1060 <deleteMat@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testMat>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
movaps 0xed0(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeb4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe98(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe7c(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x4,%edx
call   1060 <buildMat@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x4,%esi
mov    $0x4,%edx
call   1030 <outMat@plt>
mov    $0x4,%edi
mov    %r14,%rsi
call   1040 <buildTriangularMat@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x4,%esi
call   1070 <outTriangularMat@plt>
mov    %r15,%rdi
mov    $0x4,%esi
call   1050 <deleteMat@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1050 <deleteMat@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.testMat.elems = [16 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16]
define void @testMat() {
%1 = alloca i32
%2 = alloca [16 x i32]
%3 = alloca i32**
%4 = alloca i32**
store i32 4, i32* %1
%5 = bitcast [16 x i32]* %2 to i8*
%6 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%7 = load i32, i32* %1
%8 = load i32, i32* %1
%9 = call i32** @buildMat(i32* %6, i32 %7, i32 %8)
store i32** %9, i32*** %3
%10 = load i32**, i32*** %3
%11 = load i32, i32* %1
%12 = load i32, i32* %1
%13 = call i32 @outMat(i32** %10, i32 %11, i32 %12)
%14 = load i32, i32* %1
%15 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%16 = call i32** @buildTriangularMat(i32 %14, i32* %15)
store i32** %16, i32*** %4
%17 = load i32**, i32*** %4
%18 = load i32, i32* %1
%19 = call i32 @outTriangularMat(i32** %17, i32 %18)
%20 = load i32**, i32*** %3
%21 = load i32, i32* %1
%22 = call i32 @deleteMat(i32** %20, i32 %21)
%23 = load i32**, i32*** %4
%24 = load i32, i32* %1
%25 = call i32 @deleteMat(i32** %23, i32 %24)
ret void
}

LLVM IR (-O2):
@__const.testMat.elems = [16 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16]
define void @testMat() {
%1 = alloca [16 x i32]
%2 = bitcast [16 x i32]* %1 to i8*
%3 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 0
%4 = call i32** @buildMat(i32* %3, i32 4, i32 4)
%5 = call i32 @outMat(i32** %4, i32 4, i32 4)
%6 = call i32** @buildTriangularMat(i32 4, i32* %3)
%7 = call i32 @outTriangularMat(i32** %6, i32 4)
%8 = call i32 @deleteMat(i32** %4, i32 4)
%9 = call i32 @deleteMat(i32** %6, i32 4)
ret void
}