#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 /*<<< orphan*/ build_MAX_heap(int *, int, int);
int /*<<< orphan*/ change(int *, int, int, int, int);
int /*<<< orphan*/ check_MAX_heap(int *, int, int);
int extract_MAX(int *, int *, int);
char getchar();
int /*<<< orphan*/ heapSort(int *, int, int);
int /*<<< orphan*/ insert(int *, int *, int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ print(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  char ch = ' ';
  int *arr, n, k, i, new;
  scanf("%d", &k);
  scanf("%d", &n);
  arr = (int *)malloc(2 * n * sizeof(int));
  for (i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  if (!check_MAX_heap(arr, n, k))
    build_MAX_heap(arr, n, k);
  print(arr, n);
  do {
    while (getchar() != '\n')
      ;
    ch = getchar();
    switch (ch) {
    case 'i':
      scanf("%d", &new);
      insert(arr, &n, k, new);
      print(arr, n);
      n++;
      break;
    case 'd':
      printf("%d", extract_MAX(arr, &n, k));
      print(arr, n);
      n--;
      break;
    case 'c':
      scanf("%d", &i);
      scanf("%d", &new);
      change(arr, n, k, i, new);
      print(arr, n);
      break;
    case 's':
      printf("sorting array\n");
      heapSort(arr, n, k);
      print(arr, n);
    }
  } while (ch != 'q');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x20,-0x5(%rbp)
lea    0xe7a(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   10b0 <scanf@plt>
lea    0xe6a(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   10b0 <scanf@plt>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1236 <main+0x86>
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe21(%rip),%rdi
call   10b0 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1201 <main+0x51>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <check_MAX_heap@plt>
cmp    $0x0,%eax
jne    125d <main+0xad>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   10d0 <build_MAX_heap@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <print@plt>
jmp    126e <main+0xbe>
mov    $0x0,%al
call   1090 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1286 <main+0xd6>
jmp    126e <main+0xbe>
xor    %eax,%eax
call   1090 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x10,%eax
ja     13a1 <main+0x1f1>
mov    -0x28(%rbp),%rax
lea    0xd4f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xd83(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   10b0 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    -0x14(%rbp),%rsi
call   10c0 <insert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <print@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    13a1 <main+0x1f1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    -0x14(%rbp),%rsi
call   1070 <extract_MAX@plt>
mov    %eax,%esi
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <print@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    13a1 <main+0x1f1>
lea    0xd0c(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   10b0 <scanf@plt>
lea    0xcfc(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   10b0 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
call   1040 <change@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <print@plt>
jmp    13a1 <main+0x1f1>
lea    0xcc8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <heapSort@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <print@plt>
jmp    13a6 <main+0x1f6>
movsbl -0x5(%rbp),%eax
cmp    $0x71,%eax
jne    1269 <main+0xb9>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe6f(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   10c0 <scanf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   10c0 <scanf@plt>
mov    0x8(%rsp),%edi
shl    $0x3,%edi
call   10b0 <malloc@plt>
mov    %rax,%r12
movl   $0x0,0x10(%rsp)
mov    0x8(%rsp),%esi
test   %esi,%esi
jle    1240 <main+0x80>
mov    $0x1,%ebp
lea    0xe2a(%rip),%r14
mov    %r12,%rbx
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   10c0 <scanf@plt>
mov    %ebp,0x10(%rsp)
mov    0x8(%rsp),%esi
add    $0x4,%rbx
lea    0x1(%rbp),%eax
cmp    %esi,%ebp
mov    %eax,%ebp
jl     1220 <main+0x60>
mov    0xc(%rsp),%edx
mov    %r12,%rdi
call   1030 <check_MAX_heap@plt>
test   %eax,%eax
jne    1260 <main+0xa0>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %r12,%rdi
call   10e0 <build_MAX_heap@plt>
mov    0x8(%rsp),%esi
mov    %r12,%rdi
call   1090 <print@plt>
lea    0xd8d(%rip),%rbp
lea    0xdca(%rip),%r14
lea    0x14(%rsp),%rbx
lea    0x8(%rsp),%r13
jmp    12b8 <main+0xf8>
lea    0xdba(%rip),%rdi
call   1050 <puts@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %r12,%rdi
call   1060 <heapSort@plt>
mov    0x8(%rsp),%esi
mov    %r12,%rdi
call   1090 <print@plt>
cmp    $0x71,%r15b
je     137a <main+0x1ba>
xor    %eax,%eax
call   10a0 <getchar@plt>
cmp    $0xa,%al
jne    12b8 <main+0xf8>
xor    %eax,%eax
call   10a0 <getchar@plt>
mov    %eax,%r15d
movsbl %al,%eax
add    $0xffffff9d,%eax
cmp    $0x10,%eax
ja     12ae <main+0xee>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
mov    %r14,%rdi
lea    0x10(%rsp),%rsi
call   10c0 <scanf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10c0 <scanf@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    %r12,%rdi
call   1040 <change@plt>
jmp    12a2 <main+0xe2>
mov    0xc(%rsp),%edx
mov    %r12,%rdi
mov    %r13,%rsi
call   1080 <extract_MAX@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%rsp),%esi
mov    %r12,%rdi
call   1090 <print@plt>
addl   $0xffffffff,0x8(%rsp)
jmp    12ae <main+0xee>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10c0 <scanf@plt>
mov    0xc(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    %r12,%rdi
mov    %r13,%rsi
call   10d0 <insert@plt>
mov    0x8(%rsp),%esi
mov    %r12,%rdi
call   1090 <print@plt>
addl   $0x1,0x8(%rsp)
jmp    12ae <main+0xee>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@str = [14 x i8] c"sorting array\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%11 = load i32, i32* %1
%12 = shl i32 %11, 3
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
store i32 0, i32* %3
%15 = load i32, i32* %1
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %0, %17
%18 = phi i32 [ %22, %17 ], [ 0, %0 ]
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %14, i64 %19
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %20)
%22 = add nuw nsw i32 %18, 1
store i32 %22, i32* %3
%23 = load i32, i32* %1
%24 = icmp slt i32 %22, %23
br i1 %24, label %17, label %25
25: ; preds = %17, %0
%26 = phi i32 [ %15, %0 ], [ %23, %17 ]
%27 = load i32, i32* %2
%28 = call i32 @check_MAX_heap(i32* %14, i32 %26, i32 %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i32, i32* %1
%32 = load i32, i32* %2
%33 = call i32 @build_MAX_heap(i32* %14, i32 %31, i32 %32)
br label %34
34: ; preds = %30, %25
%35 = load i32, i32* %1
%36 = call i32 @print(i32* %14, i32 %35)
br label %37
37: ; preds = %40, %34
%38 = call signext i8 (...) @getchar()
%39 = icmp eq i8 %38, 10
br i1 %39, label %41, label %40
40: ; preds = %37, %78
br label %37
41: ; preds = %37
%42 = call signext i8 (...) @getchar()
%43 = sext i8 %42 to i32
switch i32 %43, label %78 [
i32 105, label %44
i32 100, label %53
i32 99, label %61
i32 115, label %71
]
44: ; preds = %41
%45 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%46 = load i32, i32* %2
%47 = load i32, i32* %4
%48 = call i32 @insert(i32* %14, i32* %1, i32 %46, i32 %47)
%49 = load i32, i32* %1
%50 = call i32 @print(i32* %14, i32 %49)
%51 = load i32, i32* %1
%52 = add nsw i32 %51, 1
store i32 %52, i32* %1
br label %78
53: ; preds = %41
%54 = load i32, i32* %2
%55 = call i32 @extract_MAX(i32* %14, i32* %1, i32 %54)
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %55)
%57 = load i32, i32* %1
%58 = call i32 @print(i32* %14, i32 %57)
%59 = load i32, i32* %1
%60 = add nsw i32 %59, -1
store i32 %60, i32* %1
br label %78
61: ; preds = %41
%62 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%63 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%64 = load i32, i32* %1
%65 = load i32, i32* %2
%66 = load i32, i32* %3
%67 = load i32, i32* %4
%68 = call i32 @change(i32* %14, i32 %64, i32 %65, i32 %66, i32 %67)
%69 = load i32, i32* %1
%70 = call i32 @print(i32* %14, i32 %69)
br label %78
71: ; preds = %41
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%73 = load i32, i32* %1
%74 = load i32, i32* %2
%75 = call i32 @heapSort(i32* %14, i32 %73, i32 %74)
%76 = load i32, i32* %1
%77 = call i32 @print(i32* %14, i32 %76)
br label %78
78: ; preds = %44, %53, %61, %41, %71
%79 = icmp eq i8 %42, 113
br i1 %79, label %80, label %40
80: ; preds = %78
ret i32 0
}