#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 log(int);
int /*<<< orphan*/ sort_add(long, double *);
int /*<<< orphan*/ sort_par(long, double *, int, int);
void sort_iter_single(long num_links, double *restrict add1, int parent) {
  static int MERGE_SORT_LIMIT_SIZE = 16384;
  static int first_sort_iter_call = 1;
  static double merge_time;
  int par_depth = 1;
  if (first_sort_iter_call) {
    first_sort_iter_call = 0;
    par_depth = (int)(log(parent) / log(2));
    MERGE_SORT_LIMIT_SIZE = num_links / parent / 2;
    if (MERGE_SORT_LIMIT_SIZE < 4096)
      MERGE_SORT_LIMIT_SIZE = 4096;
    parent = 1;
  }
  if (num_links > MERGE_SORT_LIMIT_SIZE)
    sort_par(num_links, add1, parent, par_depth);
  else
    sort_add(num_links, add1);
  if (parent == 1) {
    first_sort_iter_call = 1;
    merge_time = 0;
  }
  return;
}


x86 assembly (clang, -O0):
<sort_iter_single>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,0x2eeb(%rip)
je     11bf <sort_iter_single+0x8f>
movl   $0x0,0x2edb(%rip)
mov    -0x14(%rbp),%edi
call   1040 <log@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x2,%edi
call   1040 <log@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cqto
idiv   %rcx
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %eax,0x2e9a(%rip)
cmpl   $0x1000,0x2e90(%rip)
jge    11b8 <sort_iter_single+0x88>
movl   $0x1000,0x2e80(%rip)
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq 0x2e6e(%rip),%rcx
cmp    %rcx,%rax
jle    11eb <sort_iter_single+0xbb>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <sort_par@plt>
jmp    11f8 <sort_iter_single+0xc8>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <sort_add@plt>
cmpl   $0x1,-0x14(%rbp)
jne    1217 <sort_iter_single+0xe7>
movl   $0x1,0x2e30(%rip)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2e31(%rip)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_iter_single>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
cmpb   $0x1,0x2efa(%rip)
jne    1155 <sort_iter_single+0x25>
mov    $0x1,%ecx
mov    0x2ee5(%rip),%eax
jmp    11bf <sort_iter_single+0x8f>
movb   $0x1,0x2ee4(%rip)
mov    %ebp,%edi
call   1040 <log@plt>
mov    %eax,%r15d
mov    $0x2,%edi
call   1040 <log@plt>
mov    %eax,%ecx
mov    %r15d,%eax
cltd
idiv   %ecx
mov    %eax,%ecx
movslq %ebp,%rsi
mov    %rbx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     1193 <sort_iter_single+0x63>
mov    %rbx,%rax
cqto
idiv   %rsi
jmp    1199 <sort_iter_single+0x69>
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
mov    %rax,%rdx
shr    $0x3f,%rdx
add    %rax,%rdx
shr    %rdx
cmp    $0x1001,%edx
mov    $0x1000,%eax
cmovge %edx,%eax
mov    %eax,0x2e7e(%rip)
mov    $0x1,%ebp
cltq
mov    %rbx,%rdi
mov    %r14,%rsi
cmp    %rbx,%rax
jge    11da <sort_iter_single+0xaa>
mov    %ebp,%edx
call   1030 <sort_par@plt>
cmp    $0x1,%ebp
je     11e4 <sort_iter_single+0xb4>
jmp    11eb <sort_iter_single+0xbb>
call   1050 <sort_add@plt>
cmp    $0x1,%ebp
jne    11eb <sort_iter_single+0xbb>
movb   $0x0,0x2e55(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@sort_iter_single.MERGE_SORT_LIMIT_SIZE = internal global i32 16384
@sort_iter_single.first_sort_iter_call = internal global i32 1
@sort_iter_single.merge_time = internal global double 0.000000e+00
define void @sort_iter_single(i64 %0, double* noalias %1, i32 %2) {
%4 = alloca i64
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
store i64 %0, i64* %4
store double* %1, double** %5
store i32 %2, i32* %6
store i32 1, i32* %7
%8 = load i32, i32* @sort_iter_single.first_sort_iter_call
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %3
store i32 0, i32* @sort_iter_single.first_sort_iter_call
%11 = load i32, i32* %6
%12 = call i32 @log(i32 %11)
%13 = call i32 @log(i32 2)
%14 = sdiv i32 %12, %13
store i32 %14, i32* %7
%15 = load i64, i64* %4
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = sdiv i64 %15, %17
%19 = sdiv i64 %18, 2
%20 = trunc i64 %19 to i32
store i32 %20, i32* @sort_iter_single.MERGE_SORT_LIMIT_SIZE
%21 = load i32, i32* @sort_iter_single.MERGE_SORT_LIMIT_SIZE
%22 = icmp slt i32 %21, 4096
br i1 %22, label %23, label %24
23: ; preds = %10
store i32 4096, i32* @sort_iter_single.MERGE_SORT_LIMIT_SIZE
br label %24
24: ; preds = %23, %10
store i32 1, i32* %6
br label %25
25: ; preds = %24, %3
%26 = load i64, i64* %4
%27 = load i32, i32* @sort_iter_single.MERGE_SORT_LIMIT_SIZE
%28 = sext i32 %27 to i64
%29 = icmp sgt i64 %26, %28
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = load i64, i64* %4
%32 = load double*, double** %5
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = call i32 @sort_par(i64 %31, double* %32, i32 %33, i32 %34)
br label %40
36: ; preds = %25
%37 = load i64, i64* %4
%38 = load double*, double** %5
%39 = call i32 @sort_add(i64 %37, double* %38)
br label %40
40: ; preds = %36, %30
%41 = load i32, i32* %6
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 1, i32* @sort_iter_single.first_sort_iter_call
store double 0.000000e+00, double* @sort_iter_single.merge_time
br label %44
44: ; preds = %43, %40
ret void
}

LLVM IR (-O2):
@sort_iter_single.MERGE_SORT_LIMIT_SIZE = internal unnamed_addr global i32 16384
@sort_iter_single.first_sort_iter_call = internal unnamed_addr global i1 false
define void @sort_iter_single(i64 %0, double* noalias %1, i32 %2) {
%4 = load i1, i1* @sort_iter_single.first_sort_iter_call
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = load i32, i32* @sort_iter_single.MERGE_SORT_LIMIT_SIZE
br label %17
7: ; preds = %3
store i1 true, i1* @sort_iter_single.first_sort_iter_call
%8 = tail call i32 @log(i32 %2)
%9 = tail call i32 @log(i32 2)
%10 = sdiv i32 %8, %9
%11 = sext i32 %2 to i64
%12 = sdiv i64 %0, %11
%13 = sdiv i64 %12, 2
%14 = trunc i64 %13 to i32
%15 = icmp sgt i32 %14, 4096
%16 = select i1 %15, i32 %14, i32 4096
store i32 %16, i32* @sort_iter_single.MERGE_SORT_LIMIT_SIZE
br label %17
17: ; preds = %5, %7
%18 = phi i32 [ %16, %7 ], [ %6, %5 ]
%19 = phi i32 [ 1, %7 ], [ %2, %5 ]
%20 = phi i32 [ %10, %7 ], [ 1, %5 ]
%21 = sext i32 %18 to i64
%22 = icmp slt i64 %21, %0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = tail call i32 @sort_par(i64 %0, double* %1, i32 %19, i32 %20)
br label %27
25: ; preds = %17
%26 = tail call i32 @sort_add(i64 %0, double* %1)
br label %27
27: ; preds = %25, %23
%28 = icmp eq i32 %19, 1
br i1 %28, label %29, label %30
29: ; preds = %27
store i1 false, i1* @sort_iter_single.first_sort_iter_call
br label %30
30: ; preds = %29, %27
ret void
}