// File: /workspace/github_c_makefile_star2_O2/thegenemyers[P]DASCRUBBER/align.c
// Function: split_nd
static int split_nd(char *A, int M, char *B, int N, Trace_Waves *wave, int *px, int *py)
{ int x, y;
  int D;

  int  *VF = wave->VF;
  int  *VB = wave->VB;
  int   flow;  //  fhgh == D !
  int   blow, bhgh;
  char *a;

  y = 0;
  if (N < M)
    while (y < N && B[y] == A[y])
      y += 1;
  else
    { while (y < M && B[y] == A[y])
        y += 1;
      if (y >= M && N == M)
        { *px = *py = M;
          return (0);
        }
    }

  flow   = 0;
  VF[0]  = y;
  VF[-1] = -2;

  x = N-M;
  a = A-x;
  y = N-1;
  if (N > M)
    while (y >= x && B[y] == a[y])
      y -= 1;
  else
    while (y >= 0 && B[y] == a[y])
      y -= 1;

  blow = bhgh = -x;
  VB += x;
  VB[blow]   = y;
  VB[blow-1] = N+1;

  for (D = 1; 1; D += 1)
    { int   k, r;
      int   am, ac, ap;

      //  Forward wave

      flow -= 1;
      am = ac = VF[flow-1] = -2;

      a = A + D;
      x = M - D;
      for (k = D; k >= flow; k--)
        { ap = ac;
          ac = am+1;
          am = VF[k-1];

          if (ac < am)
            if (ap < am)
              y  = am;
            else
              y = ap;
          else
            if (ap < ac)
              y = ac;
            else
              y = ap;

          if (blow <= k && k <= bhgh)
            { r = VB[k];
              if (y > r)
                { D = (D<<1)-1;
                  if (ap > r)
                    y = ap;
                  else if (ac > r)
                    y = ac;
                  else
                    y = r+1;
                  x = k+y;
                  *px = x;
                  *py = y;
                  return (D);
                }
            }

          if (N < x)
            while (y < N && B[y] == a[y])
              y += 1;
          else
            while (y < x && B[y] == a[y])
              y += 1;
          
          VF[k] = y;
          a -= 1;
          x += 1;
        }

#ifdef DEBUG_AWAVE
      print_awave(VF,flow,D);
#endif

      //  Reverse Wave

      bhgh += 1;
      blow -= 1;
	am = ac = VB[blow-1] = N+1;

      a = A + bhgh;
      x = -bhgh;
      for (k = bhgh; k >= blow; k--)
        { ap = ac+1;
          ac = am;
          am = VB[k-1];

          if (ac > am)
            if (ap > am)
              y  = am;
            else
              y = ap;
          else
            if (ap > ac)
              y = ac;
            else
              y = ap;

          if (flow <= k && k <= D)
            { r = VF[k];
	        if (y <= r)
                { D = (D << 1);
                  if (ap <= r)
                    y = ap;
                  else if (ac <= r)
                    y = ac;
                  else
                    y = r;
                  x = k+y;
                  *px = x;
                  *py = y;
                  return (D);
                }
            }

          y -= 1;
          if (x > 0)
            while (y >= x && B[y] == a[y])
              y -= 1;
          else
            while (y >= 0 && B[y] == a[y])
              y -= 1;

          VB[k] = y;
          a -= 1;
          x += 1;
        }

#ifdef DEBUG_AWAVE
      print_awave(VB,blow,bhgh);
#endif
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x38(%rsp), %r10
movq 0x38(%r8), %r15
movq 0x40(%r8), %rax
movl %ecx, %r11d
subl %esi, %r11d
jge 0xe356
xorl %r10d, %r10d
testl %ecx, %ecx
movl $0x0, %ebx
cmovgl %ecx, %ebx
cmpq %r10, %rbx
je 0xe39d
movb (%rdx,%r10), %r8b
cmpb (%rdi,%r10), %r8b
jne 0xe377
incq %r10
jmp 0xe342
xorl %r14d, %r14d
testl %esi, %esi
movl $0x0, %ebx
cmovgl %esi, %ebx
cmpq %r14, %rbx
je 0xe37f
movb (%rdx,%r14), %r8b
cmpb (%rdi,%r14), %r8b
jne 0xe37c
incq %r14
jmp 0xe363
movl %r10d, %ebx
jmp 0xe39d
movl %r14d, %ebx
cmpl %esi, %ebx
setl %bpl
cmpl %esi, %ecx
setne %r8b
orb %bpl, %r8b
jne 0xe39d
movl %ecx, (%r10)
movl %ecx, (%r9)
xorl %edx, %edx
jmp 0xe6cf
movslq %r11d, %r14
leal -0x1(%rcx), %ebp
movl %ebx, (%r15)
movq %r15, -0x38(%rsp)
movl $0xfffffffe, -0x4(%r15) # imm = 0xFFFFFFFE
cmpl %esi, %ecx
movq %r9, -0x18(%rsp)
movq %rdi, -0x10(%rsp)
jle 0xe3f8
movslq %ecx, %rbx
movslq %esi, %r8
leaq (%r8,%rdi), %r12
decq %r12
movl %ebp, %r9d
movq %rbx, %r8
movl %r9d, %r15d
cmpq %r14, %r8
jle 0xe424
movb -0x1(%rdx,%r8), %r10b
leal -0x1(%r15), %r9d
leaq -0x1(%r12), %r11
decq %r8
cmpb (%r12), %r10b
movq %r11, %r12
je 0xe3d4
jmp 0xe424
movq %rdi, %r12
subq %r14, %r12
movslq %ecx, %rbx
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %ebp, %r8d
testl %r8d, %r8d
js 0xe424
movl %r8d, %r11d
movb (%rdx,%r11), %r10b
cmpb (%r12,%r11), %r10b
jne 0xe421
decl %r8d
jmp 0xe40a
movl %r8d, %r15d
movl %r14d, %edi
negl %edi
leaq (%rax,%r14,4), %r8
movslq %edi, %rdi
movl %r15d, (%r8,%rdi,4)
leal 0x1(%rcx), %r9d
notl %r14d
movslq %r14d, %rax
movq %r8, -0x40(%rsp)
movl %r9d, -0x28(%rsp)
movl %r9d, (%r8,%rax,4)
subl %esi, %ebp
movl %esi, %eax
movq %rcx, -0x8(%rsp)
subl %ecx, %eax
incl %eax
movabsq $0x1, %r11
xorl %r13d, %r13d
movl $0xfffffffe, %r9d       # imm = 0xFFFFFFFE
movq %rdi, -0x30(%rsp)
movq %rdi, -0x48(%rsp)
movq -0x38(%rsp), %r14
decl %esi
movl %ebp, -0x20(%rsp)
movslq %ebp, %rbp
movl %eax, -0x24(%rsp)
movslq %eax, %r10
movl %esi, -0x1c(%rsp)
movslq %esi, %r12
movl $0xfffffffe, -0x8(%r14,%r13,4) # imm = 0xFFFFFFFE
decq %r13
movq -0x10(%rsp), %rax
leaq (%rax,%r11), %rsi
movq %r11, -0x50(%rsp)
movq %r11, %rax
movl %r9d, %edi
cmpq %r13, %rax
jl 0xe568
movl %r9d, %ecx
movl %edi, %r11d
leal 0x1(%r11), %r9d
movl -0x4(%r14,%rax,4), %edi
cmpl %edi, %ecx
movl %edi, %r14d
cmovgl %ecx, %r14d
cmpl %r11d, %ecx
movl %r9d, %r8d
cmovgl %ecx, %r8d
cmpl %edi, %r9d
cmovll %r14d, %r8d
cmpq %rax, -0x48(%rsp)
setg %r14b
cmpq -0x30(%rsp), %rax
setg %r15b
orb %r14b, %r15b
jne 0xe50d
movq -0x40(%rsp), %r14
movl (%r14,%rax,4), %r14d
cmpl %r14d, %r8d
jg 0xe676
movslq %r8d, %rcx
cmpq %rbx, %r12
jle 0xe53a
movq -0x8(%rsp), %r11
cmpl %r11d, %r8d
cmovlel %r11d, %r8d
movq -0x38(%rsp), %r14
cmpq %rbx, %rcx
jge 0xe553
movb (%rdx,%rcx), %r11b
cmpb (%rsi,%rcx), %r11b
jne 0xe556
incq %rcx
jmp 0xe526
movq -0x38(%rsp), %r14
cmpq %r12, %rcx
jge 0xe556
movb (%rdx,%rcx), %r8b
cmpb (%rsi,%rcx), %r8b
jne 0xe556
incq %rcx
jmp 0xe53f
movl %r8d, %ecx
movl %ecx, (%r14,%rax,4)
decq %rsi
incq %r12
decq %rax
jmp 0xe4b2
movq -0x40(%rsp), %rax
movl -0x28(%rsp), %edi
movq -0x48(%rsp), %rcx
movl %edi, -0x8(%rax,%rcx,4)
decq %rcx
movq %rcx, -0x48(%rsp)
movq -0x10(%rsp), %rax
movq -0x30(%rsp), %rcx
leaq (%rax,%rcx), %r12
incq %r12
incq %rcx
movq %rcx, -0x30(%rsp)
movl %edi, %esi
movl %edi, %eax
movq -0x50(%rsp), %r11
cmpq -0x48(%rsp), %r10
jl 0xe658
movl %eax, %edi
movl %esi, %eax
leal 0x1(%rdi), %r8d
movq -0x40(%rsp), %rcx
movl -0x4(%rcx,%r10,4), %esi
cmpl %esi, %edi
movl %esi, %r9d
cmovll %r8d, %r9d
cmpl %eax, %edi
movl %eax, %ecx
cmovll %r8d, %ecx
cmpl %esi, %eax
cmovgl %r9d, %ecx
cmpq %r10, %r13
setg %r9b
cmpq %r11, %r10
setg %r11b
orb %r9b, %r11b
jne 0xe5f8
movl (%r14,%r10,4), %r9d
cmpl %r9d, %ecx
jle 0xe6a8
decl %ecx
testq %rbp, %rbp
jle 0xe61a
movslq %ecx, %rdi
movq -0x50(%rsp), %r11
cmpq %rbp, %rdi
jl 0xe641
movb (%rdx,%rdi), %cl
cmpb (%r12,%rdi), %cl
jne 0xe641
decq %rdi
jmp 0xe607
cmpl $-0x1, %ecx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
cmovll %ecx, %edi
movq -0x50(%rsp), %r11
testl %ecx, %ecx
js 0xe641
movl %ecx, %r8d
movb (%rdx,%r8), %r9b
cmpb (%r12,%r8), %r9b
jne 0xe63f
decl %ecx
jmp 0xe62a
movl %ecx, %edi
movq -0x40(%rsp), %rcx
movl %edi, (%rcx,%r10,4)
decq %r12
incq %rbp
decq %r10
jmp 0xe5a4
incq %r11
movl -0x20(%rsp), %ebp
decl %ebp
movl -0x24(%rsp), %eax
incl %eax
movl -0x1c(%rsp), %esi
movl $0xfffffffe, %r9d       # imm = 0xFFFFFFFE
jmp 0xe47b
leal 0x1(%r14), %edx
cmpl %r14d, %r11d
cmovll %edx, %r9d
cmpl %r14d, %ecx
cmovgl %ecx, %r9d
movq -0x50(%rsp), %rdx
leal -0x1(,%rdx,2), %edx
addl %r9d, %eax
movq -0x18(%rsp), %rcx
movl %eax, (%rcx)
movq 0x38(%rsp), %rax
movl %r9d, (%rax)
jmp 0xe6cf
movq -0x50(%rsp), %rdx
addl %edx, %edx
cmpl %r9d, %eax
cmovgel %r9d, %eax
cmpl %r9d, %edi
cmovll %r8d, %eax
addl %eax, %r10d
movq -0x18(%rsp), %rcx
movl %r10d, (%rcx)
movq 0x38(%rsp), %rcx
movl %eax, (%rcx)
movl %edx, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq