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

/* Variables and functions */
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sorter_sqrt_sort_common_sort(int *, size_t, int *, int *);
void sorter_sqrt_sort(int64_t *arr, size_t Len) {
  size_t L = 1;
  int64_t *ExtBuf;
  int *Tags;
  while (L * L < Len) {
    L *= 2;
  }
  int NK = (Len - 1) / L + 2;
  ExtBuf = (int64_t *)malloc(L * sizeof(int64_t));
  if (ExtBuf == 0) {
    return;
  }
  Tags = (int *)malloc(NK * sizeof(int));
  if (Tags == 0) {
    return;
  }
  sorter_sqrt_sort_common_sort(arr, Len, ExtBuf, Tags);
  free(Tags);
  free(ExtBuf);
}


x86 assembly (clang, -O0):
<sorter_sqrt_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    116c <sorter_sqrt_sort+0x3c>
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1148 <sorter_sqrt_sort+0x18>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
add    $0x2,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a6 <sorter_sqrt_sort+0x76>
jmp    11f0 <sorter_sqrt_sort+0xc0>
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c9 <sorter_sqrt_sort+0x99>
jmp    11f0 <sorter_sqrt_sort+0xc0>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <sorter_sqrt_sort_common_sort@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sorter_sqrt_sort>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r13
mov    %rdi,%r14
mov    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,%rbx
mov    %rax,%rcx
imul   %rax,%rcx
add    %rax,%rax
cmp    %r13,%rcx
jb     1150 <sorter_sqrt_sort+0x20>
lea    0x0(,%rbx,4),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11dd <sorter_sqrt_sort+0xad>
mov    %rax,%r15
lea    -0x1(%r13),%rax
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
je     118d <sorter_sqrt_sort+0x5d>
xor    %edx,%edx
div    %rbx
jmp    1191 <sorter_sqrt_sort+0x61>
xor    %edx,%edx
div    %ebx
shl    $0x20,%rax
movabs $0x200000000,%rdi
add    %rax,%rdi
shr    $0x1e,%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     11dd <sorter_sqrt_sort+0xad>
mov    %rax,%r12
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    %rax,%rcx
call   1040 <sorter_sqrt_sort_common_sort@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @sorter_sqrt_sort(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
store i64 1, i64* %5
br label %9
9: ; preds = %15, %2
%10 = load i64, i64* %5
%11 = load i64, i64* %5
%12 = mul i64 %10, %11
%13 = load i64, i64* %4
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i64, i64* %5
%17 = mul i64 %16, 2
store i64 %17, i64* %5
br label %9
18: ; preds = %9
%19 = load i64, i64* %4
%20 = sub i64 %19, 1
%21 = load i64, i64* %5
%22 = udiv i64 %20, %21
%23 = add i64 %22, 2
%24 = trunc i64 %23 to i32
store i32 %24, i32* %8
%25 = load i64, i64* %5
%26 = mul i64 %25, 4
%27 = trunc i64 %26 to i32
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i32*
store i32* %29, i32** %6
%30 = load i32*, i32** %6
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %33
32: ; preds = %18
br label %53
33: ; preds = %18
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = mul i64 %35, 4
%37 = trunc i64 %36 to i32
%38 = call i64 @malloc(i32 %37)
%39 = inttoptr i64 %38 to i32*
store i32* %39, i32** %7
%40 = load i32*, i32** %7
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %43
42: ; preds = %33
br label %53
43: ; preds = %33
%44 = load i32*, i32** %3
%45 = load i64, i64* %4
%46 = load i32*, i32** %6
%47 = load i32*, i32** %7
%48 = call i32 @sorter_sqrt_sort_common_sort(i32* %44, i64 %45, i32* %46, i32* %47)
%49 = load i32*, i32** %7
%50 = call i32 @free(i32* %49)
%51 = load i32*, i32** %6
%52 = call i32 @free(i32* %51)
br label %53
53: ; preds = %43, %42, %32
ret void
}

LLVM IR (-O2):
define void @sorter_sqrt_sort(i32* %0, i64 %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64 [ 1, %2 ], [ %7, %3 ]
%5 = mul i64 %4, %4
%6 = icmp ult i64 %5, %1
%7 = shl i64 %4, 1
br i1 %6, label %3, label %8
8: ; preds = %3
%9 = trunc i64 %4 to i32
%10 = shl i32 %9, 2
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
%13 = icmp eq i64 %11, 0
br i1 %13, label %28, label %14
14: ; preds = %8
%15 = add i64 %1, -1
%16 = udiv i64 %15, %4
%17 = shl i64 %16, 32
%18 = add i64 %17, 8589934592
%19 = lshr exact i64 %18, 30
%20 = trunc i64 %19 to i32
%21 = tail call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
%23 = icmp eq i64 %21, 0
br i1 %23, label %28, label %24
24: ; preds = %14
%25 = tail call i32 @sorter_sqrt_sort_common_sort(i32* %0, i64 %1, i32* %12, i32* %22)
%26 = tail call i32 @free(i32* %22)
%27 = tail call i32 @free(i32* %12)
br label %28
28: ; preds = %14, %8, %24
ret void
}