#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 */
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int a[100000], r;
  srand(time(NULL));
  for (int z = 0; z < 100000; z++) {
    r = rand();
    a[z] = r;
  }
  int length = sizeof(a) / sizeof(int);
  if (0) {
    int i, j, count;
    int *temp = malloc(length * sizeof(int));
    for (i = 0; i < length; i++) {
      count = 0;
      for (j = 0; j < length; j++) {
        if (a[j] < a[i])
          count++;
        else if (a[j] == a[i] && j < i)
          count++;
      }
      temp[count] = a[i];
    }
    memcpy(a, temp, length * sizeof(int));
    free(temp);
  } else {
    int *temp = malloc(length * sizeof(int));
#pragma omp parallel for shared(a, length, temp)
    for (int i = 0; i < length; i++) {
      int count = 0;
      for (int j = 0; j < length; j++) {
        if (a[j] < a[i])
          count++;
        else if (a[j] == a[i] && j < i)
          count++;
      }
      temp[count] = a[i];
    }
    memcpy(a, temp, length * sizeof(int));
    free(temp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61ac0,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x61a98(%rbp)
cmpl   $0x186a0,-0x61a98(%rbp)
jge    11d1 <main+0x71>
mov    $0x0,%al
call   1080 <rand@plt>
mov    %eax,-0x61a94(%rbp)
mov    -0x61a94(%rbp),%ecx
movslq -0x61a98(%rbp),%rax
mov    %ecx,-0x61a90(%rbp,%rax,4)
mov    -0x61a98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61a98(%rbp)
jmp    118c <main+0x2c>
movl   $0x186a0,-0x61a9c(%rbp)
movslq -0x61a9c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x61aa8(%rbp)
movl   $0x0,-0x61aac(%rbp)
mov    -0x61aac(%rbp),%eax
cmp    -0x61a9c(%rbp),%eax
jge    1300 <main+0x1a0>
movl   $0x0,-0x61ab0(%rbp)
movl   $0x0,-0x61ab4(%rbp)
mov    -0x61ab4(%rbp),%eax
cmp    -0x61a9c(%rbp),%eax
jge    12cd <main+0x16d>
movslq -0x61ab4(%rbp),%rax
mov    -0x61a90(%rbp,%rax,4),%eax
movslq -0x61aac(%rbp),%rcx
cmp    -0x61a90(%rbp,%rcx,4),%eax
jge    126c <main+0x10c>
mov    -0x61ab0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61ab0(%rbp)
jmp    12b4 <main+0x154>
movslq -0x61ab4(%rbp),%rax
mov    -0x61a90(%rbp,%rax,4),%eax
movslq -0x61aac(%rbp),%rcx
cmp    -0x61a90(%rbp,%rcx,4),%eax
jne    12af <main+0x14f>
mov    -0x61ab4(%rbp),%eax
cmp    -0x61aac(%rbp),%eax
jge    12af <main+0x14f>
mov    -0x61ab0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61ab0(%rbp)
jmp    12b4 <main+0x154>
jmp    12b9 <main+0x159>
mov    -0x61ab4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61ab4(%rbp)
jmp    1224 <main+0xc4>
movslq -0x61aac(%rbp),%rax
mov    -0x61a90(%rbp,%rax,4),%edx
mov    -0x61aa8(%rbp),%rax
movslq -0x61ab0(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x61aac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61aac(%rbp)
jmp    11fe <main+0x9e>
lea    -0x61a90(%rbp),%rdi
mov    -0x61aa8(%rbp),%rsi
movslq -0x61a9c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x61aa8(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x61ac0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x61a80,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <rand@plt>
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x186a0,%rbx
jne    1180 <main+0x20>
mov    $0x61a80,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
movdqa 0xe61(%rip),%xmm9
movdqa 0xe68(%rip),%xmm10
movdqa 0xe6f(%rip),%xmm14
movdqa 0xe76(%rip),%xmm11
movdqa 0xe7d(%rip),%xmm12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rsp,%rax,4),%ecx
movd   %ecx,%xmm0
pshufd $0x0,%xmm0,%xmm15
movq   %rax,%xmm0
pshufd $0x44,%xmm0,%xmm13
pxor   %xmm7,%xmm7
mov    $0x4,%edx
movdqa %xmm9,%xmm5
movdqa 0xdf2(%rip),%xmm4
pxor   %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movdqa %xmm5,%xmm2
pxor   %xmm14,%xmm2
movdqa %xmm13,%xmm3
pxor   %xmm14,%xmm3
movdqa %xmm3,%xmm0
pcmpgtd %xmm2,%xmm0
pshufd $0xa0,%xmm0,%xmm6
pcmpeqd %xmm3,%xmm2
pshufd $0xf5,%xmm2,%xmm2
pand   %xmm6,%xmm2
pshufd $0xf5,%xmm0,%xmm0
por    %xmm2,%xmm0
movdqa %xmm4,%xmm2
pxor   %xmm14,%xmm2
movdqa %xmm3,%xmm6
pcmpgtd %xmm2,%xmm6
pshufd $0xa0,%xmm6,%xmm8
pcmpeqd %xmm3,%xmm2
pshufd $0xf5,%xmm2,%xmm2
pand   %xmm8,%xmm2
pshufd $0xf5,%xmm6,%xmm6
por    %xmm2,%xmm6
movdqa -0x10(%rsp,%rdx,4),%xmm2
packssdw %xmm6,%xmm0
movdqa %xmm15,%xmm6
pcmpgtd %xmm2,%xmm6
pcmpeqd %xmm15,%xmm2
pand   %xmm2,%xmm0
movdqa %xmm6,%xmm2
pandn  %xmm0,%xmm2
movdqa %xmm5,%xmm0
paddq  %xmm10,%xmm0
pand   %xmm11,%xmm2
psubd  %xmm6,%xmm2
paddd  %xmm2,%xmm7
pxor   %xmm14,%xmm0
movdqa %xmm3,%xmm2
pcmpgtd %xmm0,%xmm2
pshufd $0xa0,%xmm2,%xmm6
pcmpeqd %xmm3,%xmm0
pshufd $0xf5,%xmm0,%xmm0
pand   %xmm6,%xmm0
movdqa %xmm4,%xmm6
paddq  %xmm10,%xmm6
pshufd $0xf5,%xmm2,%xmm2
por    %xmm0,%xmm2
pxor   %xmm14,%xmm6
movdqa %xmm3,%xmm0
pcmpgtd %xmm6,%xmm0
pcmpeqd %xmm3,%xmm6
pshufd $0xa0,%xmm0,%xmm3
pshufd $0xf5,%xmm6,%xmm6
pand   %xmm3,%xmm6
pshufd $0xf5,%xmm0,%xmm0
por    %xmm6,%xmm0
movdqa (%rsp,%rdx,4),%xmm3
packssdw %xmm0,%xmm2
movdqa %xmm15,%xmm0
pcmpgtd %xmm3,%xmm0
pcmpeqd %xmm15,%xmm3
pand   %xmm3,%xmm2
movdqa %xmm0,%xmm3
pandn  %xmm2,%xmm3
pand   %xmm11,%xmm3
psubd  %xmm0,%xmm3
paddd  %xmm3,%xmm1
paddq  %xmm12,%xmm5
paddq  %xmm12,%xmm4
add    $0x8,%rdx
cmp    $0x186a4,%rdx
jne    1220 <main+0xc0>
paddd  %xmm7,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%edx
mov    %ecx,(%rbx,%rdx,4)
add    $0x1,%rax
cmp    $0x186a0,%rax
jne    11e0 <main+0x80>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    $0x61a80,%edx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x61a80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca [100000 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 @time(i32* null)
%11 = call i32 @srand(i32 %10)
store i32 0, i32* %4
br label %12
12: ; preds = %21, %0
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 100000
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = call i32 (...) @rand()
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [100000 x i32], [100000 x i32]* %2, i64 0, i64 %19
store i32 %17, i32* %20
br label %21
21: ; preds = %15
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %12
24: ; preds = %12
store i32 100000, i32* %5
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 4
%28 = trunc i64 %27 to i32
%29 = call i32* @malloc(i32 %28)
store i32* %29, i32** %6
store i32 0, i32* %7
br label %30
30: ; preds = %83, %24
%31 = load i32, i32* %7
%32 = load i32, i32* %5
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %86
34: ; preds = %30
store i32 0, i32* %8
store i32 0, i32* %9
br label %35
35: ; preds = %71, %34
%36 = load i32, i32* %9
%37 = load i32, i32* %5
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %74
39: ; preds = %35
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [100000 x i32], [100000 x i32]* %2, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [100000 x i32], [100000 x i32]* %2, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = icmp slt i32 %43, %47
br i1 %48, label %49, label %52
49: ; preds = %39
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %70
52: ; preds = %39
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [100000 x i32], [100000 x i32]* %2, i64 0, i64 %54
%56 = load i32, i32* %55
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [100000 x i32], [100000 x i32]* %2, i64 0, i64 %58
%60 = load i32, i32* %59
%61 = icmp eq i32 %56, %60
br i1 %61, label %62, label %69
62: ; preds = %52
%63 = load i32, i32* %9
%64 = load i32, i32* %7
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %69
66: ; preds = %62
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
br label %69
69: ; preds = %66, %62, %52
br label %70
70: ; preds = %69, %49
br label %71
71: ; preds = %70
%72 = load i32, i32* %9
%73 = add nsw i32 %72, 1
store i32 %73, i32* %9
br label %35
74: ; preds = %35
%75 = load i32, i32* %7
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [100000 x i32], [100000 x i32]* %2, i64 0, i64 %76
%78 = load i32, i32* %77
%79 = load i32*, i32** %6
%80 = load i32, i32* %8
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %79, i64 %81
store i32 %78, i32* %82
br label %83
83: ; preds = %74
%84 = load i32, i32* %7
%85 = add nsw i32 %84, 1
store i32 %85, i32* %7
br label %30
86: ; preds = %30
%87 = getelementptr inbounds [100000 x i32], [100000 x i32]* %2, i64 0, i64 0
%88 = load i32*, i32** %6
%89 = load i32, i32* %5
%90 = sext i32 %89 to i64
%91 = mul i64 %90, 4
%92 = trunc i64 %91 to i32
%93 = call i32 @memcpy(i32* %87, i32* %88, i32 %92)
%94 = load i32*, i32** %6
%95 = call i32 @free(i32* %94)
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [100000 x i32]
%2 = bitcast [100000 x i32]* %1 to i8*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
br label %7
5: ; preds = %7
%6 = tail call i32* @malloc(i32 400000)
br label %13
7: ; preds = %0, %7
%8 = phi i64 [ 0, %0 ], [ %11, %7 ]
%9 = tail call i32 (...) @rand()
%10 = getelementptr inbounds [100000 x i32], [100000 x i32]* %1, i64 0, i64 %8
store i32 %9, i32* %10
%11 = add nuw nsw i64 %8, 1
%12 = icmp eq i64 %11, 100000
br i1 %12, label %5, label %7
13: ; preds = %5, %54
%14 = phi i64 [ 0, %5 ], [ %59, %54 ]
%15 = getelementptr inbounds [100000 x i32], [100000 x i32]* %1, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = insertelement <4 x i32> poison, i32 %16, i64 0
%18 = shufflevector <4 x i32> %17, <4 x i32> poison, <4 x i32> zeroinitializer
%19 = insertelement <4 x i32> poison, i32 %16, i64 0
%20 = shufflevector <4 x i32> %19, <4 x i32> poison, <4 x i32> zeroinitializer
%21 = insertelement <4 x i64> poison, i64 %14, i64 0
%22 = shufflevector <4 x i64> %21, <4 x i64> poison, <4 x i32> zeroinitializer
%23 = insertelement <4 x i64> poison, i64 %14, i64 0
%24 = shufflevector <4 x i64> %23, <4 x i64> poison, <4 x i32> zeroinitializer
br label %25
25: ; preds = %25, %13
%26 = phi i64 [ 0, %13 ], [ %51, %25 ]
%27 = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, %13 ], [ %52, %25 ]
%28 = phi <4 x i32> [ zeroinitializer, %13 ], [ %49, %25 ]
%29 = phi <4 x i32> [ zeroinitializer, %13 ], [ %50, %25 ]
%30 = add <4 x i64> %27, <i64 4, i64 4, i64 4, i64 4>
%31 = getelementptr inbounds [100000 x i32], [100000 x i32]* %1, i64 0, i64 %26
%32 = bitcast i32* %31 to <4 x i32>*
%33 = load <4 x i32>, <4 x i32>* %32
%34 = getelementptr inbounds i32, i32* %31, i64 4
%35 = bitcast i32* %34 to <4 x i32>*
%36 = load <4 x i32>, <4 x i32>* %35
%37 = icmp slt <4 x i32> %33, %18
%38 = icmp slt <4 x i32> %36, %20
%39 = icmp eq <4 x i32> %33, %18
%40 = icmp eq <4 x i32> %36, %20
%41 = icmp ult <4 x i64> %27, %22
%42 = icmp ult <4 x i64> %30, %24
%43 = select <4 x i1> %39, <4 x i1> %41, <4 x i1> zeroinitializer
%44 = select <4 x i1> %40, <4 x i1> %42, <4 x i1> zeroinitializer
%45 = select <4 x i1> %37, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x i1> %43
%46 = select <4 x i1> %38, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x i1> %44
%47 = zext <4 x i1> %45 to <4 x i32>
%48 = zext <4 x i1> %46 to <4 x i32>
%49 = add <4 x i32> %28, %47
%50 = add <4 x i32> %29, %48
%51 = add nuw i64 %26, 8
%52 = add <4 x i64> %27, <i64 8, i64 8, i64 8, i64 8>
%53 = icmp eq i64 %51, 100000
br i1 %53, label %54, label %25
54: ; preds = %25
%55 = add <4 x i32> %50, %49
%56 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %55)
%57 = zext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %6, i64 %57
store i32 %16, i32* %58
%59 = add nuw nsw i64 %14, 1
%60 = icmp eq i64 %59, 100000
br i1 %60, label %61, label %13
61: ; preds = %54
%62 = getelementptr inbounds [100000 x i32], [100000 x i32]* %1, i64 0, i64 0
%63 = call i32 @memcpy(i32* %62, i32* %6, i32 400000)
%64 = call i32 @free(i32* %6)
ret i32 0
}