#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 *calloc(size_t, int);
int getBell(int *, int, int);
int /*<<< orphan*/ setBell(int *, int, int, int);
int *bellTriangle(int n) {
  size_t length = n * (n + 1) / 2;
  int *tri = calloc(length, sizeof(int));
  int i, j;
  setBell(tri, 1, 0, 1);
  for (i = 2; i <= n; ++i) {
    setBell(tri, i, 0, getBell(tri, i - 1, i - 2));
    for (j = 1; j < i; ++j) {
      int value = getBell(tri, i, j - 1) + getBell(tri, i - 1, j - 1);
      setBell(tri, i, j, value);
    }
  }
  return tri;
}


x86 assembly (clang, -O0):
<bellTriangle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1,%ecx
xor    %edx,%edx
mov    %ecx,%esi
call   1030 <setBell@plt>
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1239 <bellTriangle+0x109>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
mov    -0x1c(%rbp),%edx
sub    $0x2,%edx
call   1050 <getBell@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    %eax,%ecx
xor    %edx,%edx
call   1030 <setBell@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1226 <bellTriangle+0xf6>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
sub    $0x1,%edx
call   1050 <getBell@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
mov    -0x20(%rbp),%edx
sub    $0x1,%edx
call   1050 <getBell@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
call   1030 <setBell@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c6 <bellTriangle+0x96>
jmp    122b <bellTriangle+0xfb>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1180 <bellTriangle+0x50>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bellTriangle>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    0x1(%rbx),%eax
imul   %edi,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rdi
mov    $0x4,%esi
call   1040 <calloc@plt>
mov    %rax,%r13
mov    $0x1,%r12d
mov    %rax,%rdi
mov    $0x1,%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1030 <setBell@plt>
mov    %rbx,0x10(%rsp)
cmp    $0x2,%ebx
jl     120d <bellTriangle+0xdd>
mov    $0x2,%r15d
nopl   (%rax)
lea    -0x1(%r15),%esi
lea    -0x2(%r15),%edx
mov    %r13,%rdi
mov    %esi,0xc(%rsp)
call   1050 <getBell@plt>
xor    %ebp,%ebp
mov    %r13,%rdi
mov    %r15d,%esi
xor    %edx,%edx
mov    %eax,%ecx
call   1030 <setBell@plt>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%rbp),%ebx
mov    %r13,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1050 <getBell@plt>
mov    %eax,%r14d
mov    %r13,%rdi
mov    0xc(%rsp),%esi
mov    %ebp,%edx
call   1050 <getBell@plt>
add    %eax,%r14d
mov    %r13,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %r14d,%ecx
call   1030 <setBell@plt>
mov    %ebx,%ebp
cmp    %ebx,%r12d
jne    11c0 <bellTriangle+0x90>
lea    0x1(%r15),%eax
add    $0x1,%r12d
cmp    0x10(%rsp),%r15d
mov    %eax,%r15d
jne    1190 <bellTriangle+0x60>
mov    %r13,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @bellTriangle(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
%8 = load i32, i32* %2
%9 = load i32, i32* %2
%10 = add nsw i32 %9, 1
%11 = mul nsw i32 %8, %10
%12 = sdiv i32 %11, 2
%13 = sext i32 %12 to i64
store i64 %13, i64* %3
%14 = load i64, i64* %3
%15 = call i32* @calloc(i64 %14, i32 4)
store i32* %15, i32** %4
%16 = load i32*, i32** %4
%17 = call i32 @setBell(i32* %16, i32 1, i32 0, i32 1)
store i32 2, i32* %5
br label %18
18: ; preds = %58, %1
%19 = load i32, i32* %5
%20 = load i32, i32* %2
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %61
22: ; preds = %18
%23 = load i32*, i32** %4
%24 = load i32, i32* %5
%25 = load i32*, i32** %4
%26 = load i32, i32* %5
%27 = sub nsw i32 %26, 1
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 2
%30 = call i32 @getBell(i32* %25, i32 %27, i32 %29)
%31 = call i32 @setBell(i32* %23, i32 %24, i32 0, i32 %30)
store i32 1, i32* %6
br label %32
32: ; preds = %54, %22
%33 = load i32, i32* %6
%34 = load i32, i32* %5
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %57
36: ; preds = %32
%37 = load i32*, i32** %4
%38 = load i32, i32* %5
%39 = load i32, i32* %6
%40 = sub nsw i32 %39, 1
%41 = call i32 @getBell(i32* %37, i32 %38, i32 %40)
%42 = load i32*, i32** %4
%43 = load i32, i32* %5
%44 = sub nsw i32 %43, 1
%45 = load i32, i32* %6
%46 = sub nsw i32 %45, 1
%47 = call i32 @getBell(i32* %42, i32 %44, i32 %46)
%48 = add nsw i32 %41, %47
store i32 %48, i32* %7
%49 = load i32*, i32** %4
%50 = load i32, i32* %5
%51 = load i32, i32* %6
%52 = load i32, i32* %7
%53 = call i32 @setBell(i32* %49, i32 %50, i32 %51, i32 %52)
br label %54
54: ; preds = %36
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %32
57: ; preds = %32
br label %58
58: ; preds = %57
%59 = load i32, i32* %5
%60 = add nsw i32 %59, 1
store i32 %60, i32* %5
br label %18
61: ; preds = %18
%62 = load i32*, i32** %4
ret i32* %62
}

LLVM IR (-O2):
define i32* @bellTriangle(i32 %0) {
%2 = add i32 %0, 1
%3 = mul nsw i32 %2, %0
%4 = sdiv i32 %3, 2
%5 = sext i32 %4 to i64
%6 = tail call i32* @calloc(i64 %5, i32 4)
%7 = tail call i32 @setBell(i32* %6, i32 1, i32 0, i32 1)
%8 = icmp slt i32 %0, 2
br i1 %8, label %27, label %9
9: ; preds = %1, %24
%10 = phi i32 [ %25, %24 ], [ 2, %1 ]
%11 = add nsw i32 %10, -1
%12 = add nsw i32 %10, -2
%13 = tail call i32 @getBell(i32* %6, i32 %11, i32 %12)
%14 = tail call i32 @setBell(i32* %6, i32 %10, i32 0, i32 %13)
br label %15
15: ; preds = %9, %15
%16 = phi i32 [ 1, %9 ], [ %22, %15 ]
%17 = add nsw i32 %16, -1
%18 = tail call i32 @getBell(i32* %6, i32 %10, i32 %17)
%19 = tail call i32 @getBell(i32* %6, i32 %11, i32 %17)
%20 = add nsw i32 %19, %18
%21 = tail call i32 @setBell(i32* %6, i32 %10, i32 %16, i32 %20)
%22 = add nuw nsw i32 %16, 1
%23 = icmp eq i32 %22, %10
br i1 %23, label %24, label %15
24: ; preds = %15
%25 = add nuw i32 %10, 1
%26 = icmp eq i32 %10, %0
br i1 %26, label %27, label %9
27: ; preds = %24, %1
ret i32* %6
}