#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 */
typedef int /*<<< orphan*/ p;

/* Variables and functions */
void *malloc(int);
int /*<<< orphan*/ optimal_bst(float *, float *, int, int **, int **);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  float p[] = {0, 0.15, 0.10, 0.05, 0.10, 0.20};
  float q[] = {0.05, 0.10, 0.05, 0.05, 0.05, 0.10};
  int **e, **root, i, j;
  int n = sizeof(p) / sizeof(int) - 1;
  e = malloc(sizeof(int *) * (n + 1));
  for (i = 0; i <= n + 1; i++)
    e[i] = malloc(sizeof(int) * (n + 1));
  root = malloc(sizeof(int *) * (n + 1));
  for (i = 0; i <= n + 1; i++)
    root[i] = malloc(sizeof(int) * (n + 1));
  optimal_bst(p, q, n, e, root);
  for (i = 0; i < n + 1; i++) {
    printf("\n");
    for (j = 0; j < n + 1; j++)
      printf("%d\t", root[i][j]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb4(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xeb9(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xeb6(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xeb3(%rip),%rax
mov    %rax,-0x30(%rbp)
movl   $0x5,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    -0x5c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jg     11e7 <main+0xb7>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x48(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11a6 <main+0x76>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    -0x5c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jg     1246 <main+0x116>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x50(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1205 <main+0xd5>
lea    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x5c(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%r8
call   1040 <optimal_bst@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    -0x5c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    12de <main+0x1ae>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    -0x5c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    12cb <main+0x19b>
mov    -0x50(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x58(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    128b <main+0x15b>
jmp    12d0 <main+0x1a0>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1265 <main+0x135>
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    0xec0(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xea4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    0xec8(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    $0x30,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,0x8(%r14)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%r14)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,0x18(%r14)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,0x20(%r14)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,0x28(%r14)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,0x30(%r14)
mov    $0x30,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,(%r15)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,0x8(%r15)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%r15)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,0x18(%r15)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,0x20(%r15)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,0x28(%r15)
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,0x30(%r15)
lea    0x20(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x5,%edx
mov    %r14,%rcx
mov    %r15,%r8
call   1050 <optimal_bst@plt>
lea    0xdc5(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%r15,%rbx,8),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0x4(%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0x8(%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0xc(%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0x10(%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%rbx,8),%rax
mov    0x14(%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x6,%rbx
jne    1280 <main+0x140>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.p = [6 x float] [float 0.000000e+00, float 0x3FC3333340000000, float 0x3FB99999A0000000, float 0x3FA99999A0000000, float 0x3FB99999A0000000, float 0x3FC99999A0000000]
@__const.main.q = [6 x float] [float 0x3FA99999A0000000, float 0x3FB99999A0000000, float 0x3FA99999A0000000, float 0x3FA99999A0000000, float 0x3FA99999A0000000, float 0x3FB99999A0000000]
@.str = [2 x i8] c"\0A\00"
@.str.1 = [4 x i8] c"%d\09\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [6 x float]
%3 = alloca [6 x float]
%4 = alloca i32**
%5 = alloca i32**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = bitcast [6 x float]* %2 to i8*
%10 = bitcast [6 x float]* %3 to i8*
store i32 5, i32* %8
%11 = load i32, i32* %8
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = mul i64 8, %13
%15 = trunc i64 %14 to i32
%16 = call i8* @malloc(i32 %15)
%17 = bitcast i8* %16 to i32**
store i32** %17, i32*** %4
store i32 0, i32* %6
br label %18
18: ; preds = %35, %0
%19 = load i32, i32* %6
%20 = load i32, i32* %8
%21 = add nsw i32 %20, 1
%22 = icmp sle i32 %19, %21
br i1 %22, label %23, label %38
23: ; preds = %18
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = mul i64 4, %26
%28 = trunc i64 %27 to i32
%29 = call i8* @malloc(i32 %28)
%30 = bitcast i8* %29 to i32*
%31 = load i32**, i32*** %4
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32*, i32** %31, i64 %33
store i32* %30, i32** %34
br label %35
35: ; preds = %23
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %18
38: ; preds = %18
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = mul i64 8, %41
%43 = trunc i64 %42 to i32
%44 = call i8* @malloc(i32 %43)
%45 = bitcast i8* %44 to i32**
store i32** %45, i32*** %5
store i32 0, i32* %6
br label %46
46: ; preds = %63, %38
%47 = load i32, i32* %6
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
%50 = icmp sle i32 %47, %49
br i1 %50, label %51, label %66
51: ; preds = %46
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = mul i64 4, %54
%56 = trunc i64 %55 to i32
%57 = call i8* @malloc(i32 %56)
%58 = bitcast i8* %57 to i32*
%59 = load i32**, i32*** %5
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32*, i32** %59, i64 %61
store i32* %58, i32** %62
br label %63
63: ; preds = %51
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %46
66: ; preds = %46
%67 = getelementptr inbounds [6 x float], [6 x float]* %2, i64 0, i64 0
%68 = getelementptr inbounds [6 x float], [6 x float]* %3, i64 0, i64 0
%69 = load i32, i32* %8
%70 = load i32**, i32*** %4
%71 = load i32**, i32*** %5
%72 = call i32 @optimal_bst(float* %67, float* %68, i32 %69, i32** %70, i32** %71)
store i32 0, i32* %6
br label %73
73: ; preds = %100, %66
%74 = load i32, i32* %6
%75 = load i32, i32* %8
%76 = add nsw i32 %75, 1
%77 = icmp slt i32 %74, %76
br i1 %77, label %78, label %103
78: ; preds = %73
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %80
80: ; preds = %96, %78
%81 = load i32, i32* %7
%82 = load i32, i32* %8
%83 = add nsw i32 %82, 1
%84 = icmp slt i32 %81, %83
br i1 %84, label %85, label %99
85: ; preds = %80
%86 = load i32**, i32*** %5
%87 = load i32, i32* %6
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i32*, i32** %86, i64 %88
%90 = load i32*, i32** %89
%91 = load i32, i32* %7
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i32, i32* %90, i64 %92
%94 = load i32, i32* %93
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %94)
br label %96
96: ; preds = %85
%97 = load i32, i32* %7
%98 = add nsw i32 %97, 1
store i32 %98, i32* %7
br label %80
99: ; preds = %80
br label %100
100: ; preds = %99
%101 = load i32, i32* %6
%102 = add nsw i32 %101, 1
store i32 %102, i32* %6
br label %73
103: ; preds = %73
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.p = [6 x float] [float 0.000000e+00, float 0x3FC3333340000000, float 0x3FB99999A0000000, float 0x3FA99999A0000000, float 0x3FB99999A0000000, float 0x3FC99999A0000000]
@__const.main.q = [6 x float] [float 0x3FA99999A0000000, float 0x3FB99999A0000000, float 0x3FA99999A0000000, float 0x3FA99999A0000000, float 0x3FA99999A0000000, float 0x3FB99999A0000000]
@.str.1 = [4 x i8] c"%d\09\00"
define i32 @main() {
%1 = alloca [6 x float]
%2 = alloca [6 x float]
%3 = bitcast [6 x float]* %1 to i8*
%4 = bitcast [6 x float]* %2 to i8*
%5 = tail call dereferenceable_or_null(48) i8* @malloc(i32 48)
%6 = bitcast i8* %5 to i32**
%7 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%8 = bitcast i8* %5 to i8**
store i8* %7, i8** %8
%9 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%10 = getelementptr inbounds i32*, i32** %6, i64 1
%11 = bitcast i32** %10 to i8**
store i8* %9, i8** %11
%12 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%13 = getelementptr inbounds i32*, i32** %6, i64 2
%14 = bitcast i32** %13 to i8**
store i8* %12, i8** %14
%15 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%16 = getelementptr inbounds i32*, i32** %6, i64 3
%17 = bitcast i32** %16 to i8**
store i8* %15, i8** %17
%18 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%19 = getelementptr inbounds i32*, i32** %6, i64 4
%20 = bitcast i32** %19 to i8**
store i8* %18, i8** %20
%21 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%22 = getelementptr inbounds i32*, i32** %6, i64 5
%23 = bitcast i32** %22 to i8**
store i8* %21, i8** %23
%24 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%25 = getelementptr inbounds i32*, i32** %6, i64 6
%26 = bitcast i32** %25 to i8**
store i8* %24, i8** %26
%27 = tail call dereferenceable_or_null(48) i8* @malloc(i32 48)
%28 = bitcast i8* %27 to i32**
%29 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%30 = bitcast i8* %27 to i8**
store i8* %29, i8** %30
%31 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%32 = getelementptr inbounds i32*, i32** %28, i64 1
%33 = bitcast i32** %32 to i8**
store i8* %31, i8** %33
%34 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%35 = getelementptr inbounds i32*, i32** %28, i64 2
%36 = bitcast i32** %35 to i8**
store i8* %34, i8** %36
%37 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%38 = getelementptr inbounds i32*, i32** %28, i64 3
%39 = bitcast i32** %38 to i8**
store i8* %37, i8** %39
%40 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%41 = getelementptr inbounds i32*, i32** %28, i64 4
%42 = bitcast i32** %41 to i8**
store i8* %40, i8** %42
%43 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%44 = getelementptr inbounds i32*, i32** %28, i64 5
%45 = bitcast i32** %44 to i8**
store i8* %43, i8** %45
%46 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%47 = getelementptr inbounds i32*, i32** %28, i64 6
%48 = bitcast i32** %47 to i8**
store i8* %46, i8** %48
%49 = getelementptr inbounds [6 x float], [6 x float]* %1, i64 0, i64 0
%50 = getelementptr inbounds [6 x float], [6 x float]* %2, i64 0, i64 0
%51 = call i32 @optimal_bst(float* %49, float* %50, i32 5, i32** %6, i32** %28)
br label %52
52: ; preds = %0, %52
%53 = phi i64 [ 0, %0 ], [ %79, %52 ]
%54 = call i32 @putchar(i32 10)
%55 = getelementptr inbounds i32*, i32** %28, i64 %53
%56 = load i32*, i32** %55
%57 = load i32, i32* %56
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %57)
%59 = load i32*, i32** %55
%60 = getelementptr inbounds i32, i32* %59, i64 1
%61 = load i32, i32* %60
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %61)
%63 = load i32*, i32** %55
%64 = getelementptr inbounds i32, i32* %63, i64 2
%65 = load i32, i32* %64
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %65)
%67 = load i32*, i32** %55
%68 = getelementptr inbounds i32, i32* %67, i64 3
%69 = load i32, i32* %68
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %69)
%71 = load i32*, i32** %55
%72 = getelementptr inbounds i32, i32* %71, i64 4
%73 = load i32, i32* %72
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %73)
%75 = load i32*, i32** %55
%76 = getelementptr inbounds i32, i32* %75, i64 5
%77 = load i32, i32* %76
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %77)
%79 = add nuw nsw i64 %53, 1
%80 = icmp eq i64 %79, 6
br i1 %80, label %81, label %52
81: ; preds = %52
%82 = call i32 @putchar(i32 10)
ret i32 0
}