#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*/ a;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
size_t findRank(int *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int A[1000000], B[100];
  FILE *fp_num, *fp_rank, *fp_out;
  int a[] = {10, 30, 60, 100, 1, 2, 7, 9, 80, 40, 55, 22, 99};
  int size = sizeof(a) / sizeof(a[0]);
  int rank = 10;
  printf("\n The element with rank %d is %d\n", rank,
         a[findRank(a, 0, size - 1, rank)]);
  printf("\n");
  printf("\n\n\n\n\n");
  fp_num = fopen("data.in", "r");
  for (int i = 0; i < 1000000; i++)
    fscanf(fp_num, "%d", &A[i]);
  printf("\n\n\n\n\n");
  fp_rank = fopen("data_rank.in", "r");
  for (int i = 0; i < 100; i++)
    fscanf(fp_rank, "%d", &B[i]);
  fclose(fp_rank);
  fclose(fp_num);
  fp_out = fopen("data_out.in", "w");
  for (int i = 0; i < 100; i++) {
    fprintf(fp_out, "%d\n", A[findRank(A, 0, 1000000 - 1, B[i])]);
  }
  fclose(fp_out);
  printf("\n\n\n\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3d0b10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x3d0af0(%rbp),%rdi
lea    0xe69(%rip),%rsi
mov    $0x34,%edx
call   1080 <memcpy@plt>
movl   $0xd,-0x3d0af4(%rbp)
movl   $0xa,-0x3d0af8(%rbp)
mov    -0x3d0af8(%rbp),%eax
mov    %eax,-0x3d0b08(%rbp)
lea    -0x3d0af0(%rbp),%rdi
mov    -0x3d0af4(%rbp),%edx
sub    $0x1,%edx
mov    -0x3d0af8(%rbp),%ecx
xor    %esi,%esi
call   1030 <findRank@plt>
mov    -0x3d0b08(%rbp),%esi
mov    -0x3d0af0(%rbp,%rax,4),%edx
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe40(%rip),%rdi
lea    0xe41(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x3d0aa8(%rbp)
movl   $0x0,-0x3d0afc(%rbp)
cmpl   $0xf4240,-0x3d0afc(%rbp)
jge    1285 <main+0x115>
mov    -0x3d0aa8(%rbp),%rdi
movslq -0x3d0afc(%rbp),%rax
lea    -0x3d0910(%rbp),%rdx
shl    $0x2,%rax
add    %rax,%rdx
lea    0xdfa(%rip),%rsi
call   1060 <fscanf@plt>
mov    -0x3d0afc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0afc(%rbp)
jmp    1239 <main+0xc9>
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdcf(%rip),%rdi
lea    0xdc3(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x3d0ab0(%rbp)
movl   $0x0,-0x3d0b00(%rbp)
cmpl   $0x64,-0x3d0b00(%rbp)
jge    1300 <main+0x190>
mov    -0x3d0ab0(%rbp),%rdi
movslq -0x3d0b00(%rbp),%rax
lea    -0x3d0aa0(%rbp),%rdx
shl    $0x2,%rax
add    %rax,%rdx
lea    0xd7f(%rip),%rsi
call   1060 <fscanf@plt>
mov    -0x3d0b00(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0b00(%rbp)
jmp    12b7 <main+0x147>
mov    -0x3d0ab0(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x3d0aa8(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd57(%rip),%rdi
lea    0xd5c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x3d0ab8(%rbp)
movl   $0x0,-0x3d0b04(%rbp)
cmpl   $0x64,-0x3d0b04(%rbp)
jge    13a6 <main+0x236>
mov    -0x3d0ab8(%rbp),%rax
mov    %rax,-0x3d0b10(%rbp)
lea    -0x3d0910(%rbp),%rdi
movslq -0x3d0b04(%rbp),%rax
mov    -0x3d0aa0(%rbp,%rax,4),%ecx
xor    %esi,%esi
mov    $0xf423f,%edx
call   1030 <findRank@plt>
mov    -0x3d0b10(%rbp),%rdi
mov    -0x3d0910(%rbp,%rax,4),%edx
lea    0xcc5(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x3d0b04(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3d0b04(%rbp)
jmp    133c <main+0x1cc>
mov    -0x3d0ab8(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xc9d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x3d0b10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3d0ad8,%rsp
mov    0xe9c(%rip),%eax
mov    %eax,0x30(%rsp)
movaps 0xe81(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe65(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe49(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0xc,%edx
mov    $0xa,%ecx
call   1040 <findRank@plt>
mov    (%rsp,%rax,4),%edx
lea    0xe59(%rip),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe86(%rip),%rdi
call   1050 <puts@plt>
lea    0xe52(%rip),%rdi
lea    0xe53(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
lea    0xe46(%rip),%r15
nopw   0x0(%rax,%rax,1)
lea    (%rsp,%rbx,1),%rdx
add    $0x1d0,%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <fscanf@plt>
add    $0x4,%rbx
cmp    $0x3d0900,%rbx
jne    1220 <main+0xa0>
lea    0xe34(%rip),%rdi
call   1050 <puts@plt>
lea    0xe0d(%rip),%rdi
lea    0xe01(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r12
xor    %ebx,%ebx
lea    0xdf2(%rip),%r15
xchg   %ax,%ax
lea    (%rsp,%rbx,1),%rdx
add    $0x40,%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1080 <fscanf@plt>
add    $0x4,%rbx
cmp    $0x190,%rbx
jne    1270 <main+0xf0>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
lea    0xdc9(%rip),%rdi
lea    0xdce(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r12
xor    %ebx,%ebx
lea    0x1d0(%rsp),%r14
lea    0xd8b(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    0x40(%rsp,%rbx,4),%ecx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xf423f,%edx
call   1040 <findRank@plt>
mov    0x1d0(%rsp,%rax,4),%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1090 <fprintf@plt>
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    12d0 <main+0x150>
mov    %r12,%rdi
call   1060 <fclose@plt>
lea    0xd70(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x3d0ad8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.a = [13 x i32] [i32 10, i32 30, i32 60, i32 100, i32 1, i32 2, i32 7, i32 9, i32 80, i32 40, i32 55, i32 22, i32 99]
@.str = [34 x i8] c"\0A The element with rank %d is %d\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [6 x i8] c"\0A\0A\0A\0A\0A\00"
@.str.3 = [8 x i8] c"data.in\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [13 x i8] c"data_rank.in\00"
@.str.7 = [12 x i8] c"data_out.in\00"
@.str.8 = [2 x i8] c"w\00"
@.str.9 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1000000 x i32]
%7 = alloca [100 x i32]
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca [13 x i32]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = bitcast [13 x i32]* %11 to i8*
store i32 13, i32* %12
store i32 10, i32* %13
%18 = load i32, i32* %13
%19 = getelementptr inbounds [13 x i32], [13 x i32]* %11, i64 0, i64 0
%20 = load i32, i32* %12
%21 = sub nsw i32 %20, 1
%22 = load i32, i32* %13
%23 = call i64 @findRank(i32* %19, i32 0, i32 %21, i32 %22)
%24 = getelementptr inbounds [13 x i32], [13 x i32]* %11, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %29, i32** %8
store i32 0, i32* %14
br label %30
30: ; preds = %39, %2
%31 = load i32, i32* %14
%32 = icmp slt i32 %31, 1000000
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = load i32*, i32** %8
%35 = load i32, i32* %14
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %6, i64 0, i64 %36
%38 = call i32 @fscanf(i32* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %37)
br label %39
39: ; preds = %33
%40 = load i32, i32* %14
%41 = add nsw i32 %40, 1
store i32 %41, i32* %14
br label %30
42: ; preds = %30
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %44, i32** %9
store i32 0, i32* %15
br label %45
45: ; preds = %54, %42
%46 = load i32, i32* %15
%47 = icmp slt i32 %46, 100
br i1 %47, label %48, label %57
48: ; preds = %45
%49 = load i32*, i32** %9
%50 = load i32, i32* %15
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [100 x i32], [100 x i32]* %7, i64 0, i64 %51
%53 = call i32 @fscanf(i32* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %52)
br label %54
54: ; preds = %48
%55 = load i32, i32* %15
%56 = add nsw i32 %55, 1
store i32 %56, i32* %15
br label %45
57: ; preds = %45
%58 = load i32*, i32** %9
%59 = call i32 @fclose(i32* %58)
%60 = load i32*, i32** %8
%61 = call i32 @fclose(i32* %60)
%62 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %62, i32** %10
store i32 0, i32* %16
br label %63
63: ; preds = %77, %57
%64 = load i32, i32* %16
%65 = icmp slt i32 %64, 100
br i1 %65, label %66, label %80
66: ; preds = %63
%67 = load i32*, i32** %10
%68 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %6, i64 0, i64 0
%69 = load i32, i32* %16
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [100 x i32], [100 x i32]* %7, i64 0, i64 %70
%72 = load i32, i32* %71
%73 = call i64 @findRank(i32* %68, i32 0, i32 999999, i32 %72)
%74 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %6, i64 0, i64 %73
%75 = load i32, i32* %74
%76 = call i32 @fprintf(i32* %67, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %75)
br label %77
77: ; preds = %66
%78 = load i32, i32* %16
%79 = add nsw i32 %78, 1
store i32 %79, i32* %16
br label %63
80: ; preds = %63
%81 = load i32*, i32** %10
%82 = call i32 @fclose(i32* %81)
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [13 x i32] [i32 10, i32 30, i32 60, i32 100, i32 1, i32 2, i32 7, i32 9, i32 80, i32 40, i32 55, i32 22, i32 99]
@.str = [34 x i8] c"\0A The element with rank %d is %d\0A\00"
@.str.3 = [8 x i8] c"data.in\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [13 x i8] c"data_rank.in\00"
@.str.7 = [12 x i8] c"data_out.in\00"
@.str.8 = [2 x i8] c"w\00"
@.str.9 = [4 x i8] c"%d\0A\00"
@str.11 = [5 x i8] c"\0A\0A\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1000000 x i32]
%4 = alloca [100 x i32]
%5 = alloca [13 x i32]
%6 = bitcast [1000000 x i32]* %3 to i8*
%7 = bitcast [100 x i32]* %4 to i8*
%8 = bitcast [13 x i32]* %5 to i8*
%9 = getelementptr inbounds [13 x i32], [13 x i32]* %5, i64 0, i64 0
%10 = call i64 @findRank(i32* %9, i32 0, i32 12, i32 10)
%11 = getelementptr inbounds [13 x i32], [13 x i32]* %5, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 10, i32 %12)
%14 = call i32 @putchar(i32 10)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.11, i64 0, i64 0))
%16 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %20
17: ; preds = %20
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.11, i64 0, i64 0))
%19 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %31
20: ; preds = %2, %20
%21 = phi i64 [ 0, %2 ], [ %24, %20 ]
%22 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %3, i64 0, i64 %21
%23 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %22)
%24 = add nuw nsw i64 %21, 1
%25 = icmp eq i64 %24, 1000000
br i1 %25, label %17, label %20
26: ; preds = %31
%27 = call i32 @fclose(i32* %19)
%28 = call i32 @fclose(i32* %16)
%29 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%30 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %3, i64 0, i64 0
br label %40
31: ; preds = %17, %31
%32 = phi i64 [ 0, %17 ], [ %35, %31 ]
%33 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %32
%34 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %33)
%35 = add nuw nsw i64 %32, 1
%36 = icmp eq i64 %35, 100
br i1 %36, label %26, label %31
37: ; preds = %40
%38 = call i32 @fclose(i32* %29)
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.11, i64 0, i64 0))
ret i32 0
40: ; preds = %26, %40
%41 = phi i64 [ 0, %26 ], [ %48, %40 ]
%42 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = call i64 @findRank(i32* %30, i32 0, i32 999999, i32 %43)
%45 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %3, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %46)
%48 = add nuw nsw i64 %41, 1
%49 = icmp eq i64 %48, 100
br i1 %49, label %37, label %40
}