#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 */
scalar_t__ malloc(int);
int minimumTotal(int **, int, int *);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  int triangleColSizes[] = {1, 2, 3, 4};
  int **triangle = (int **)malloc(sizeof(int *) * 4);
  for (int i = 0; i < 4; i++) {
    triangle[i] = (int *)malloc(sizeof(int) * triangleColSizes[i]);
  }
  triangle[0][0] = 2;
  triangle[1][0] = 3;
  triangle[1][1] = 4;
  triangle[2][0] = 6;
  triangle[2][1] = 5;
  triangle[2][2] = 7;
  triangle[3][0] = 4;
  triangle[3][1] = 1;
  triangle[3][2] = 8;
  triangle[3][3] = 3;
  printf("%d\n", minimumTotal(triangle, 4, triangleColSizes));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x20,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x4,-0x2c(%rbp)
jge    11a5 <main+0x75>
movslq -0x2c(%rbp),%rax
movslq -0x20(%rbp,%rax,4),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    116a <main+0x3a>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movl   $0x2,(%rax)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
movl   $0x3,(%rax)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
movl   $0x4,0x4(%rax)
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
movl   $0x6,(%rax)
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
movl   $0x5,0x4(%rax)
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
movl   $0x7,0x8(%rax)
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rax
movl   $0x4,(%rax)
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rax
movl   $0x1,0x4(%rax)
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rax
movl   $0x8,0x8(%rax)
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rax
movl   $0x3,0xc(%rax)
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rdx
mov    $0x4,%esi
call   1040 <minimumTotal@plt>
mov    %eax,%esi
lea    0xdbf(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movaps 0xed4(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    $0x20,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,(%rbx)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rbx)
mov    $0xc,%edi
call   1050 <malloc@plt>
mov    %rax,0x10(%rbx)
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,0x18(%rbx)
mov    (%rbx),%rcx
movl   $0x2,(%rcx)
mov    0x8(%rbx),%rcx
movabs $0x400000003,%rdx
mov    %rdx,(%rcx)
mov    0x10(%rbx),%rcx
movabs $0x500000006,%rdx
mov    %rdx,(%rcx)
movl   $0x7,0x8(%rcx)
movaps 0xe43(%rip),%xmm0
movups %xmm0,(%rax)
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1040 <minimumTotal@plt>
lea    0xe49(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.triangleColSizes = [4 x i32] [i32 1, i32 2, i32 3, i32 4]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i32]
%3 = alloca i32**
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [4 x i32]* %2 to i8*
%6 = call i64 @malloc(i32 32)
%7 = inttoptr i64 %6 to i32**
store i32** %7, i32*** %3
store i32 0, i32* %4
br label %8
8: ; preds = %25, %0
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = sext i32 %15 to i64
%17 = mul i64 4, %16
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i32*
%21 = load i32**, i32*** %3
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32*, i32** %21, i64 %23
store i32* %20, i32** %24
br label %25
25: ; preds = %11
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %8
28: ; preds = %8
%29 = load i32**, i32*** %3
%30 = getelementptr inbounds i32*, i32** %29, i64 0
%31 = load i32*, i32** %30
%32 = getelementptr inbounds i32, i32* %31, i64 0
store i32 2, i32* %32
%33 = load i32**, i32*** %3
%34 = getelementptr inbounds i32*, i32** %33, i64 1
%35 = load i32*, i32** %34
%36 = getelementptr inbounds i32, i32* %35, i64 0
store i32 3, i32* %36
%37 = load i32**, i32*** %3
%38 = getelementptr inbounds i32*, i32** %37, i64 1
%39 = load i32*, i32** %38
%40 = getelementptr inbounds i32, i32* %39, i64 1
store i32 4, i32* %40
%41 = load i32**, i32*** %3
%42 = getelementptr inbounds i32*, i32** %41, i64 2
%43 = load i32*, i32** %42
%44 = getelementptr inbounds i32, i32* %43, i64 0
store i32 6, i32* %44
%45 = load i32**, i32*** %3
%46 = getelementptr inbounds i32*, i32** %45, i64 2
%47 = load i32*, i32** %46
%48 = getelementptr inbounds i32, i32* %47, i64 1
store i32 5, i32* %48
%49 = load i32**, i32*** %3
%50 = getelementptr inbounds i32*, i32** %49, i64 2
%51 = load i32*, i32** %50
%52 = getelementptr inbounds i32, i32* %51, i64 2
store i32 7, i32* %52
%53 = load i32**, i32*** %3
%54 = getelementptr inbounds i32*, i32** %53, i64 3
%55 = load i32*, i32** %54
%56 = getelementptr inbounds i32, i32* %55, i64 0
store i32 4, i32* %56
%57 = load i32**, i32*** %3
%58 = getelementptr inbounds i32*, i32** %57, i64 3
%59 = load i32*, i32** %58
%60 = getelementptr inbounds i32, i32* %59, i64 1
store i32 1, i32* %60
%61 = load i32**, i32*** %3
%62 = getelementptr inbounds i32*, i32** %61, i64 3
%63 = load i32*, i32** %62
%64 = getelementptr inbounds i32, i32* %63, i64 2
store i32 8, i32* %64
%65 = load i32**, i32*** %3
%66 = getelementptr inbounds i32*, i32** %65, i64 3
%67 = load i32*, i32** %66
%68 = getelementptr inbounds i32, i32* %67, i64 3
store i32 3, i32* %68
%69 = load i32**, i32*** %3
%70 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%71 = call i32 @minimumTotal(i32** %69, i32 4, i32* %70)
%72 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %71)
ret i32 0
}

LLVM IR (-O2):
@__const.main.triangleColSizes = [4 x i32] [i32 1, i32 2, i32 3, i32 4]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [4 x i32]
%2 = bitcast [4 x i32]* %1 to i8*
%3 = tail call i64 @malloc(i32 32)
%4 = inttoptr i64 %3 to i32**
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
%6 = tail call i64 @malloc(i32 4)
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %4
%8 = tail call i64 @malloc(i32 8)
%9 = inttoptr i64 %8 to i32*
%10 = getelementptr inbounds i32*, i32** %4, i64 1
store i32* %9, i32** %10
%11 = tail call i64 @malloc(i32 12)
%12 = inttoptr i64 %11 to i32*
%13 = getelementptr inbounds i32*, i32** %4, i64 2
store i32* %12, i32** %13
%14 = tail call i64 @malloc(i32 16)
%15 = inttoptr i64 %14 to i32*
%16 = getelementptr inbounds i32*, i32** %4, i64 3
store i32* %15, i32** %16
%17 = load i32*, i32** %4
store i32 2, i32* %17
%18 = load i32*, i32** %10
store i32 3, i32* %18
%19 = getelementptr inbounds i32, i32* %18, i64 1
store i32 4, i32* %19
%20 = load i32*, i32** %13
store i32 6, i32* %20
%21 = getelementptr inbounds i32, i32* %20, i64 1
store i32 5, i32* %21
%22 = getelementptr inbounds i32, i32* %20, i64 2
store i32 7, i32* %22
%23 = inttoptr i64 %14 to <4 x i32>*
store <4 x i32> <i32 4, i32 1, i32 8, i32 3>, <4 x i32>* %23
%24 = call i32 @minimumTotal(i32** %4, i32 4, i32* %5)
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %24)
ret i32 0
}