#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 */
size_t mat_to_arr(unsigned int, unsigned int, unsigned int);
long long arr_subdiagonal_sum(int *arr, unsigned int dism,
                              unsigned int length) {
  long long res = 0;
  for (unsigned int i = 1; i <= dism; i++)
    res += arr[mat_to_arr(dism - i + 1, i, dism)];
  return res;
}


x86 assembly (clang, -O0):
<arr_subdiagonal_sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
ja     117a <arr_subdiagonal_sum+0x6a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
sub    -0x1c(%rbp),%edi
add    $0x1,%edi
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <mat_to_arr@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
movslq (%rax,%rcx,4),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1131 <arr_subdiagonal_sum+0x21>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arr_subdiagonal_sum>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
je     1150 <arr_subdiagonal_sum+0x40>
mov    %esi,%r15d
mov    %rdi,%r14
mov    $0x1,%ebp
xor    %r12d,%r12d
mov    %esi,%ebx
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r15d,%edx
call   1030 <mat_to_arr@plt>
movslq (%r14,%rax,4),%rax
add    %rax,%r12
add    $0x1,%ebp
add    $0xffffffff,%ebx
cmp    %r15d,%ebp
jbe    1130 <arr_subdiagonal_sum+0x20>
jmp    1153 <arr_subdiagonal_sum+0x43>
xor    %r12d,%r12d
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @arr_subdiagonal_sum(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i64 0, i64* %7
store i32 1, i32* %8
br label %9
9: ; preds = %27, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %5
%12 = icmp ule i32 %10, %11
br i1 %12, label %13, label %30
13: ; preds = %9
%14 = load i32*, i32** %4
%15 = load i32, i32* %5
%16 = load i32, i32* %8
%17 = sub i32 %15, %16
%18 = add i32 %17, 1
%19 = load i32, i32* %8
%20 = load i32, i32* %5
%21 = call i64 @mat_to_arr(i32 %18, i32 %19, i32 %20)
%22 = getelementptr inbounds i32, i32* %14, i64 %21
%23 = load i32, i32* %22
%24 = sext i32 %23 to i64
%25 = load i64, i64* %7
%26 = add nsw i64 %25, %24
store i64 %26, i64* %7
br label %27
27: ; preds = %13
%28 = load i32, i32* %8
%29 = add i32 %28, 1
store i32 %29, i32* %8
br label %9
30: ; preds = %9
%31 = load i64, i64* %7
ret i64 %31
}

LLVM IR (-O2):
define i64 @arr_subdiagonal_sum(i32* nocapture %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = add i32 %1, 1
br label %9
7: ; preds = %9, %3
%8 = phi i64 [ 0, %3 ], [ %17, %9 ]
ret i64 %8
9: ; preds = %5, %9
%10 = phi i32 [ 1, %5 ], [ %18, %9 ]
%11 = phi i64 [ 0, %5 ], [ %17, %9 ]
%12 = sub i32 %6, %10
%13 = tail call i64 @mat_to_arr(i32 %12, i32 %10, i32 %1)
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = sext i32 %15 to i64
%17 = add nsw i64 %11, %16
%18 = add i32 %10, 1
%19 = icmp ugt i32 %18, %1
br i1 %19, label %7, label %9
}