#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 */
struct Node {
  int dummy;
};

/* Variables and functions */
int **CreateMatrix(int);
struct Node *CreateTree(int /*<<< orphan*/, int, int **, int *, int *);
int /*<<< orphan*/ LoadFile(char *, int *, int *, int *);
int /*<<< orphan*/ PrintMatrix(int **, int, char *);
int /*<<< orphan*/ PrintTree(struct Node *);
int /*<<< orphan*/ QuickSorting(int *, int *, int);
int /*<<< orphan*/ SaveTree(struct Node *, char *);
int /*<<< orphan*/ SeekOptimalBinTree(int **, int **, int **, int *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int a[1000];
  int p[1000];
  int n;
  LoadFile("input.txt", a, p, &n);
  QuickSorting(a, p, n);
  int size = 1000 + 1;
  int **c = CreateMatrix(size);
  int **w = CreateMatrix(size);
  int **r = CreateMatrix(size);
  SeekOptimalBinTree(c, w, r, p, n);
  struct Node *root = CreateTree(0, n, r, a, p);
  for (int i = 0; i < n; i++) {
    printf("%3d ", a[i]);
  }
  printf("\n");
  for (int i = 0; i < n; i++) {
    printf("%3d ", p[i]);
  }
  PrintMatrix(c, n, "Cost");
  PrintMatrix(w, n, "Weight");
  PrintMatrix(r, n, "Root");
  PrintTree(root);
  SaveTree(root, "output.txt");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xfb0(%rbp),%rsi
lea    -0x1f50(%rbp),%rdx
lea    0xe49(%rip),%rdi
lea    -0x1f54(%rbp),%rcx
call   10a0 <LoadFile@plt>
lea    -0xfb0(%rbp),%rdi
lea    -0x1f50(%rbp),%rsi
mov    -0x1f54(%rbp),%edx
call   1090 <QuickSorting@plt>
movl   $0x3e9,-0x1f58(%rbp)
mov    -0x1f58(%rbp),%edi
call   1060 <CreateMatrix@plt>
mov    %rax,-0x1f60(%rbp)
mov    -0x1f58(%rbp),%edi
call   1060 <CreateMatrix@plt>
mov    %rax,-0x1f68(%rbp)
mov    -0x1f58(%rbp),%edi
call   1060 <CreateMatrix@plt>
mov    %rax,-0x1f70(%rbp)
mov    -0x1f60(%rbp),%rdi
mov    -0x1f68(%rbp),%rsi
mov    -0x1f70(%rbp),%rdx
lea    -0x1f50(%rbp),%rcx
mov    -0x1f54(%rbp),%r8d
call   1070 <SeekOptimalBinTree@plt>
mov    -0x1f54(%rbp),%esi
mov    -0x1f70(%rbp),%rdx
lea    -0xfb0(%rbp),%rcx
lea    -0x1f50(%rbp),%r8
xor    %edi,%edi
call   1080 <CreateTree@plt>
mov    %rax,-0x1f78(%rbp)
movl   $0x0,-0x1f7c(%rbp)
mov    -0x1f7c(%rbp),%eax
cmp    -0x1f54(%rbp),%eax
jge    12b9 <main+0x129>
movslq -0x1f7c(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%esi
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1f7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f7c(%rbp)
jmp    1277 <main+0xe7>
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1f80(%rbp)
mov    -0x1f80(%rbp),%eax
cmp    -0x1f54(%rbp),%eax
jge    1313 <main+0x183>
movslq -0x1f80(%rbp),%rax
mov    -0x1f50(%rbp,%rax,4),%esi
lea    0xd12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1f80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f80(%rbp)
jmp    12d1 <main+0x141>
mov    -0x1f60(%rbp),%rdi
mov    -0x1f54(%rbp),%esi
lea    0xcea(%rip),%rdx
call   1030 <PrintMatrix@plt>
mov    -0x1f68(%rbp),%rdi
mov    -0x1f54(%rbp),%esi
lea    0xcd6(%rip),%rdx
call   1030 <PrintMatrix@plt>
mov    -0x1f70(%rbp),%rdi
mov    -0x1f54(%rbp),%esi
lea    0xcc4(%rip),%rdx
call   1030 <PrintMatrix@plt>
mov    -0x1f78(%rbp),%rdi
call   1040 <PrintTree@plt>
mov    -0x1f78(%rbp),%rdi
lea    0xcaa(%rip),%rsi
call   10b0 <SaveTree@plt>
xor    %eax,%eax
add    $0x1f80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f58,%rsp
lea    0xe48(%rip),%rdi
lea    0xfb0(%rsp),%r12
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%rcx
mov    %r12,%rsi
mov    %rbx,%rdx
call   10b0 <LoadFile@plt>
mov    0xc(%rsp),%edx
mov    %r12,%rdi
mov    %rbx,%rsi
call   10a0 <QuickSorting@plt>
mov    $0x3e9,%edi
call   1070 <CreateMatrix@plt>
mov    %rax,%r15
mov    $0x3e9,%edi
call   1070 <CreateMatrix@plt>
mov    %rax,%r14
mov    $0x3e9,%edi
call   1070 <CreateMatrix@plt>
mov    %rax,%r13
mov    0xc(%rsp),%r8d
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1080 <SeekOptimalBinTree@plt>
mov    0xc(%rsp),%esi
xor    %edi,%edi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %rbx,%r8
call   1090 <CreateTree@plt>
mov    %rax,%r12
cmpl   $0x0,0xc(%rsp)
jle    126f <main+0xcf>
lea    0xdc4(%rip),%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    0xfb0(%rsp,%rbp,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jl     1250 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    12ac <main+0x10c>
lea    0xd82(%rip),%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbp,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rsi
cmp    %rsi,%rbp
jl     1290 <main+0xf0>
lea    0xd5c(%rip),%rdx
mov    %r15,%rdi
call   1040 <PrintMatrix@plt>
mov    0xc(%rsp),%esi
lea    0xd4e(%rip),%rdx
mov    %r14,%rdi
call   1040 <PrintMatrix@plt>
mov    0xc(%rsp),%esi
lea    0xd42(%rip),%rdx
mov    %r13,%rdi
call   1040 <PrintMatrix@plt>
mov    %r12,%rdi
call   1050 <PrintTree@plt>
lea    0xd30(%rip),%rsi
mov    %r12,%rdi
call   10c0 <SaveTree@plt>
xor    %eax,%eax
add    $0x1f58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.Node = type { i32 }
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [5 x i8] c"%3d \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [5 x i8] c"Cost\00"
@.str.4 = [7 x i8] c"Weight\00"
@.str.5 = [5 x i8] c"Root\00"
@.str.6 = [11 x i8] c"output.txt\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i32]
%3 = alloca [1000 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i32**
%8 = alloca i32**
%9 = alloca %struct.Node*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
%12 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 0
%13 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%14 = call i32 @LoadFile(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %12, i32* %13, i32* %4)
%15 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 0
%16 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%17 = load i32, i32* %4
%18 = call i32 @QuickSorting(i32* %15, i32* %16, i32 %17)
store i32 1001, i32* %5
%19 = load i32, i32* %5
%20 = call i32** @CreateMatrix(i32 %19)
store i32** %20, i32*** %6
%21 = load i32, i32* %5
%22 = call i32** @CreateMatrix(i32 %21)
store i32** %22, i32*** %7
%23 = load i32, i32* %5
%24 = call i32** @CreateMatrix(i32 %23)
store i32** %24, i32*** %8
%25 = load i32**, i32*** %6
%26 = load i32**, i32*** %7
%27 = load i32**, i32*** %8
%28 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%29 = load i32, i32* %4
%30 = call i32 @SeekOptimalBinTree(i32** %25, i32** %26, i32** %27, i32* %28, i32 %29)
%31 = load i32, i32* %4
%32 = load i32**, i32*** %8
%33 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 0
%34 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%35 = call %struct.Node* @CreateTree(i32 0, i32 %31, i32** %32, i32* %33, i32* %34)
store %struct.Node* %35, %struct.Node** %9
store i32 0, i32* %10
br label %36
36: ; preds = %46, %0
%37 = load i32, i32* %10
%38 = load i32, i32* %4
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %49
40: ; preds = %36
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %40
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
br label %36
49: ; preds = %36
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %11
br label %51
51: ; preds = %61, %49
%52 = load i32, i32* %11
%53 = load i32, i32* %4
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %64
55: ; preds = %51
%56 = load i32, i32* %11
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %55
%62 = load i32, i32* %11
%63 = add nsw i32 %62, 1
store i32 %63, i32* %11
br label %51
64: ; preds = %51
%65 = load i32**, i32*** %6
%66 = load i32, i32* %4
%67 = call i32 @PrintMatrix(i32** %65, i32 %66, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%68 = load i32**, i32*** %7
%69 = load i32, i32* %4
%70 = call i32 @PrintMatrix(i32** %68, i32 %69, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%71 = load i32**, i32*** %8
%72 = load i32, i32* %4
%73 = call i32 @PrintMatrix(i32** %71, i32 %72, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%74 = load %struct.Node*, %struct.Node** %9
%75 = call i32 @PrintTree(%struct.Node* %74)
%76 = load %struct.Node*, %struct.Node** %9
%77 = call i32 @SaveTree(%struct.Node* %76, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.Node = type { i32 }
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [5 x i8] c"%3d \00"
@.str.3 = [5 x i8] c"Cost\00"
@.str.4 = [7 x i8] c"Weight\00"
@.str.5 = [5 x i8] c"Root\00"
@.str.6 = [11 x i8] c"output.txt\00"
define i32 @main() {
%1 = alloca [1000 x i32]
%2 = alloca [1000 x i32]
%3 = alloca i32
%4 = bitcast [1000 x i32]* %1 to i8*
%5 = bitcast [1000 x i32]* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 0
%8 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 0
%9 = call i32 @LoadFile(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %7, i32* %8, i32* %3)
%10 = load i32, i32* %3
%11 = call i32 @QuickSorting(i32* %7, i32* %8, i32 %10)
%12 = call i32** @CreateMatrix(i32 1001)
%13 = call i32** @CreateMatrix(i32 1001)
%14 = call i32** @CreateMatrix(i32 1001)
%15 = load i32, i32* %3
%16 = call i32 @SeekOptimalBinTree(i32** %12, i32** %13, i32** %14, i32* %8, i32 %15)
%17 = load i32, i32* %3
%18 = call %struct.Node* @CreateTree(i32 0, i32 %17, i32** %14, i32* %7, i32* %8)
%19 = load i32, i32* %3
%20 = icmp sgt i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %25, %0
%22 = call i32 @putchar(i32 10)
%23 = load i32, i32* %3
%24 = icmp sgt i32 %23, 0
br i1 %24, label %43, label %34
25: ; preds = %0, %25
%26 = phi i64 [ %30, %25 ], [ 0, %0 ]
%27 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = add nuw nsw i64 %26, 1
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %30, %32
br i1 %33, label %25, label %21
34: ; preds = %43, %21
%35 = phi i32 [ %23, %21 ], [ %49, %43 ]
%36 = call i32 @PrintMatrix(i32** %12, i32 %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* %3
%38 = call i32 @PrintMatrix(i32** %13, i32 %37, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32, i32* %3
%40 = call i32 @PrintMatrix(i32** %14, i32 %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%41 = call i32 @PrintTree(%struct.Node* %18)
%42 = call i32 @SaveTree(%struct.Node* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
43: ; preds = %21, %43
%44 = phi i64 [ %48, %43 ], [ 0, %21 ]
%45 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = add nuw nsw i64 %44, 1
%49 = load i32, i32* %3
%50 = sext i32 %49 to i64
%51 = icmp slt i64 %48, %50
br i1 %51, label %43, label %34
}