#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*/ print_array(int *, int);
int /*<<< orphan*/ rank(int *, int, int *, int);
int /*<<< orphan*/ rearrange(int *, int, int *, int);
int main(void) {
  int a[20] = {321321, 32, 43, 43, 54, 65, 76, 3123, 43, 1, 0, 0, 1321};
  int r[20] = {0};
  print_array(a, 20);
  rank(a, 20, r, 20);
  print_array(r, 20);
  rearrange(a, 20, r, 20);
  print_array(a, 20);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe93(%rip),%rsi
mov    $0x50,%edx
call   1070 <memcpy@plt>
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
lea    -0x60(%rbp),%rdi
mov    $0x14,%esi
call   1040 <print_array@plt>
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rdx
mov    $0x14,%ecx
mov    %ecx,%esi
call   1030 <rank@plt>
lea    -0xb0(%rbp),%rdi
mov    $0x14,%esi
call   1040 <print_array@plt>
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rdx
mov    $0x14,%ecx
mov    %ecx,%esi
call   1060 <rearrange@plt>
lea    -0x60(%rbp),%rdi
mov    $0x14,%esi
call   1040 <print_array@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xa8,%rsp
movaps 0xeff(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xee0(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xec1(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xea5(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe89(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0x50(%rsp),%r14
mov    %r14,%rdi
mov    $0x14,%esi
call   1040 <print_array@plt>
mov    %rsp,%rbx
mov    %r14,%rdi
mov    $0x14,%esi
mov    %rbx,%rdx
mov    $0x14,%ecx
call   1030 <rank@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
call   1040 <print_array@plt>
mov    %r14,%rdi
mov    $0x14,%esi
mov    %rbx,%rdx
mov    $0x14,%ecx
call   1050 <rearrange@plt>
mov    %r14,%rdi
mov    $0x14,%esi
call   1040 <print_array@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.a = [20 x i32] [i32 321321, i32 32, i32 43, i32 43, i32 54, i32 65, i32 76, i32 3123, i32 43, i32 1, i32 0, i32 0, i32 1321, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0]
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i32]
%3 = alloca [20 x i32]
store i32 0, i32* %1
%4 = bitcast [20 x i32]* %2 to i8*
%5 = bitcast [20 x i32]* %3 to i8*
%6 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%7 = call i32 @print_array(i32* %6, i32 20)
%8 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%9 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%10 = call i32 @rank(i32* %8, i32 20, i32* %9, i32 20)
%11 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%12 = call i32 @print_array(i32* %11, i32 20)
%13 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%14 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%15 = call i32 @rearrange(i32* %13, i32 20, i32* %14, i32 20)
%16 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%17 = call i32 @print_array(i32* %16, i32 20)
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [20 x i32] [i32 321321, i32 32, i32 43, i32 43, i32 54, i32 65, i32 76, i32 3123, i32 43, i32 1, i32 0, i32 0, i32 1321, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0]
define i32 @main() {
%1 = alloca [20 x i32]
%2 = alloca [20 x i32]
%3 = bitcast [20 x i32]* %1 to i8*
%4 = bitcast [20 x i32]* %2 to i8*
%5 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%6 = call i32 @print_array(i32* %5, i32 20)
%7 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%8 = call i32 @rank(i32* %5, i32 20, i32* %7, i32 20)
%9 = call i32 @print_array(i32* %7, i32 20)
%10 = call i32 @rearrange(i32* %5, i32 20, i32* %7, i32 20)
%11 = call i32 @print_array(i32* %5, i32 20)
ret i32 0
}