#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 */
void **upper_triangle_pointer_alloc(void *, long, char, short);
void *vector_alloc(long, char);
void **upper_triangle_all_alloc(long num_rows, char type, short indexing) {
  void *a;
  long ges_laenge;
  ges_laenge = (num_rows + 1) * num_rows;
  ges_laenge = ges_laenge / 2 + indexing;
  a = vector_alloc(ges_laenge, type);
  if (a == NULL)
    return NULL;
  return upper_triangle_pointer_alloc(a, num_rows, type, indexing);
}


x86 assembly (clang, -O0):
<upper_triangle_all_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dx,%ax
mov    %sil,%cl
mov    %rdi,-0x10(%rbp)
mov    %cl,-0x11(%rbp)
mov    %ax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
movswq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <vector_alloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118d <upper_triangle_all_alloc+0x6d>
movq   $0x0,-0x8(%rbp)
jmp    11a8 <upper_triangle_all_alloc+0x88>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x11(%rbp),%al
movsbl %al,%edx
movswl -0x14(%rbp),%ecx
call   1040 <upper_triangle_pointer_alloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upper_triangle_all_alloc>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x1(%rdi),%rax
imul   %rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
add    %rax,%rcx
sar    %rcx
movslq %edx,%rdi
add    %rcx,%rdi
call   1030 <vector_alloc@plt>
test   %rax,%rax
je     1168 <upper_triangle_all_alloc+0x48>
movsbl %bpl,%edx
movswl %r14w,%ecx
mov    %rax,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <upper_triangle_pointer_alloc@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8** @upper_triangle_all_alloc(i64 %0, i8 signext %1, i16 signext %2) {
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i8
%7 = alloca i16
%8 = alloca i8*
%9 = alloca i64
store i64 %0, i64* %5
store i8 %1, i8* %6
store i16 %2, i16* %7
%10 = load i64, i64* %5
%11 = add nsw i64 %10, 1
%12 = load i64, i64* %5
%13 = mul nsw i64 %11, %12
store i64 %13, i64* %9
%14 = load i64, i64* %9
%15 = sdiv i64 %14, 2
%16 = load i16, i16* %7
%17 = sext i16 %16 to i64
%18 = add nsw i64 %15, %17
store i64 %18, i64* %9
%19 = load i64, i64* %9
%20 = load i8, i8* %6
%21 = call i8* @vector_alloc(i64 %19, i8 signext %20)
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %3
store i8** null, i8*** %4
br label %31
25: ; preds = %3
%26 = load i8*, i8** %8
%27 = load i64, i64* %5
%28 = load i8, i8* %6
%29 = load i16, i16* %7
%30 = call i8** @upper_triangle_pointer_alloc(i8* %26, i64 %27, i8 signext %28, i16 signext %29)
store i8** %30, i8*** %4
br label %31
31: ; preds = %25, %24
%32 = load i8**, i8*** %4
ret i8** %32
}

LLVM IR (-O2):
define i8** @upper_triangle_all_alloc(i64 %0, i8 signext %1, i16 signext %2) {
%4 = add nsw i64 %0, 1
%5 = mul nsw i64 %4, %0
%6 = sdiv i64 %5, 2
%7 = sext i16 %2 to i64
%8 = add nsw i64 %6, %7
%9 = tail call i8* @vector_alloc(i64 %8, i8 signext %1)
%10 = icmp eq i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %3
%12 = tail call i8** @upper_triangle_pointer_alloc(i8* %9, i64 %0, i8 signext %1, i16 signext %2)
br label %13
13: ; preds = %3, %11
%14 = phi i8** [ %12, %11 ], [ null, %3 ]
ret i8** %14
}