#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;

/* Variables and functions */
size_t findRank(int *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int a[] = {10, 30, 60, 100, 1, 2, 7, 9, 80, 40, 55, 22, 99};
  int size = sizeof(a) / sizeof(a[0]);
  int rank;
  printf("Try Ranks Below %d\n", size + 1);
  printf("Print 1000 to Quit!!\n");
  scanf("%d", &rank);
  while (rank != 1000) {
    printf("\n The element with rank %d is %d\n", rank,
           a[findRank(a, 0, size - 1, rank)]);
    scanf("%d", &rank);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe9f(%rip),%rsi
mov    $0x34,%edx
call   1050 <memcpy@plt>
movl   $0xd,-0x54(%rbp)
mov    -0x54(%rbp),%esi
add    $0x1,%esi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec3(%rip),%rdi
lea    -0x58(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x3e8,-0x58(%rbp)
je     11f5 <main+0xb5>
mov    -0x58(%rbp),%eax
mov    %eax,-0x5c(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%edx
sub    $0x1,%edx
mov    -0x58(%rbp),%ecx
xor    %esi,%esi
call   1030 <findRank@plt>
mov    -0x5c(%rbp),%esi
mov    -0x50(%rbp,%rax,4),%edx
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe77(%rip),%rdi
lea    -0x58(%rbp),%rsi
call   1060 <scanf@plt>
jmp    11a4 <main+0x64>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    0xece(%rip),%eax
mov    %eax,0x40(%rsp)
movaps 0xeb3(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe97(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe7b(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xea3(%rip),%rdi
mov    $0xe,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xec9(%rip),%rdi
call   1050 <puts@plt>
lea    0xe98(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%ebp
cmp    $0x3e8,%ebp
je     1218 <main+0xc8>
lea    0x10(%rsp),%r14
lea    0xe79(%rip),%r15
lea    0xe6f(%rip),%r12
lea    0xc(%rsp),%rbx
xchg   %ax,%ax
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
mov    %ebp,%ecx
call   1040 <findRank@plt>
mov    0x10(%rsp,%rax,4),%edx
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%ebp
cmp    $0x3e8,%ebp
jne    11e0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
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 = [20 x i8] c"Try Ranks Below %d\0A\00"
@.str.1 = [22 x i8] c"Print 1000 to Quit!!\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [34 x i8] c"\0A The element with rank %d is %d\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [13 x i32]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [13 x i32]* %6 to i8*
store i32 13, i32* %7
%10 = load i32, i32* %7
%11 = add nsw i32 %10, 1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
br label %15
15: ; preds = %18, %2
%16 = load i32, i32* %8
%17 = icmp ne i32 %16, 1000
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = load i32, i32* %8
%20 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 0
%21 = load i32, i32* %7
%22 = sub nsw i32 %21, 1
%23 = load i32, i32* %8
%24 = call i64 @findRank(i32* %20, i32 0, i32 %22, i32 %23)
%25 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %19, i32 %26)
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
br label %15
29: ; preds = %15
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, 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 = [20 x i8] c"Try Ranks Below %d\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [34 x i8] c"\0A The element with rank %d is %d\0A\00"
@str = [21 x i8] c"Print 1000 to Quit!!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [13 x i32]
%4 = alloca i32
%5 = bitcast [13 x i32]* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 14)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1000
br i1 %11, label %23, label %12
12: ; preds = %2
%13 = getelementptr inbounds [13 x i32], [13 x i32]* %3, i64 0, i64 0
br label %14
14: ; preds = %12, %14
%15 = phi i32 [ %10, %12 ], [ %21, %14 ]
%16 = call i64 @findRank(i32* %13, i32 0, i32 12, i32 %15)
%17 = getelementptr inbounds [13 x i32], [13 x i32]* %3, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %15, i32 %18)
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 1000
br i1 %22, label %23, label %14
23: ; preds = %14, %2
%24 = call i32 @putchar(i32 10)
ret i32 0
}