#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*/ int64_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sorter_sqrt_sort_build_blocks(int /*<<< orphan*/ *, int,
                                                 int);
int /*<<< orphan*/ sorter_sqrt_sort_combine_blocks(int /*<<< orphan*/ *, int,
                                                   int, int, int *);
int /*<<< orphan*/ sorter_sqrt_sort_merge_down(int /*<<< orphan*/ *,
                                               int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ sorter_sqrt_sort_sort_ins(int /*<<< orphan*/ *, int);
void sorter_sqrt_sort_common_sort(int64_t *arr, int Len, int64_t *extbuf,
                                  int *Tags) {
  int lblock, cbuf;
  if (Len < 16) {
    sorter_sqrt_sort_sort_ins(arr, Len);
    return;
  }
  lblock = 1;
  while (lblock * lblock < Len) {
    lblock *= 2;
  }
  memcpy(extbuf, arr, lblock * sizeof(int64_t));
  sorter_sqrt_sort_common_sort(extbuf, lblock, arr, Tags);
  sorter_sqrt_sort_build_blocks(arr + lblock, Len - lblock, lblock);
  cbuf = lblock;
  while (Len > (cbuf *= 2)) {
    sorter_sqrt_sort_combine_blocks(arr + lblock, Len - lblock, cbuf, lblock,
                                    Tags);
  }
  sorter_sqrt_sort_merge_down(arr + lblock, extbuf, Len - lblock, lblock);
}


x86 assembly (clang, -O0):
<sorter_sqrt_sort_common_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x10,-0xc(%rbp)
jge    1192 <sorter_sqrt_sort_common_sort+0x32>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <sorter_sqrt_sort_sort_ins@plt>
jmp    1263 <sorter_sqrt_sort_common_sort+0x103>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
imul   -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b7 <sorter_sqrt_sort_common_sort+0x57>
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1199 <sorter_sqrt_sort_common_sort+0x39>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <sorter_sqrt_sort_common_sort@plt>
mov    -0x8(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
sub    -0x24(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1070 <sorter_sqrt_sort_build_blocks@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x28(%rbp),%ecx
shl    $0x1,%ecx
mov    %ecx,-0x28(%rbp)
cmp    %ecx,%eax
jle    1242 <sorter_sqrt_sort_common_sort+0xe2>
mov    -0x8(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
sub    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%r8
call   1040 <sorter_sqrt_sort_combine_blocks@plt>
jmp    1205 <sorter_sqrt_sort_common_sort+0xa5>
mov    -0x8(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
sub    -0x24(%rbp),%edx
mov    -0x24(%rbp),%ecx
call   1080 <sorter_sqrt_sort_merge_down@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sorter_sqrt_sort_common_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r12d
mov    %rdi,%r13
cmp    $0x10,%esi
jge    1192 <sorter_sqrt_sort_common_sort+0x32>
mov    %r13,%rdi
mov    %r12d,%esi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <sorter_sqrt_sort_sort_ins@plt>
mov    %rcx,%r15
mov    %rdx,%r14
mov    $0x1,%ebp
nopl   (%rax)
mov    %ebp,%ebx
mov    %ebp,%eax
imul   %ebp,%eax
lea    (%rbx,%rbx,1),%ebp
cmp    %r12d,%eax
jl     11a0 <sorter_sqrt_sort_common_sort+0x40>
mov    %ebx,%eax
mov    %rax,0x8(%rsp)
lea    0x0(,%rbx,4),%edx
mov    %r14,%rdi
mov    %r13,%rsi
call   1060 <memcpy@plt>
mov    %r14,0x10(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r13,%rdx
mov    %r15,%rcx
call   1050 <sorter_sqrt_sort_common_sort@plt>
mov    0x8(%rsp),%rax
lea    0x0(,%rax,4),%r14
add    %r13,%r14
mov    %r12d,%r13d
sub    %ebx,%r13d
mov    %r14,%rdi
mov    %r13d,%esi
mov    %ebx,%edx
call   1070 <sorter_sqrt_sort_build_blocks@plt>
cmp    %r12d,%ebp
jge    1229 <sorter_sqrt_sort_common_sort+0xc9>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %r13d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %r15,%r8
call   1040 <sorter_sqrt_sort_combine_blocks@plt>
add    %ebp,%ebp
cmp    %r12d,%ebp
jl     1210 <sorter_sqrt_sort_common_sort+0xb0>
mov    %r14,%rdi
mov    0x10(%rsp),%rsi
mov    %r13d,%edx
mov    %ebx,%ecx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <sorter_sqrt_sort_merge_down@plt>

LLVM IR (-O0):
define void @sorter_sqrt_sort_common_sort(i32* %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 16
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = load i32*, i32** %5
%15 = load i32, i32* %6
%16 = call i32 @sorter_sqrt_sort_sort_ins(i32* %14, i32 %15)
br label %77
17: ; preds = %4
store i32 1, i32* %9
br label %18
18: ; preds = %24, %17
%19 = load i32, i32* %9
%20 = load i32, i32* %9
%21 = mul nsw i32 %19, %20
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* %9
%26 = mul nsw i32 %25, 2
store i32 %26, i32* %9
br label %18
27: ; preds = %18
%28 = load i32*, i32** %7
%29 = load i32*, i32** %5
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 4
%33 = trunc i64 %32 to i32
%34 = call i32 @memcpy(i32* %28, i32* %29, i32 %33)
%35 = load i32*, i32** %7
%36 = load i32, i32* %9
%37 = load i32*, i32** %5
%38 = load i32*, i32** %8
%39 = load i32*, i32** %5
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %6
%44 = load i32, i32* %9
%45 = sub nsw i32 %43, %44
%46 = load i32, i32* %9
%47 = call i32 @sorter_sqrt_sort_build_blocks(i32* %42, i32 %45, i32 %46)
%48 = load i32, i32* %9
store i32 %48, i32* %10
br label %49
49: ; preds = %54, %27
%50 = load i32, i32* %6
%51 = load i32, i32* %10
%52 = mul nsw i32 %51, 2
store i32 %52, i32* %10
%53 = icmp sgt i32 %50, %52
br i1 %53, label %54, label %66
54: ; preds = %49
%55 = load i32*, i32** %5
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
%59 = load i32, i32* %6
%60 = load i32, i32* %9
%61 = sub nsw i32 %59, %60
%62 = load i32, i32* %10
%63 = load i32, i32* %9
%64 = load i32*, i32** %8
%65 = call i32 @sorter_sqrt_sort_combine_blocks(i32* %58, i32 %61, i32 %62, i32 %63, i32* %64)
br label %49
66: ; preds = %49
%67 = load i32*, i32** %5
%68 = load i32, i32* %9
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %67, i64 %69
%71 = load i32*, i32** %7
%72 = load i32, i32* %6
%73 = load i32, i32* %9
%74 = sub nsw i32 %72, %73
%75 = load i32, i32* %9
%76 = call i32 @sorter_sqrt_sort_merge_down(i32* %70, i32* %71, i32 %74, i32 %75)
br label %77
77: ; preds = %66, %13
ret void
}

LLVM IR (-O2):
define void @sorter_sqrt_sort_common_sort(i32* %0, i32 %1, i32* %2, i32* %3) {
%5 = icmp slt i32 %1, 16
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @sorter_sqrt_sort_sort_ins(i32* %0, i32 %1)
br label %28
8: ; preds = %4, %8
%9 = phi i32 [ %12, %8 ], [ 1, %4 ]
%10 = mul nsw i32 %9, %9
%11 = icmp slt i32 %10, %1
%12 = shl nsw i32 %9, 1
br i1 %11, label %8, label %13
13: ; preds = %8
%14 = zext i32 %9 to i64
%15 = shl i32 %9, 2
%16 = tail call i32 @memcpy(i32* %2, i32* %0, i32 %15)
tail call void @sorter_sqrt_sort_common_sort(i32* %2, i32 %9, i32* %0, i32* %3)
%17 = getelementptr inbounds i32, i32* %0, i64 %14
%18 = sub nsw i32 %1, %9
%19 = tail call i32 @sorter_sqrt_sort_build_blocks(i32* %17, i32 %18, i32 %9)
%20 = icmp slt i32 %12, %1
br i1 %20, label %21, label %26
21: ; preds = %13, %21
%22 = phi i32 [ %24, %21 ], [ %12, %13 ]
%23 = tail call i32 @sorter_sqrt_sort_combine_blocks(i32* %17, i32 %18, i32 %22, i32 %9, i32* %3)
%24 = shl nsw i32 %22, 1
%25 = icmp slt i32 %24, %1
br i1 %25, label %21, label %26
26: ; preds = %21, %13
%27 = tail call i32 @sorter_sqrt_sort_merge_down(i32* %17, i32* %2, i32 %18, i32 %9)
br label %28
28: ; preds = %26, %6
ret void
}