#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 */
double count_sort_parallel(double *, int, int);
double count_sort_serial(double *, int);
int /*<<< orphan*/ memcpy(double *, double *, int);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  double v[20001];
  double v2[20001];
  int nthreads, n;
  int i;
  scanf(" %d %d", &nthreads, &n);
  for (i = 0; i < n; i++) {
    scanf(" %lf", &v[i]);
  }
  memcpy(v2, v, n * sizeof(double));
  double time = count_sort_serial(v, n);
  for (i = 0; i < n; i++) {
    printf(" %.2lf", v[i]);
  }
  printf("\n%lf\n", time);
  time = count_sort_parallel(v2, n, nthreads);
  for (i = 0; i < n; i++) {
    printf(" %.2lf", v2[i]);
  }
  printf("\n%lf\n", time);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e240,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    -0x4e224(%rbp),%rsi
lea    -0x4e228(%rbp),%rdx
mov    $0x0,%al
call   1070 <scanf@plt>
movl   $0x0,-0x4e22c(%rbp)
mov    -0x4e22c(%rbp),%eax
cmp    -0x4e228(%rbp),%eax
jge    11d1 <main+0x81>
movslq -0x4e22c(%rbp),%rax
lea    -0x27110(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x4e22c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e22c(%rbp)
jmp    1188 <main+0x38>
lea    -0x4e220(%rbp),%rdi
lea    -0x27110(%rbp),%rsi
movslq -0x4e228(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
lea    -0x27110(%rbp),%rdi
mov    -0x4e228(%rbp),%esi
call   1030 <count_sort_serial@plt>
movsd  %xmm0,-0x4e238(%rbp)
ff
movl   $0x0,-0x4e22c(%rbp)
mov    -0x4e22c(%rbp),%eax
cmp    -0x4e228(%rbp),%eax
jge    1257 <main+0x107>
movslq -0x4e22c(%rbp),%rax
movsd  -0x27110(%rbp,%rax,8),%xmm0
fd ff
lea    0xdce(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4e22c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e22c(%rbp)
jmp    1215 <main+0xc5>
movsd  -0x4e238(%rbp),%xmm0
ff
lea    0xdad(%rip),%rdi
call   1050 <printf@plt>
lea    -0x4e220(%rbp),%rdi
mov    -0x4e228(%rbp),%esi
mov    -0x4e224(%rbp),%edx
call   1040 <count_sort_parallel@plt>
movsd  %xmm0,-0x4e238(%rbp)
ff
movl   $0x0,-0x4e22c(%rbp)
mov    -0x4e22c(%rbp),%eax
cmp    -0x4e228(%rbp),%eax
jge    12d7 <main+0x187>
movslq -0x4e22c(%rbp),%rax
movsd  -0x4e220(%rbp,%rax,8),%xmm0
fb ff
lea    0xd4e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4e22c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e22c(%rbp)
jmp    1295 <main+0x145>
movsd  -0x4e238(%rbp),%xmm0
ff
lea    0xd2d(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x4e240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x4e240,%rsp
lea    0xe9d(%rip),%rdi
lea    0x1c(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0xc(%rsp),%edx
test   %edx,%edx
jle    11af <main+0x5f>
lea    0x27130(%rsp),%r15
lea    0xe7c(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rdx
add    $0x8,%r15
cmp    %rdx,%rbx
jl     1190 <main+0x40>
shl    $0x3,%edx
lea    0x20(%rsp),%rdi
lea    0x27130(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <memcpy@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1030 <count_sort_serial@plt>
movsd  %xmm0,0x10(%rsp)
cmpl   $0x0,0xc(%rsp)
jle    120f <main+0xbf>
xor    %ebx,%ebx
lea    0xe23(%rip),%r14
nopl   0x0(%rax)
movsd  0x27130(%rsp,%rbx,8),%xmm0
mov    %r14,%rdi
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11f0 <main+0xa0>
lea    0xdfd(%rip),%rdi
movsd  0x10(%rsp),%xmm0
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    0x1c(%rsp),%edx
lea    0x20(%rsp),%rdi
call   1040 <count_sort_parallel@plt>
movsd  %xmm0,0x10(%rsp)
cmpl   $0x0,0xc(%rsp)
jle    126c <main+0x11c>
xor    %ebx,%ebx
lea    0xdc3(%rip),%r14
nopl   0x0(%rax)
movsd  0x20(%rsp,%rbx,8),%xmm0
mov    %r14,%rdi
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1250 <main+0x100>
lea    0xda0(%rip),%rdi
movsd  0x10(%rsp),%xmm0
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x4e240,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c" %d %d\00"
@.str.1 = [5 x i8] c" %lf\00"
@.str.2 = [7 x i8] c" %.2lf\00"
@.str.3 = [6 x i8] c"\0A%lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20001 x double]
%3 = alloca [20001 x double]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5)
store i32 0, i32* %6
br label %9
9: ; preds = %18, %0
%10 = load i32, i32* %6
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [20001 x double], [20001 x double]* %2, i64 0, i64 %15
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double* %16)
br label %18
18: ; preds = %13
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
br label %9
21: ; preds = %9
%22 = getelementptr inbounds [20001 x double], [20001 x double]* %3, i64 0, i64 0
%23 = getelementptr inbounds [20001 x double], [20001 x double]* %2, i64 0, i64 0
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 8
%27 = trunc i64 %26 to i32
%28 = call i32 @memcpy(double* %22, double* %23, i32 %27)
%29 = getelementptr inbounds [20001 x double], [20001 x double]* %2, i64 0, i64 0
%30 = load i32, i32* %5
%31 = call double @count_sort_serial(double* %29, i32 %30)
store double %31, double* %7
store i32 0, i32* %6
br label %32
32: ; preds = %42, %21
%33 = load i32, i32* %6
%34 = load i32, i32* %5
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %45
36: ; preds = %32
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [20001 x double], [20001 x double]* %2, i64 0, i64 %38
%40 = load double, double* %39
%41 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %40)
br label %42
42: ; preds = %36
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %32
45: ; preds = %32
%46 = load double, double* %7
%47 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %46)
%48 = getelementptr inbounds [20001 x double], [20001 x double]* %3, i64 0, i64 0
%49 = load i32, i32* %5
%50 = load i32, i32* %4
%51 = call double @count_sort_parallel(double* %48, i32 %49, i32 %50)
store double %51, double* %7
store i32 0, i32* %6
br label %52
52: ; preds = %62, %45
%53 = load i32, i32* %6
%54 = load i32, i32* %5
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %65
56: ; preds = %52
%57 = load i32, i32* %6
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [20001 x double], [20001 x double]* %3, i64 0, i64 %58
%60 = load double, double* %59
%61 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %60)
br label %62
62: ; preds = %56
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %52
65: ; preds = %52
%66 = load double, double* %7
%67 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %66)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c" %d %d\00"
@.str.1 = [5 x i8] c" %lf\00"
@.str.2 = [7 x i8] c" %.2lf\00"
@.str.3 = [6 x i8] c"\0A%lf\0A\00"
define i32 @main() {
%1 = alloca [20001 x double]
%2 = alloca [20001 x double]
%3 = alloca i32
%4 = alloca i32
%5 = bitcast [20001 x double]* %1 to i8*
%6 = bitcast [20001 x double]* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4)
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %0, %12
%13 = phi i64 [ %16, %12 ], [ 0, %0 ]
%14 = getelementptr inbounds [20001 x double], [20001 x double]* %1, i64 0, i64 %13
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double* %14)
%16 = add nuw nsw i64 %13, 1
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %12, label %20
20: ; preds = %12, %0
%21 = phi i32 [ %10, %0 ], [ %17, %12 ]
%22 = getelementptr inbounds [20001 x double], [20001 x double]* %2, i64 0, i64 0
%23 = getelementptr inbounds [20001 x double], [20001 x double]* %1, i64 0, i64 0
%24 = shl i32 %21, 3
%25 = call i32 @memcpy(double* %22, double* %23, i32 %24)
%26 = load i32, i32* %4
%27 = call double @count_sort_serial(double* %23, i32 %26)
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %20, %30
%31 = phi i64 [ %35, %30 ], [ 0, %20 ]
%32 = getelementptr inbounds [20001 x double], [20001 x double]* %1, i64 0, i64 %31
%33 = load double, double* %32
%34 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %33)
%35 = add nuw nsw i64 %31, 1
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = icmp slt i64 %35, %37
br i1 %38, label %30, label %39
39: ; preds = %30, %20
%40 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %27)
%41 = load i32, i32* %4
%42 = load i32, i32* %3
%43 = call double @count_sort_parallel(double* %22, i32 %41, i32 %42)
%44 = load i32, i32* %4
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %55
46: ; preds = %39, %46
%47 = phi i64 [ %51, %46 ], [ 0, %39 ]
%48 = getelementptr inbounds [20001 x double], [20001 x double]* %2, i64 0, i64 %47
%49 = load double, double* %48
%50 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %49)
%51 = add nuw nsw i64 %47, 1
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = icmp slt i64 %51, %53
br i1 %54, label %46, label %55
55: ; preds = %46, %39
%56 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %43)
ret i32 0
}