#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*/ dist;

/* Variables and functions */
int /*<<< orphan*/ add(int *, int *, int);
int del(int *, int *);
int get_median(int *, int *, int *, int *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int pri_q[5] = {};
  int min_q[5] = {};
  int max_q[5] = {};
  int dist[5] = {50, 10, 20, 40, 30};
  int cap = 0;
  int min_cap = 0;
  int max_cap = 0;
  for (int i = 0; i < sizeof(dist) / sizeof(int); i++) {
    add(pri_q, &cap, dist[i]);
    printf("\nAdd node %d, root[0] is %d, capacity %d ", dist[i], pri_q[0],
           cap);
  }
  printf("\nPull nodes, note that values are in asending order now\n");
  cap--;
  while (cap >= 0) {
    printf("Pull root node with : value is %d, new capaciity is %d\n",
           del(pri_q, &cap), cap);
  }
  int val = 0;
  for (int i = 0; i < sizeof(dist) / sizeof(int); i++) {
    val = get_median(min_q, &min_cap, max_q, &max_cap, dist[i]);
    printf("\nAdd node %d, min_q[0]=%d,cap=%d, "
           "max_q[0]=%d, cap=%d median %d\n",
           dist[i], min_q[0], min_cap, max_q[0], max_cap, val);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    0xe60(%rip),%rax
mov    %rax,-0x90(%rbp)
mov    0xe5a(%rip),%rax
mov    %rax,-0x88(%rbp)
mov    0xe55(%rip),%eax
mov    %eax,-0x80(%rbp)
movl   $0x0,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
movl   $0x0,-0x9c(%rbp)
movl   $0x0,-0xa0(%rbp)
movslq -0xa0(%rbp),%rax
cmp    $0x5,%rax
jae    124e <main+0xfe>
lea    -0x30(%rbp),%rdi
movslq -0xa0(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%edx
lea    -0x94(%rbp),%rsi
call   1030 <add@plt>
movslq -0xa0(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%esi
mov    -0x30(%rbp),%edx
mov    -0x94(%rbp),%ecx
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xa0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa0(%rbp)
jmp    11e6 <main+0x96>
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x94(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
jl     12a3 <main+0x153>
lea    -0x30(%rbp),%rdi
lea    -0x94(%rbp),%rsi
call   1070 <del@plt>
mov    %eax,%esi
mov    -0x94(%rbp),%edx
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126b <main+0x11b>
movl   $0x0,-0xa4(%rbp)
movl   $0x0,-0xa8(%rbp)
movslq -0xa8(%rbp),%rax
cmp    $0x5,%rax
jae    1345 <main+0x1f5>
lea    -0x50(%rbp),%rdi
lea    -0x70(%rbp),%rdx
movslq -0xa8(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%r8d
ff
lea    -0x98(%rbp),%rsi
lea    -0x9c(%rbp),%rcx
call   1060 <get_median@plt>
mov    %eax,-0xa4(%rbp)
movslq -0xa8(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%esi
mov    -0x50(%rbp),%edx
mov    -0x98(%rbp),%ecx
mov    -0x70(%rbp),%r8d
mov    -0x9c(%rbp),%r9d
mov    -0xa4(%rbp),%eax
lea    0xd88(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xa8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa8(%rbp)
jmp    12b7 <main+0x167>
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movl   $0x0,0x30(%rsp)
movaps %xmm0,0x60(%rsp)
movl   $0x0,0x70(%rsp)
movaps %xmm0,0x40(%rsp)
movl   $0x0,0x50(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x1c(%rsp)
movl   $0x0,0x18(%rsp)
lea    0x20(%rsp),%r15
lea    0x14(%rsp),%r14
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x32,%edx
call   1030 <add@plt>
mov    0x20(%rsp),%edx
mov    0x14(%rsp),%ecx
lea    0xe35(%rip),%rbx
mov    %rbx,%rdi
mov    $0x32,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <add@plt>
mov    0x20(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x14,%edx
call   1030 <add@plt>
mov    0x20(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    %rbx,%rdi
mov    $0x14,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x28,%edx
call   1030 <add@plt>
mov    0x20(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    %rbx,%rdi
mov    $0x28,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x1e,%edx
call   1030 <add@plt>
mov    0x20(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    %rbx,%rdi
mov    $0x1e,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe26(%rip),%rdi
call   1040 <puts@plt>
mov    0x14(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x14(%rsp)
test   %eax,%eax
jle    12d2 <main+0x182>
lea    0x20(%rsp),%r14
lea    0x14(%rsp),%r15
lea    0xd88(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <del@plt>
mov    0x14(%rsp),%edx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0x14(%rsp)
jns    12b0 <main+0x160>
lea    0x60(%rsp),%r13
lea    0x1c(%rsp),%r14
lea    0x40(%rsp),%r15
lea    0x18(%rsp),%r12
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    $0x32,%r8d
call   1060 <get_median@plt>
mov    0x60(%rsp),%edx
mov    0x1c(%rsp),%ecx
mov    0x40(%rsp),%r8d
mov    0x18(%rsp),%r9d
mov    %eax,(%rsp)
lea    0xd49(%rip),%rbx
mov    %rbx,%rdi
mov    $0x32,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    $0xa,%r8d
call   1060 <get_median@plt>
mov    0x60(%rsp),%edx
mov    0x1c(%rsp),%ecx
mov    0x40(%rsp),%r8d
mov    0x18(%rsp),%r9d
mov    %eax,(%rsp)
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    $0x14,%r8d
call   1060 <get_median@plt>
mov    0x60(%rsp),%edx
mov    0x1c(%rsp),%ecx
mov    0x40(%rsp),%r8d
mov    0x18(%rsp),%r9d
mov    %eax,(%rsp)
mov    %rbx,%rdi
mov    $0x14,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    $0x28,%r8d
call   1060 <get_median@plt>
mov    0x60(%rsp),%edx
mov    0x1c(%rsp),%ecx
mov    0x40(%rsp),%r8d
mov    0x18(%rsp),%r9d
mov    %eax,(%rsp)
mov    %rbx,%rdi
mov    $0x28,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    $0x1e,%r8d
call   1060 <get_median@plt>
mov    0x60(%rsp),%edx
mov    0x1c(%rsp),%ecx
mov    0x40(%rsp),%r8d
mov    0x18(%rsp),%r9d
mov    %eax,(%rsp)
mov    %rbx,%rdi
mov    $0x1e,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.dist = [5 x i32] [i32 50, i32 10, i32 20, i32 40, i32 30]
@.str = [42 x i8] c"\0AAdd node %d, root[0] is %d, capacity %d \00"
@.str.1 = [57 x i8] c"\0APull nodes, note that values are in asending order now\0A\00"
@.str.2 = [56 x i8] c"Pull root node with : value is %d, new capaciity is %d\0A\00"
@.str.3 = [65 x i8] c"\0AAdd node %d, min_q[0]=%d,cap=%d, max_q[0]=%d, cap=%d median %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [5 x i32]
%7 = alloca [5 x i32]
%8 = alloca [5 x i32]
%9 = alloca [5 x i32]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = bitcast [5 x i32]* %6 to i8*
%17 = bitcast [5 x i32]* %7 to i8*
%18 = bitcast [5 x i32]* %8 to i8*
%19 = bitcast [5 x i32]* %9 to i8*
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
br label %20
20: ; preds = %39, %2
%21 = load i32, i32* %13
%22 = sext i32 %21 to i64
%23 = icmp ult i64 %22, 5
br i1 %23, label %24, label %42
24: ; preds = %20
%25 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 0
%26 = load i32, i32* %13
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [5 x i32], [5 x i32]* %9, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = call i32 @add(i32* %25, i32* %10, i32 %29)
%31 = load i32, i32* %13
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [5 x i32], [5 x i32]* %9, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 0
%36 = load i32, i32* %35
%37 = load i32, i32* %10
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %34, i32 %36, i32 %37)
br label %39
39: ; preds = %24
%40 = load i32, i32* %13
%41 = add nsw i32 %40, 1
store i32 %41, i32* %13
br label %20
42: ; preds = %20
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
%44 = load i32, i32* %10
%45 = add nsw i32 %44, -1
store i32 %45, i32* %10
br label %46
46: ; preds = %49, %42
%47 = load i32, i32* %10
%48 = icmp sge i32 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %46
%50 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 0
%51 = call i32 @del(i32* %50, i32* %10)
%52 = load i32, i32* %10
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i32 %51, i32 %52)
br label %46
54: ; preds = %46
store i32 0, i32* %14
store i32 0, i32* %15
br label %55
55: ; preds = %79, %54
%56 = load i32, i32* %15
%57 = sext i32 %56 to i64
%58 = icmp ult i64 %57, 5
br i1 %58, label %59, label %82
59: ; preds = %55
%60 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 0
%61 = getelementptr inbounds [5 x i32], [5 x i32]* %8, i64 0, i64 0
%62 = load i32, i32* %15
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [5 x i32], [5 x i32]* %9, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = call i32 @get_median(i32* %60, i32* %11, i32* %61, i32* %12, i32 %65)
store i32 %66, i32* %14
%67 = load i32, i32* %15
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [5 x i32], [5 x i32]* %9, i64 0, i64 %68
%70 = load i32, i32* %69
%71 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 0
%72 = load i32, i32* %71
%73 = load i32, i32* %11
%74 = getelementptr inbounds [5 x i32], [5 x i32]* %8, i64 0, i64 0
%75 = load i32, i32* %74
%76 = load i32, i32* %12
%77 = load i32, i32* %14
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0), i32 %70, i32 %72, i32 %73, i32 %75, i32 %76, i32 %77)
br label %79
79: ; preds = %59
%80 = load i32, i32* %15
%81 = add nsw i32 %80, 1
store i32 %81, i32* %15
br label %55
82: ; preds = %55
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@.str = [42 x i8] c"\0AAdd node %d, root[0] is %d, capacity %d \00"
@.str.2 = [56 x i8] c"Pull root node with : value is %d, new capaciity is %d\0A\00"
@.str.3 = [65 x i8] c"\0AAdd node %d, min_q[0]=%d,cap=%d, max_q[0]=%d, cap=%d median %d\0A\00"
@str = [56 x i8] c"\0APull nodes, note that values are in asending order now\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [5 x i32]
%4 = alloca [5 x i32]
%5 = alloca [5 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = bitcast [5 x i32]* %3 to i8*
%10 = bitcast [5 x i32]* %4 to i8*
%11 = bitcast [5 x i32]* %5 to i8*
%12 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%13 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%14 = bitcast i32* %8 to i8*
store i32 0, i32* %8
%15 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%16 = call i32 @add(i32* %15, i32* %6, i32 50)
%17 = load i32, i32* %15
%18 = load i32, i32* %6
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 50, i32 %17, i32 %18)
%20 = call i32 @add(i32* %15, i32* %6, i32 10)
%21 = load i32, i32* %15
%22 = load i32, i32* %6
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 10, i32 %21, i32 %22)
%24 = call i32 @add(i32* %15, i32* %6, i32 20)
%25 = load i32, i32* %15
%26 = load i32, i32* %6
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 20, i32 %25, i32 %26)
%28 = call i32 @add(i32* %15, i32* %6, i32 40)
%29 = load i32, i32* %15
%30 = load i32, i32* %6
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 40, i32 %29, i32 %30)
%32 = call i32 @add(i32* %15, i32* %6, i32 30)
%33 = load i32, i32* %15
%34 = load i32, i32* %6
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 30, i32 %33, i32 %34)
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%37 = load i32, i32* %6
%38 = add nsw i32 %37, -1
store i32 %38, i32* %6
%39 = icmp sgt i32 %37, 0
br i1 %39, label %73, label %40
40: ; preds = %73, %2
%41 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 0
%42 = getelementptr inbounds [5 x i32], [5 x i32]* %5, i64 0, i64 0
%43 = call i32 @get_median(i32* %41, i32* %7, i32* %42, i32* %8, i32 50)
%44 = load i32, i32* %41
%45 = load i32, i32* %7
%46 = load i32, i32* %42
%47 = load i32, i32* %8
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0), i32 50, i32 %44, i32 %45, i32 %46, i32 %47, i32 %43)
%49 = call i32 @get_median(i32* %41, i32* %7, i32* %42, i32* %8, i32 10)
%50 = load i32, i32* %41
%51 = load i32, i32* %7
%52 = load i32, i32* %42
%53 = load i32, i32* %8
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0), i32 10, i32 %50, i32 %51, i32 %52, i32 %53, i32 %49)
%55 = call i32 @get_median(i32* %41, i32* %7, i32* %42, i32* %8, i32 20)
%56 = load i32, i32* %41
%57 = load i32, i32* %7
%58 = load i32, i32* %42
%59 = load i32, i32* %8
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0), i32 20, i32 %56, i32 %57, i32 %58, i32 %59, i32 %55)
%61 = call i32 @get_median(i32* %41, i32* %7, i32* %42, i32* %8, i32 40)
%62 = load i32, i32* %41
%63 = load i32, i32* %7
%64 = load i32, i32* %42
%65 = load i32, i32* %8
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0), i32 40, i32 %62, i32 %63, i32 %64, i32 %65, i32 %61)
%67 = call i32 @get_median(i32* %41, i32* %7, i32* %42, i32* %8, i32 30)
%68 = load i32, i32* %41
%69 = load i32, i32* %7
%70 = load i32, i32* %42
%71 = load i32, i32* %8
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0), i32 30, i32 %68, i32 %69, i32 %70, i32 %71, i32 %67)
ret i32 0
73: ; preds = %2, %73
%74 = call i32 @del(i32* %15, i32* %6)
%75 = load i32, i32* %6
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i32 %74, i32 %75)
%77 = load i32, i32* %6
%78 = icmp sgt i32 %77, -1
br i1 %78, label %73, label %40
}