#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 FindElement(int *, int /*<<< orphan*/, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int);
int main(void) {
  int n, m, i, rank;
  int *arr;
  int *find;
  scanf("%d", n);
  scanf("%d", m);
  arr = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) {
    scanf("%d", arr[i]);
  }
  while (m > 0) {
    int element = 0;
    scanf("%d", rank);
    element = FindElement(arr, 0, n - 1);
    printf("Element with rank %d = %d \n", element);
    m--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0x8(%rbp),%esi
lea    0xea7(%rip),%rdi
call   1060 <scanf@plt>
mov    -0xc(%rbp),%esi
lea    0xe98(%rip),%rdi
call   1060 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b8 <main+0x78>
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe5b(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1187 <main+0x47>
jmp    11bd <main+0x7d>
cmpl   $0x0,-0xc(%rbp)
jle    120e <main+0xce>
movl   $0x0,-0x2c(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe28(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <FindElement@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xe08(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11bd <main+0x7d>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xed8(%rip),%rbx
mov    %rbx,%rdi
call   1040 <scanf@plt>
mov    %rbx,%rdi
call   1040 <scanf@plt>
xor    %edi,%edi
call   1030 <malloc@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 undef)
%2 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 undef)
%3 = tail call i64 @malloc(i32 0)
ret i32 0
}