// File: /workspace/github_c_makefile_star2_O0/thegenemyers[P]DAMASKER/tandem.c
// Function: lex_sort
static Double *lex_sort(int bytes[16], Double *src, Double *trg, Lex_Arg *parmx)
{ THREAD  threads[NTHREADS];

  int64   len, x, y;
  Double *xch;
  int     i, j, k, z;
  int     b, c, fb;

  len       = parmx[NTHREADS-1].end;
  LEX_zsize = (len-1)/NTHREADS + 1;
  LEX_src   = src;
  LEX_trg   = trg;
  QMASK     = (BMASK << NSHIFT);

  for (c = 0; c < 16; c++)
    if (bytes[c])
      break;
  fb = c;
  for (b = c; b < 16; b = c)
    { for (c = b+1; c < 16; c++)
        if (bytes[c])
          break;
      LEX_last  = (c >= 16);
      LEX_shift = (b << 3);
      LEX_next  = (c << 3);
 
      if (b == fb)
        { for (i = 0; i < NTHREADS; i++)
            for (z = 0; z < NTHREADS*BPOWR; z++)
              parmx[i].sptr[z] = 0;
        }
      else
        { x = 0;
          for (i = 0; i < NTHREADS; i++)
            { parmx[i].beg = x;
              x = LEX_zsize*(i+1);
              if (x > len)
                x = len;
              parmx[i].end = x;
              for (j = 0; j < BPOWR; j++)
                parmx[i].tptr[j] = 0;
            }
          parmx[NTHREADS-1].end = len;

          for (j = 0; j < BPOWR; j++)
            { k = (j << NSHIFT);
              for (z = 0; z < NTHREADS; z++)
                for (i = 0; i < NTHREADS; i++)
                  { parmx[i].tptr[j] += parmx[z].sptr[k+i];
                    parmx[z].sptr[k+i] = 0;
                  }
            }
        }

      x = 0;
      for (j = 0; j < BPOWR; j++)
        for (i = 0; i < NTHREADS; i++)
          { y = parmx[i].tptr[j];
            parmx[i].tptr[j] = x;
            x += y;
          }

      for (i = 0; i < NTHREADS; i++)
        pthread_create(threads+i,NULL,lex_thread,parmx+i);

      for (i = 0; i < NTHREADS; i++)
        pthread_join(threads[i],NULL);

      xch     = LEX_src;
      LEX_src = LEX_trg;
      LEX_trg = xch;

#ifdef TEST_LSORT
      printf("\nLSORT %d\n",LEX_shift);
      if (LEX_shift >= 64)
        { x = (1 << ((LEX_shift-64)+BSHIFT))-1;
          for (i = 0; i < len; i++)
            { printf("%6d: %8llx %8llx %8llx %8llx : %4llx",
                     i,LEX_src[i].p2>>32,(LEX_src[i].p2)&0xffffffffll,LEX_src[i].p1>>32,
                     LEX_src[i].p1&0xffffffffll,LEX_src[i].p2&x);
              if (i > 0 && (LEX_src[i].p1 < LEX_src[i].p1 ||
                             (LEX_src[i].p1 == LEX_src[i].p1 && 
                             (LEX_src[i].p2 & x) < (LEX_src[i-1].p2 & x))))
                printf(" OO");
              printf("\n");
            }
        }
      else
        { x = (1 << (LEX_shift+BSHIFT))-1;
          for (i = 0; i < len; i++)
            { printf("%6d: %8llx %8llx %8llx %8llx : %4llx",
                     i,LEX_src[i].p2>>32,(LEX_src[i].p2)&0xffffffffll,LEX_src[i].p1>>32,
                     LEX_src[i].p1&0xffffffffll,LEX_src[i].p1&x);
              if (i > 0 && (LEX_src[i].p1 & x) < (LEX_src[i-1].p1 & x))
                printf(" OO");
              printf("\n");
            }
        }
#endif
    }

  return (LEX_src);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl 0x295f7(%rip), %eax     # 0x2e448
movq %rsp, %rcx
movq %rcx, -0x28(%rbp)
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x78(%rbp)
movq %rcx, %rsp
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movl 0x295c9(%rip), %ecx     # 0x2e448
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x818, %rcx, %rcx      # imm = 0x818
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
subq $0x1, %rax
movslq 0x295a2(%rip), %rcx     # 0x2e448
cqto
idivq %rcx
addq $0x1, %rax
movq %rax, 0x295ca(%rip)     # 0x2e480
movq -0x10(%rbp), %rax
movq %rax, 0x295c7(%rip)     # 0x2e488
movq -0x18(%rbp), %rax
movq %rax, 0x295c4(%rip)     # 0x2e490
movl 0x2957a(%rip), %eax     # 0x2e44c
movl %eax, %ecx
movl $0xff, %eax
shlq %cl, %rax
movq %rax, 0x295b5(%rip)     # 0x2e498
movl $0x0, -0x68(%rbp)
cmpl $0x10, -0x68(%rbp)
jge 0x4f0d
movq -0x8(%rbp), %rax
movslq -0x68(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x4f00
jmp 0x4f0d
jmp 0x4f02
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x4eea
movl -0x68(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0x64(%rbp)
cmpl $0x10, -0x64(%rbp)
jge 0x52f8
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
cmpl $0x10, -0x68(%rbp)
jge 0x4f4f
movq -0x8(%rbp), %rax
movslq -0x68(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x4f42
jmp 0x4f4f
jmp 0x4f44
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x4f2c
cmpl $0x10, -0x68(%rbp)
setge %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x2953f(%rip)     # 0x2e4a0
movl -0x64(%rbp), %eax
shll $0x3, %eax
movl %eax, 0x29537(%rip)     # 0x2e4a4
movl -0x68(%rbp), %eax
shll $0x3, %eax
movl %eax, 0x2952f(%rip)     # 0x2e4a8
movl -0x64(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jne 0x4fec
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl 0x294b7(%rip), %eax     # 0x2e448
jge 0x4fe7
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl 0x294a5(%rip), %ecx     # 0x2e448
shll $0x8, %ecx
cmpl %ecx, %eax
jge 0x4fda
movq -0x20(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x818, %rcx, %rcx      # imm = 0x818
addq %rcx, %rax
movq 0x810(%rax), %rax
movslq -0x60(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x4f9a
jmp 0x4fdc
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x4f88
jmp 0x51bd
movq $0x0, -0x40(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl 0x29444(%rip), %eax     # 0x2e448
jge 0x50b1
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movslq -0x54(%rbp), %rdx
imulq $0x818, %rdx, %rdx      # imm = 0x818
addq %rdx, %rax
movq %rcx, (%rax)
movq 0x29456(%rip), %rax     # 0x2e480
movl -0x54(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
imulq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jle 0x504d
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movslq -0x54(%rbp), %rdx
imulq $0x818, %rdx, %rdx      # imm = 0x818
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x58(%rbp)
cmpl $0x100, -0x58(%rbp)     # imm = 0x100
jge 0x50a1
movq -0x20(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x818, %rcx, %rcx      # imm = 0x818
addq %rcx, %rax
movslq -0x58(%rbp), %rcx
movq $0x0, 0x10(%rax,%rcx,8)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x506e
jmp 0x50a3
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x4ffb
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movl 0x29389(%rip), %edx     # 0x2e448
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x818, %rdx, %rdx      # imm = 0x818
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x58(%rbp)
cmpl $0x100, -0x58(%rbp)     # imm = 0x100
jge 0x51bb
movl -0x58(%rbp), %eax
movl 0x2935c(%rip), %ecx     # 0x2e44c
shll %cl, %eax
movl %eax, -0x5c(%rbp)
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl 0x29343(%rip), %eax     # 0x2e448
jge 0x51ab
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl 0x2932d(%rip), %eax     # 0x2e448
jge 0x519b
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
imulq $0x818, %rcx, %rcx      # imm = 0x818
addq %rcx, %rax
movq 0x810(%rax), %rax
movl -0x5c(%rbp), %ecx
addl -0x54(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x818, %rcx, %rcx      # imm = 0x818
addq %rcx, %rax
movslq -0x58(%rbp), %rcx
addq 0x10(%rax,%rcx,8), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
imulq $0x818, %rcx, %rcx      # imm = 0x818
addq %rcx, %rax
movq 0x810(%rax), %rax
movl -0x5c(%rbp), %ecx
addl -0x54(%rbp), %ecx
movslq %ecx, %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x5112
jmp 0x519d
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x50fc
jmp 0x51ad
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x50da
jmp 0x51bd
movq $0x0, -0x40(%rbp)
movl $0x0, -0x58(%rbp)
cmpl $0x100, -0x58(%rbp)     # imm = 0x100
jge 0x5249
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl 0x29263(%rip), %eax     # 0x2e448
jge 0x523c
movq -0x20(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x818, %rcx, %rcx      # imm = 0x818
addq %rcx, %rax
movslq -0x58(%rbp), %rcx
movq 0x10(%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdx
movq -0x20(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x818, %rcx, %rcx      # imm = 0x818
addq %rcx, %rax
movslq -0x58(%rbp), %rcx
movq %rdx, 0x10(%rax,%rcx,8)
movq -0x48(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x51dc
jmp 0x523e
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x51cc
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl 0x291ef(%rip), %eax     # 0x2e448
jge 0x5297
movq -0x78(%rbp), %rdi
movslq -0x54(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rcx
movslq -0x54(%rbp), %rax
imulq $0x818, %rax, %rax      # imm = 0x818
addq %rax, %rcx
xorl %eax, %eax
movl %eax, %esi
leaq 0xf09(%rip), %rdx       # 0x6190
callq 0x2270
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x5250
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl 0x291a1(%rip), %eax     # 0x2e448
jge 0x52c9
movq -0x78(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x22f0
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x529e
movq 0x291b8(%rip), %rax     # 0x2e488
movq %rax, -0x50(%rbp)
movq 0x291b5(%rip), %rax     # 0x2e490
movq %rax, 0x291a6(%rip)     # 0x2e488
movq -0x50(%rbp), %rax
movq %rax, 0x291a3(%rip)     # 0x2e490
movl -0x68(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x4f19
movq 0x29189(%rip), %rax     # 0x2e488
movq -0x28(%rbp), %rcx
movq %rcx, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax,%rax)