int CountSortedRowsDouble(int M, int N, double **sorted, int *sort_idx,
                          double **uni_list, int *uni_i, int *uni_j, int *cnt) {
  int m, u, n1, n;
  for (n1 = 0; n1 < N; n1++)
    uni_list[0][n1] = sorted[0][n1];
  uni_i[0] = sort_idx[0];
  cnt[0]++;
  uni_j[sort_idx[0]] = 0;
  u = 0;
  for (m = 1; m < M; m++) {
    for (n = 0; n < N; n++)
      if (sorted[m][n] != sorted[m - 1][n])
        break;
    if (n < N) {
      u++;
      for (n1 = 0; n1 < N; n1++)
        uni_list[u][n1] = sorted[m][n1];
      uni_i[u] = sort_idx[m];
    }
    cnt[u]++;
    uni_j[sort_idx[m]] = u;
  }
  u++;
  return u;
}


x86 assembly (clang, -O0):
<CountSortedRowsDouble>:
push   %rbp
mov    %rsp,%rbp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1163 <CountSortedRowsDouble+0x63>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1129 <CountSortedRowsDouble+0x29>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
movl   $0x0,-0x30(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12bc <CountSortedRowsDouble+0x1bc>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1211 <CountSortedRowsDouble+0x111>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x38(%rbp),%rcx
ucomisd (%rax,%rcx,8),%xmm0
jne    11f9 <CountSortedRowsDouble+0xf9>
jp     11f9 <CountSortedRowsDouble+0xf9>
jmp    11fe <CountSortedRowsDouble+0xfe>
jmp    1211 <CountSortedRowsDouble+0x111>
jmp    1203 <CountSortedRowsDouble+0x103>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11ad <CountSortedRowsDouble+0xad>
mov    -0x38(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1287 <CountSortedRowsDouble+0x187>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1271 <CountSortedRowsDouble+0x171>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    122d <CountSortedRowsDouble+0x12d>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%edx
mov    0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x2c(%rbp),%rsi
movslq (%rcx,%rsi,4),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119a <CountSortedRowsDouble+0x9a>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<CountSortedRowsDouble>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r9,-0x28(%rsp)
mov    %r8,-0x30(%rsp)
mov    0x40(%rsp),%r12
mov    0x38(%rsp),%r11
mov    %esi,%r8d
mov    %esi,-0x44(%rsp)
test   %esi,%esi
mov    %rdx,-0x38(%rsp)
mov    %rcx,-0x40(%rsp)
jle    12e9 <CountSortedRowsDouble+0x1e9>
mov    (%rdx),%r15
mov    -0x30(%rsp),%rax
mov    (%rax),%rbp
cmpl   $0x4,-0x44(%rsp)
jb     116a <CountSortedRowsDouble+0x6a>
lea    (%r15,%r8,8),%rax
cmp    %rax,%rbp
jae    11f1 <CountSortedRowsDouble+0xf1>
lea    0x0(,%r8,8),%rax
add    %rbp,%rax
cmp    %rax,%r15
jae    11f1 <CountSortedRowsDouble+0xf1>
xor    %ebx,%ebx
mov    %rbx,%r9
not    %r9
add    %r8,%r9
mov    %r8,%rax
and    $0x3,%rax
je     1196 <CountSortedRowsDouble+0x96>
xchg   %ax,%ax
movsd  (%r15,%rbx,8),%xmm0
movsd  %xmm0,0x0(%rbp,%rbx,8)
add    $0x1,%rbx
add    $0xffffffffffffffff,%rax
jne    1180 <CountSortedRowsDouble+0x80>
cmp    $0x3,%r9
mov    -0x38(%rsp),%rdx
mov    -0x40(%rsp),%rcx
jb     12e9 <CountSortedRowsDouble+0x1e9>
nopw   0x0(%rax,%rax,1)
movsd  (%r15,%rbx,8),%xmm0
movsd  %xmm0,0x0(%rbp,%rbx,8)
movsd  0x8(%r15,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rbp,%rbx,8)
movsd  0x10(%r15,%rbx,8),%xmm0
movsd  %xmm0,0x10(%rbp,%rbx,8)
movsd  0x18(%r15,%rbx,8),%xmm0
movsd  %xmm0,0x18(%rbp,%rbx,8)
add    $0x4,%rbx
cmp    %rbx,%r8
jne    11b0 <CountSortedRowsDouble+0xb0>
jmp    12e9 <CountSortedRowsDouble+0x1e9>
mov    %r8d,%ebx
and    $0xfffffffc,%ebx
lea    -0x4(%rbx),%rax
mov    %rax,%r14
shr    $0x2,%r14
add    $0x1,%r14
mov    %r14d,%r9d
and    $0x3,%r9d
cmp    $0xc,%rax
jae    1217 <CountSortedRowsDouble+0x117>
xor    %eax,%eax
jmp    1283 <CountSortedRowsDouble+0x183>
and    $0xfffffffffffffffc,%r14
xor    %eax,%eax
nopl   (%rax)
movups (%r15,%rax,8),%xmm0
movups 0x10(%r15,%rax,8),%xmm1
movups %xmm0,0x0(%rbp,%rax,8)
movups %xmm1,0x10(%rbp,%rax,8)
movups 0x20(%r15,%rax,8),%xmm0
movups 0x30(%r15,%rax,8),%xmm1
movups %xmm0,0x20(%rbp,%rax,8)
movups %xmm1,0x30(%rbp,%rax,8)
movups 0x40(%r15,%rax,8),%xmm0
movups 0x50(%r15,%rax,8),%xmm1
movups %xmm0,0x40(%rbp,%rax,8)
movups %xmm1,0x50(%rbp,%rax,8)
movupd 0x60(%r15,%rax,8),%xmm0
movups 0x70(%r15,%rax,8),%xmm1
movupd %xmm0,0x60(%rbp,%rax,8)
movups %xmm1,0x70(%rbp,%rax,8)
add    $0x10,%rax
add    $0xfffffffffffffffc,%r14
jne    1220 <CountSortedRowsDouble+0x120>
test   %r9,%r9
je     12d1 <CountSortedRowsDouble+0x1d1>
lea    0x10(,%rax,8),%r10
add    %rbp,%r10
lea    (%r15,%rax,8),%r11
add    $0x10,%r11
shl    $0x5,%r9
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movupd -0x10(%r11,%rax,1),%xmm0
movups (%r11,%rax,1),%xmm1
movupd %xmm0,-0x10(%r10,%rax,1)
movups %xmm1,(%r10,%rax,1)
add    $0x20,%rax
cmp    %rax,%r9
jne    12b0 <CountSortedRowsDouble+0x1b0>
cmp    %r8,%rbx
mov    0x38(%rsp),%r11
mov    -0x38(%rsp),%rdx
mov    -0x40(%rsp),%rcx
jne    116c <CountSortedRowsDouble+0x6c>
mov    (%rcx),%eax
mov    -0x28(%rsp),%rbp
mov    %eax,0x0(%rbp)
addl   $0x1,(%r12)
movslq (%rcx),%rax
movl   $0x0,(%r11,%rax,4)
xor    %eax,%eax
cmp    $0x2,%edi
jl     1574 <CountSortedRowsDouble+0x474>
mov    %edi,%esi
mov    %r8d,%eax
and    $0xfffffffc,%eax
mov    %rax,-0x8(%rsp)
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x10(%rsp)
shr    $0x2,%rax
add    $0x1,%rax
mov    %eax,%r13d
and    $0x3,%r13d
and    $0xfffffffffffffffc,%rax
mov    %rax,-0x20(%rsp)
mov    %r8d,%r10d
and    $0x3,%r10d
mov    %r13,-0x18(%rsp)
shl    $0x5,%r13
xor    %eax,%eax
mov    $0x1,%r15d
jmp    13a2 <CountSortedRowsDouble+0x2a2>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%eax
mov    -0x40(%rsp),%rcx
mov    (%rcx,%r15,4),%edi
mov    -0x28(%rsp),%rbp
mov    %edi,0x0(%rbp,%r11,4)
mov    0x40(%rsp),%r12
mov    0x38(%rsp),%r11
mov    -0x38(%rsp),%rdx
movslq %eax,%rdi
addl   $0x1,(%r12,%rdi,4)
movslq (%rcx,%r15,4),%rbp
mov    %edi,(%r11,%rbp,4)
add    $0x1,%r15
cmp    %rsi,%r15
je     1574 <CountSortedRowsDouble+0x474>
cmpl   $0x0,-0x44(%rsp)
jle    1385 <CountSortedRowsDouble+0x285>
mov    -0x8(%rdx,%r15,8),%rbp
mov    (%rdx,%r15,8),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%r14,%rbx,8),%xmm0
ucomisd 0x0(%rbp,%rbx,8),%xmm0
jne    13e0 <CountSortedRowsDouble+0x2e0>
jp     13e0 <CountSortedRowsDouble+0x2e0>
add    $0x1,%rbx
cmp    %rbx,%r8
jne    13c0 <CountSortedRowsDouble+0x2c0>
jmp    1385 <CountSortedRowsDouble+0x285>
nopl   0x0(%rax,%rax,1)
movslq %eax,%rdi
lea    0x1(%rdi),%r11
mov    -0x30(%rsp),%rbp
mov    0x8(%rbp,%rdi,8),%r9
cmpl   $0x4,-0x44(%rsp)
jb     1412 <CountSortedRowsDouble+0x312>
lea    (%r14,%r8,8),%rdi
cmp    %rdi,%r9
jae    1494 <CountSortedRowsDouble+0x394>
lea    (%r9,%r8,8),%rdi
cmp    %rdi,%r14
jae    1494 <CountSortedRowsDouble+0x394>
xor    %r12d,%r12d
mov    %r12,%rbx
not    %rbx
add    %r8,%rbx
test   %r10,%r10
je     1446 <CountSortedRowsDouble+0x346>
mov    %r10,%rbp
cs nopw 0x0(%rax,%rax,1)
movsd  (%r14,%r12,8),%xmm0
movsd  %xmm0,(%r9,%r12,8)
add    $0x1,%r12
add    $0xffffffffffffffff,%rbp
jne    1430 <CountSortedRowsDouble+0x330>
cmp    $0x3,%rbx
jb     1360 <CountSortedRowsDouble+0x260>
movsd  (%r14,%r12,8),%xmm0
movsd  %xmm0,(%r9,%r12,8)
movsd  0x8(%r14,%r12,8),%xmm0
movsd  %xmm0,0x8(%r9,%r12,8)
movsd  0x10(%r14,%r12,8),%xmm0
movsd  %xmm0,0x10(%r9,%r12,8)
movsd  0x18(%r14,%r12,8),%xmm0
movsd  %xmm0,0x18(%r9,%r12,8)
add    $0x4,%r12
cmp    %r12,%r8
jne    1450 <CountSortedRowsDouble+0x350>
jmp    1360 <CountSortedRowsDouble+0x260>
cmpq   $0xc,-0x10(%rsp)
jae    14a0 <CountSortedRowsDouble+0x3a0>
xor    %ebp,%ebp
jmp    151a <CountSortedRowsDouble+0x41a>
mov    -0x20(%rsp),%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movups (%r14,%rbp,8),%xmm0
movups 0x10(%r14,%rbp,8),%xmm1
movups %xmm0,(%r9,%rbp,8)
movups %xmm1,0x10(%r9,%rbp,8)
movups 0x20(%r14,%rbp,8),%xmm0
movups 0x30(%r14,%rbp,8),%xmm1
movups %xmm0,0x20(%r9,%rbp,8)
movups %xmm1,0x30(%r9,%rbp,8)
movups 0x40(%r14,%rbp,8),%xmm0
movups 0x50(%r14,%rbp,8),%xmm1
movups %xmm0,0x40(%r9,%rbp,8)
movups %xmm1,0x50(%r9,%rbp,8)
movupd 0x60(%r14,%rbp,8),%xmm0
movups 0x70(%r14,%rbp,8),%xmm1
movupd %xmm0,0x60(%r9,%rbp,8)
movups %xmm1,0x70(%r9,%rbp,8)
add    $0x10,%rbp
add    $0xfffffffffffffffc,%rbx
jne    14b0 <CountSortedRowsDouble+0x3b0>
cmpq   $0x0,-0x18(%rsp)
je     155e <CountSortedRowsDouble+0x45e>
lea    (%r9,%rbp,8),%rbx
add    $0x10,%rbx
lea    (%r14,%rbp,8),%rbp
add    $0x10,%rbp
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movupd -0x10(%rbp,%rdi,1),%xmm0
movups 0x0(%rbp,%rdi,1),%xmm1
movupd %xmm0,-0x10(%rbx,%rdi,1)
movups %xmm1,(%rbx,%rdi,1)
add    $0x20,%rdi
cmp    %rdi,%r13
jne    1540 <CountSortedRowsDouble+0x440>
mov    -0x8(%rsp),%rdi
mov    %rdi,%r12
cmp    %r8,%rdi
je     1360 <CountSortedRowsDouble+0x260>
jmp    1415 <CountSortedRowsDouble+0x315>
add    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @CountSortedRowsDouble(i32 %0, i32 %1, double** %2, i32* %3, double** %4, i32* %5, i32* %6, i32* %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca double**
%12 = alloca i32*
%13 = alloca double**
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i32 %0, i32* %9
store i32 %1, i32* %10
store double** %2, double*** %11
store i32* %3, i32** %12
store double** %4, double*** %13
store i32* %5, i32** %14
store i32* %6, i32** %15
store i32* %7, i32** %16
store i32 0, i32* %19
br label %21
21: ; preds = %39, %8
%22 = load i32, i32* %19
%23 = load i32, i32* %10
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %42
25: ; preds = %21
%26 = load double**, double*** %11
%27 = getelementptr inbounds double*, double** %26, i64 0
%28 = load double*, double** %27
%29 = load i32, i32* %19
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = load double**, double*** %13
%34 = getelementptr inbounds double*, double** %33, i64 0
%35 = load double*, double** %34
%36 = load i32, i32* %19
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
store double %32, double* %38
br label %39
39: ; preds = %25
%40 = load i32, i32* %19
%41 = add nsw i32 %40, 1
store i32 %41, i32* %19
br label %21
42: ; preds = %21
%43 = load i32*, i32** %12
%44 = getelementptr inbounds i32, i32* %43, i64 0
%45 = load i32, i32* %44
%46 = load i32*, i32** %14
%47 = getelementptr inbounds i32, i32* %46, i64 0
store i32 %45, i32* %47
%48 = load i32*, i32** %16
%49 = getelementptr inbounds i32, i32* %48, i64 0
%50 = load i32, i32* %49
%51 = add nsw i32 %50, 1
store i32 %51, i32* %49
%52 = load i32*, i32** %15
%53 = load i32*, i32** %12
%54 = getelementptr inbounds i32, i32* %53, i64 0
%55 = load i32, i32* %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %52, i64 %56
store i32 0, i32* %57
store i32 0, i32* %18
store i32 1, i32* %17
br label %58
58: ; preds = %151, %42
%59 = load i32, i32* %17
%60 = load i32, i32* %9
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %154
62: ; preds = %58
store i32 0, i32* %20
br label %63
63: ; preds = %90, %62
%64 = load i32, i32* %20
%65 = load i32, i32* %10
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %93
67: ; preds = %63
%68 = load double**, double*** %11
%69 = load i32, i32* %17
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double*, double** %68, i64 %70
%72 = load double*, double** %71
%73 = load i32, i32* %20
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds double, double* %72, i64 %74
%76 = load double, double* %75
%77 = load double**, double*** %11
%78 = load i32, i32* %17
%79 = sub nsw i32 %78, 1
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds double*, double** %77, i64 %80
%82 = load double*, double** %81
%83 = load i32, i32* %20
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %82, i64 %84
%86 = load double, double* %85
%87 = fcmp une double %76, %86
br i1 %87, label %88, label %89
88: ; preds = %67
br label %93
89: ; preds = %67
br label %90
90: ; preds = %89
%91 = load i32, i32* %20
%92 = add nsw i32 %91, 1
store i32 %92, i32* %20
br label %63
93: ; preds = %88, %63
%94 = load i32, i32* %20
%95 = load i32, i32* %10
%96 = icmp slt i32 %94, %95
br i1 %96, label %97, label %135
97: ; preds = %93
%98 = load i32, i32* %18
%99 = add nsw i32 %98, 1
store i32 %99, i32* %18
store i32 0, i32* %19
br label %100
100: ; preds = %122, %97
%101 = load i32, i32* %19
%102 = load i32, i32* %10
%103 = icmp slt i32 %101, %102
br i1 %103, label %104, label %125
104: ; preds = %100
%105 = load double**, double*** %11
%106 = load i32, i32* %17
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds double*, double** %105, i64 %107
%109 = load double*, double** %108
%110 = load i32, i32* %19
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds double, double* %109, i64 %111
%113 = load double, double* %112
%114 = load double**, double*** %13
%115 = load i32, i32* %18
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds double*, double** %114, i64 %116
%118 = load double*, double** %117
%119 = load i32, i32* %19
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds double, double* %118, i64 %120
store double %113, double* %121
br label %122
122: ; preds = %104
%123 = load i32, i32* %19
%124 = add nsw i32 %123, 1
store i32 %124, i32* %19
br label %100
125: ; preds = %100
%126 = load i32*, i32** %12
%127 = load i32, i32* %17
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds i32, i32* %126, i64 %128
%130 = load i32, i32* %129
%131 = load i32*, i32** %14
%132 = load i32, i32* %18
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds i32, i32* %131, i64 %133
store i32 %130, i32* %134
br label %135
135: ; preds = %125, %93
%136 = load i32*, i32** %16
%137 = load i32, i32* %18
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds i32, i32* %136, i64 %138
%140 = load i32, i32* %139
%141 = add nsw i32 %140, 1
store i32 %141, i32* %139
%142 = load i32, i32* %18
%143 = load i32*, i32** %15
%144 = load i32*, i32** %12
%145 = load i32, i32* %17
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds i32, i32* %144, i64 %146
%148 = load i32, i32* %147
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds i32, i32* %143, i64 %149
store i32 %142, i32* %150
br label %151
151: ; preds = %135
%152 = load i32, i32* %17
%153 = add nsw i32 %152, 1
store i32 %153, i32* %17
br label %58
154: ; preds = %58
%155 = load i32, i32* %18
%156 = add nsw i32 %155, 1
store i32 %156, i32* %18
%157 = load i32, i32* %18
ret i32 %157
}

LLVM IR (-O2):
define i32 @CountSortedRowsDouble(i32 %0, i32 %1, double** nocapture %2, i32* nocapture %3, double** nocapture %4, i32* nocapture writeonly %5, i32* nocapture writeonly %6, i32* nocapture %7) {
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %137
10: ; preds = %8
%11 = load double*, double** %2
%12 = load double*, double** %4
%13 = zext i32 %1 to i64
%14 = icmp ult i32 %1, 4
br i1 %14, label %100, label %15
15: ; preds = %10
%16 = getelementptr double, double* %12, i64 %13
%17 = getelementptr double, double* %11, i64 %13
%18 = icmp ult double* %12, %17
%19 = icmp ult double* %11, %16
%20 = and i1 %18, %19
br i1 %20, label %100, label %21
21: ; preds = %15
%22 = and i64 %13, 4294967292
%23 = add nsw i64 %22, -4
%24 = lshr exact i64 %23, 2
%25 = add nuw nsw i64 %24, 1
%26 = and i64 %25, 3
%27 = icmp ult i64 %23, 12
br i1 %27, label %79, label %28
28: ; preds = %21
%29 = and i64 %25, 9223372036854775804
br label %30
30: ; preds = %30, %28
%31 = phi i64 [ 0, %28 ], [ %76, %30 ]
%32 = phi i64 [ 0, %28 ], [ %77, %30 ]
%33 = getelementptr inbounds double, double* %11, i64 %31
%34 = bitcast double* %33 to <2 x double>*
%35 = load <2 x double>, <2 x double>* %34
%36 = getelementptr inbounds double, double* %33, i64 2
%37 = bitcast double* %36 to <2 x double>*
%38 = load <2 x double>, <2 x double>* %37
%39 = getelementptr inbounds double, double* %12, i64 %31
%40 = bitcast double* %39 to <2 x double>*
store <2 x double> %35, <2 x double>* %40
%41 = getelementptr inbounds double, double* %39, i64 2
%42 = bitcast double* %41 to <2 x double>*
store <2 x double> %38, <2 x double>* %42
%43 = or i64 %31, 4
%44 = getelementptr inbounds double, double* %11, i64 %43
%45 = bitcast double* %44 to <2 x double>*
%46 = load <2 x double>, <2 x double>* %45
%47 = getelementptr inbounds double, double* %44, i64 2
%48 = bitcast double* %47 to <2 x double>*
%49 = load <2 x double>, <2 x double>* %48
%50 = getelementptr inbounds double, double* %12, i64 %43
%51 = bitcast double* %50 to <2 x double>*
store <2 x double> %46, <2 x double>* %51
%52 = getelementptr inbounds double, double* %50, i64 2
%53 = bitcast double* %52 to <2 x double>*
store <2 x double> %49, <2 x double>* %53
%54 = or i64 %31, 8
%55 = getelementptr inbounds double, double* %11, i64 %54
%56 = bitcast double* %55 to <2 x double>*
%57 = load <2 x double>, <2 x double>* %56
%58 = getelementptr inbounds double, double* %55, i64 2
%59 = bitcast double* %58 to <2 x double>*
%60 = load <2 x double>, <2 x double>* %59
%61 = getelementptr inbounds double, double* %12, i64 %54
%62 = bitcast double* %61 to <2 x double>*
store <2 x double> %57, <2 x double>* %62
%63 = getelementptr inbounds double, double* %61, i64 2
%64 = bitcast double* %63 to <2 x double>*
store <2 x double> %60, <2 x double>* %64
%65 = or i64 %31, 12
%66 = getelementptr inbounds double, double* %11, i64 %65
%67 = bitcast double* %66 to <2 x double>*
%68 = load <2 x double>, <2 x double>* %67
%69 = getelementptr inbounds double, double* %66, i64 2
%70 = bitcast double* %69 to <2 x double>*
%71 = load <2 x double>, <2 x double>* %70
%72 = getelementptr inbounds double, double* %12, i64 %65
%73 = bitcast double* %72 to <2 x double>*
store <2 x double> %68, <2 x double>* %73
%74 = getelementptr inbounds double, double* %72, i64 2
%75 = bitcast double* %74 to <2 x double>*
store <2 x double> %71, <2 x double>* %75
%76 = add nuw i64 %31, 16
%77 = add nuw i64 %32, 4
%78 = icmp eq i64 %77, %29
br i1 %78, label %79, label %30
79: ; preds = %30, %21
%80 = phi i64 [ 0, %21 ], [ %76, %30 ]
%81 = icmp eq i64 %26, 0
br i1 %81, label %98, label %82
82: ; preds = %79, %82
%83 = phi i64 [ %95, %82 ], [ %80, %79 ]
%84 = phi i64 [ %96, %82 ], [ 0, %79 ]
%85 = getelementptr inbounds double, double* %11, i64 %83
%86 = bitcast double* %85 to <2 x double>*
%87 = load <2 x double>, <2 x double>* %86
%88 = getelementptr inbounds double, double* %85, i64 2
%89 = bitcast double* %88 to <2 x double>*
%90 = load <2 x double>, <2 x double>* %89
%91 = getelementptr inbounds double, double* %12, i64 %83
%92 = bitcast double* %91 to <2 x double>*
store <2 x double> %87, <2 x double>* %92
%93 = getelementptr inbounds double, double* %91, i64 2
%94 = bitcast double* %93 to <2 x double>*
store <2 x double> %90, <2 x double>* %94
%95 = add nuw i64 %83, 4
%96 = add i64 %84, 1
%97 = icmp eq i64 %96, %26
br i1 %97, label %98, label %82
98: ; preds = %82, %79
%99 = icmp eq i64 %22, %13
br i1 %99, label %137, label %100
100: ; preds = %15, %10, %98
%101 = phi i64 [ 0, %15 ], [ 0, %10 ], [ %22, %98 ]
%102 = xor i64 %101, -1
%103 = add nsw i64 %102, %13
%104 = and i64 %13, 3
%105 = icmp eq i64 %104, 0
br i1 %105, label %115, label %106
106: ; preds = %100, %106
%107 = phi i64 [ %112, %106 ], [ %101, %100 ]
%108 = phi i64 [ %113, %106 ], [ 0, %100 ]
%109 = getelementptr inbounds double, double* %11, i64 %107
%110 = load double, double* %109
%111 = getelementptr inbounds double, double* %12, i64 %107
store double %110, double* %111
%112 = add nuw nsw i64 %107, 1
%113 = add i64 %108, 1
%114 = icmp eq i64 %113, %104
br i1 %114, label %115, label %106
115: ; preds = %106, %100
%116 = phi i64 [ %101, %100 ], [ %112, %106 ]
%117 = icmp ult i64 %103, 3
br i1 %117, label %137, label %118
118: ; preds = %115, %118
%119 = phi i64 [ %135, %118 ], [ %116, %115 ]
%120 = getelementptr inbounds double, double* %11, i64 %119
%121 = load double, double* %120
%122 = getelementptr inbounds double, double* %12, i64 %119
store double %121, double* %122
%123 = add nuw nsw i64 %119, 1
%124 = getelementptr inbounds double, double* %11, i64 %123
%125 = load double, double* %124
%126 = getelementptr inbounds double, double* %12, i64 %123
store double %125, double* %126
%127 = add nuw nsw i64 %119, 2
%128 = getelementptr inbounds double, double* %11, i64 %127
%129 = load double, double* %128
%130 = getelementptr inbounds double, double* %12, i64 %127
store double %129, double* %130
%131 = add nuw nsw i64 %119, 3
%132 = getelementptr inbounds double, double* %11, i64 %131
%133 = load double, double* %132
%134 = getelementptr inbounds double, double* %12, i64 %131
store double %133, double* %134
%135 = add nuw nsw i64 %119, 4
%136 = icmp eq i64 %135, %13
br i1 %136, label %137, label %118
137: ; preds = %115, %118, %98, %8
%138 = load i32, i32* %3
store i32 %138, i32* %5
%139 = load i32, i32* %7
%140 = add nsw i32 %139, 1
store i32 %140, i32* %7
%141 = load i32, i32* %3
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds i32, i32* %6, i64 %142
store i32 0, i32* %143
%144 = icmp sgt i32 %0, 1
br i1 %144, label %145, label %311
145: ; preds = %137
%146 = zext i32 %0 to i64
%147 = zext i32 %1 to i64
%148 = and i64 %147, 4294967292
%149 = add nsw i64 %148, -4
%150 = lshr exact i64 %149, 2
%151 = add nuw nsw i64 %150, 1
%152 = icmp ult i32 %1, 4
%153 = and i64 %147, 4294967292
%154 = and i64 %151, 3
%155 = icmp ult i64 %149, 12
%156 = and i64 %151, 9223372036854775804
%157 = icmp eq i64 %154, 0
%158 = icmp eq i64 %153, %147
%159 = and i64 %147, 3
%160 = icmp eq i64 %159, 0
br label %161
161: ; preds = %145, %299
%162 = phi i64 [ 1, %145 ], [ %309, %299 ]
%163 = phi i32 [ 0, %145 ], [ %300, %299 ]
br i1 %9, label %164, label %299
164: ; preds = %161
%165 = getelementptr inbounds double*, double** %2, i64 %162
%166 = load double*, double** %165
%167 = add nsw i64 %162, -1
%168 = getelementptr inbounds double*, double** %2, i64 %167
%169 = load double*, double** %168
br label %172
170: ; preds = %172
%171 = icmp eq i64 %179, %147
br i1 %171, label %299, label %172
172: ; preds = %164, %170
%173 = phi i64 [ 0, %164 ], [ %179, %170 ]
%174 = getelementptr inbounds double, double* %166, i64 %173
%175 = load double, double* %174
%176 = getelementptr inbounds double, double* %169, i64 %173
%177 = load double, double* %176
%178 = fcmp une double %175, %177
%179 = add nuw nsw i64 %173, 1
br i1 %178, label %180, label %170
180: ; preds = %172
%181 = add nsw i32 %163, 1
%182 = sext i32 %181 to i64
%183 = getelementptr inbounds double*, double** %4, i64 %182
%184 = load double*, double** %183
br i1 %152, label %260, label %185
185: ; preds = %180
%186 = getelementptr double, double* %184, i64 %147
%187 = getelementptr double, double* %166, i64 %147
%188 = icmp ult double* %184, %187
%189 = icmp ult double* %166, %186
%190 = and i1 %188, %189
br i1 %190, label %260, label %191
191: ; preds = %185
br i1 %155, label %241, label %192
192: ; preds = %191, %192
%193 = phi i64 [ %238, %192 ], [ 0, %191 ]
%194 = phi i64 [ %239, %192 ], [ 0, %191 ]
%195 = getelementptr inbounds double, double* %166, i64 %193
%196 = bitcast double* %195 to <2 x double>*
%197 = load <2 x double>, <2 x double>* %196
%198 = getelementptr inbounds double, double* %195, i64 2
%199 = bitcast double* %198 to <2 x double>*
%200 = load <2 x double>, <2 x double>* %199
%201 = getelementptr inbounds double, double* %184, i64 %193
%202 = bitcast double* %201 to <2 x double>*
store <2 x double> %197, <2 x double>* %202
%203 = getelementptr inbounds double, double* %201, i64 2
%204 = bitcast double* %203 to <2 x double>*
store <2 x double> %200, <2 x double>* %204
%205 = or i64 %193, 4
%206 = getelementptr inbounds double, double* %166, i64 %205
%207 = bitcast double* %206 to <2 x double>*
%208 = load <2 x double>, <2 x double>* %207
%209 = getelementptr inbounds double, double* %206, i64 2
%210 = bitcast double* %209 to <2 x double>*
%211 = load <2 x double>, <2 x double>* %210
%212 = getelementptr inbounds double, double* %184, i64 %205
%213 = bitcast double* %212 to <2 x double>*
store <2 x double> %208, <2 x double>* %213
%214 = getelementptr inbounds double, double* %212, i64 2
%215 = bitcast double* %214 to <2 x double>*
store <2 x double> %211, <2 x double>* %215
%216 = or i64 %193, 8
%217 = getelementptr inbounds double, double* %166, i64 %216
%218 = bitcast double* %217 to <2 x double>*
%219 = load <2 x double>, <2 x double>* %218
%220 = getelementptr inbounds double, double* %217, i64 2
%221 = bitcast double* %220 to <2 x double>*
%222 = load <2 x double>, <2 x double>* %221
%223 = getelementptr inbounds double, double* %184, i64 %216
%224 = bitcast double* %223 to <2 x double>*
store <2 x double> %219, <2 x double>* %224
%225 = getelementptr inbounds double, double* %223, i64 2
%226 = bitcast double* %225 to <2 x double>*
store <2 x double> %222, <2 x double>* %226
%227 = or i64 %193, 12
%228 = getelementptr inbounds double, double* %166, i64 %227
%229 = bitcast double* %228 to <2 x double>*
%230 = load <2 x double>, <2 x double>* %229
%231 = getelementptr inbounds double, double* %228, i64 2
%232 = bitcast double* %231 to <2 x double>*
%233 = load <2 x double>, <2 x double>* %232
%234 = getelementptr inbounds double, double* %184, i64 %227
%235 = bitcast double* %234 to <2 x double>*
store <2 x double> %230, <2 x double>* %235
%236 = getelementptr inbounds double, double* %234, i64 2
%237 = bitcast double* %236 to <2 x double>*
store <2 x double> %233, <2 x double>* %237
%238 = add nuw i64 %193, 16
%239 = add nuw i64 %194, 4
%240 = icmp eq i64 %239, %156
br i1 %240, label %241, label %192
241: ; preds = %192, %191
%242 = phi i64 [ 0, %191 ], [ %238, %192 ]
br i1 %157, label %259, label %243
243: ; preds = %241, %243
%244 = phi i64 [ %256, %243 ], [ %242, %241 ]
%245 = phi i64 [ %257, %243 ], [ 0, %241 ]
%246 = getelementptr inbounds double, double* %166, i64 %244
%247 = bitcast double* %246 to <2 x double>*
%248 = load <2 x double>, <2 x double>* %247
%249 = getelementptr inbounds double, double* %246, i64 2
%250 = bitcast double* %249 to <2 x double>*
%251 = load <2 x double>, <2 x double>* %250
%252 = getelementptr inbounds double, double* %184, i64 %244
%253 = bitcast double* %252 to <2 x double>*
store <2 x double> %248, <2 x double>* %253
%254 = getelementptr inbounds double, double* %252, i64 2
%255 = bitcast double* %254 to <2 x double>*
store <2 x double> %251, <2 x double>* %255
%256 = add nuw i64 %244, 4
%257 = add i64 %245, 1
%258 = icmp eq i64 %257, %154
br i1 %258, label %259, label %243
259: ; preds = %243, %241
br i1 %158, label %295, label %260
260: ; preds = %185, %180, %259
%261 = phi i64 [ 0, %185 ], [ 0, %180 ], [ %153, %259 ]
%262 = xor i64 %261, -1
%263 = add nsw i64 %262, %147
br i1 %160, label %273, label %264
264: ; preds = %260, %264
%265 = phi i64 [ %270, %264 ], [ %261, %260 ]
%266 = phi i64 [ %271, %264 ], [ 0, %260 ]
%267 = getelementptr inbounds double, double* %166, i64 %265
%268 = load double, double* %267
%269 = getelementptr inbounds double, double* %184, i64 %265
store double %268, double* %269
%270 = add nuw nsw i64 %265, 1
%271 = add i64 %266, 1
%272 = icmp eq i64 %271, %159
br i1 %272, label %273, label %264
273: ; preds = %264, %260
%274 = phi i64 [ %261, %260 ], [ %270, %264 ]
%275 = icmp ult i64 %263, 3
br i1 %275, label %295, label %276
276: ; preds = %273, %276
%277 = phi i64 [ %293, %276 ], [ %274, %273 ]
%278 = getelementptr inbounds double, double* %166, i64 %277
%279 = load double, double* %278
%280 = getelementptr inbounds double, double* %184, i64 %277
store double %279, double* %280
%281 = add nuw nsw i64 %277, 1
%282 = getelementptr inbounds double, double* %166, i64 %281
%283 = load double, double* %282
%284 = getelementptr inbounds double, double* %184, i64 %281
store double %283, double* %284
%285 = add nuw nsw i64 %277, 2
%286 = getelementptr inbounds double, double* %166, i64 %285
%287 = load double, double* %286
%288 = getelementptr inbounds double, double* %184, i64 %285
store double %287, double* %288
%289 = add nuw nsw i64 %277, 3
%290 = getelementptr inbounds double, double* %166, i64 %289
%291 = load double, double* %290
%292 = getelementptr inbounds double, double* %184, i64 %289
store double %291, double* %292
%293 = add nuw nsw i64 %277, 4
%294 = icmp eq i64 %293, %147
br i1 %294, label %295, label %276
295: ; preds = %273, %276, %259
%296 = getelementptr inbounds i32, i32* %3, i64 %162
%297 = load i32, i32* %296
%298 = getelementptr inbounds i32, i32* %5, i64 %182
store i32 %297, i32* %298
br label %299
299: ; preds = %170, %161, %295
%300 = phi i32 [ %181, %295 ], [ %163, %161 ], [ %163, %170 ]
%301 = sext i32 %300 to i64
%302 = getelementptr inbounds i32, i32* %7, i64 %301
%303 = load i32, i32* %302
%304 = add nsw i32 %303, 1
store i32 %304, i32* %302
%305 = getelementptr inbounds i32, i32* %3, i64 %162
%306 = load i32, i32* %305
%307 = sext i32 %306 to i64
%308 = getelementptr inbounds i32, i32* %6, i64 %307
store i32 %300, i32* %308
%309 = add nuw nsw i64 %162, 1
%310 = icmp eq i64 %309, %146
br i1 %310, label %311, label %161
311: ; preds = %299, %137
%312 = phi i32 [ 0, %137 ], [ %300, %299 ]
%313 = add nsw i32 %312, 1
ret i32 %313
}