#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 add_ut(int **, int);
int **buildMat(int *, int, int);
int /*<<< orphan*/ deleteMat(int **, int);
int /*<<< orphan*/ printf(char *, int);
void test_add_ut() {
  int r = 3;
  int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  int **xs = buildMat(elems, r, r);
  printf("sum of upper triangle is %d\n", add_ut(xs, r));
  deleteMat(xs, r);
}


x86 assembly (clang, -O0):
<test_add_ut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x3,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x24,%edx
call   1050 <memcpy@plt>
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1070 <buildMat@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1040 <add_ut@plt>
mov    %eax,%esi
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1060 <deleteMat@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_add_ut>:
push   %rbx
sub    $0x30,%rsp
mov    0xed5(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xeba(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe9e(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x3,%esi
mov    $0x3,%edx
call   1060 <buildMat@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x3,%esi
call   1040 <add_ut@plt>
lea    0xe95(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1050 <deleteMat@plt>
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_add_ut.elems = [9 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9]
@.str = [29 x i8] c"sum of upper triangle is %d\0A\00"
define void @test_add_ut() {
%1 = alloca i32
%2 = alloca [9 x i32]
%3 = alloca i32**
store i32 3, i32* %1
%4 = bitcast [9 x i32]* %2 to i8*
%5 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
%6 = load i32, i32* %1
%7 = load i32, i32* %1
%8 = call i32** @buildMat(i32* %5, i32 %6, i32 %7)
store i32** %8, i32*** %3
%9 = load i32**, i32*** %3
%10 = load i32, i32* %1
%11 = call i32 @add_ut(i32** %9, i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32**, i32*** %3
%14 = load i32, i32* %1
%15 = call i32 @deleteMat(i32** %13, i32 %14)
ret void
}

LLVM IR (-O2):
@__const.test_add_ut.elems = [9 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9]
@.str = [29 x i8] c"sum of upper triangle is %d\0A\00"
define void @test_add_ut() {
%1 = alloca [9 x i32]
%2 = bitcast [9 x i32]* %1 to i8*
%3 = getelementptr inbounds [9 x i32], [9 x i32]* %1, i64 0, i64 0
%4 = call i32** @buildMat(i32* %3, i32 3, i32 3)
%5 = call i32 @add_ut(i32** %4, i32 3)
%6 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 @deleteMat(i32** %4, i32 3)
ret void
}