#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*/ free(long *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, long);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ sort(long *, long *);
int main(int argc, char *argv[]) {
  long *a;
  int N, M, i;
  scanf("%d", &N);
  a = (long *)malloc(N * sizeof(long));
  for (i = 0; i < N; i++)
    scanf("%li", &a[i]);
  scanf("%d", &M);
  sort(a, a + N);
  for (i = 0; i < M; i++)
    printf("%li\n", a[N - i - 1]);
  free(a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c9 <main+0x79>
mov    -0x18(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1192 <main+0x42>
lea    0xe30(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1050 <sort@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1234 <main+0xe4>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xde6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11fa <main+0xaa>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xea2(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    (%rsp),%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
cmpl   $0x0,(%rsp)
jle    11ae <main+0x5e>
lea    0xe80(%rip),%r14
mov    %r15,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
add    $0x1,%rbp
movslq (%rsp),%rax
add    $0x8,%rbx
cmp    %rax,%rbp
jl     1190 <main+0x40>
lea    0xe4b(%rip),%rdi
xor    %ebx,%ebx
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
movslq (%rsp),%rax
lea    (%r15,%rax,8),%rsi
mov    %r15,%rdi
call   1050 <sort@plt>
cmpl   $0x0,0x4(%rsp)
jle    120f <main+0xbf>
mov    $0xffffffff,%ebp
lea    0xe21(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp),%eax
add    %ebp,%eax
cltq
mov    (%r15,%rax,8),%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%ebx
add    $0xffffffff,%ebp
cmp    0x4(%rsp),%ebx
jl     11f0 <main+0xa0>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%li\00"
@.str.2 = [5 x i8] c"%li\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = shl i32 %8, 3
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i64*
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %2, %14
%15 = phi i64 [ %18, %14 ], [ 0, %2 ]
%16 = getelementptr inbounds i64, i64* %11, i64 %15
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %16)
%18 = add nuw nsw i64 %15, 1
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %14, label %22
22: ; preds = %14, %2
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i64, i64* %11, i64 %25
%27 = call i32 @sort(i64* %11, i64* %26)
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %42
30: ; preds = %22, %30
%31 = phi i32 [ %39, %30 ], [ 0, %22 ]
%32 = load i32, i32* %3
%33 = xor i32 %31, -1
%34 = add i32 %32, %33
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i64, i64* %11, i64 %35
%37 = load i64, i64* %36
%38 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %37)
%39 = add nuw nsw i32 %31, 1
%40 = load i32, i32* %4
%41 = icmp slt i32 %39, %40
br i1 %41, label %30, label %42
42: ; preds = %30, %22
%43 = call i32 @free(i64* %11)
ret i32 0
}