// File: /workspace/github_c_makefile_star2_O3/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 0x40(%rsp), %r10
movq 0x38(%rsp), %r11
movl %ecx, %ebp
subl %esi, %ebp
movq %rcx, -0x68(%rsp)
jge 0xf871
testl %ecx, %ecx
jle 0xf892
movl %ecx, %r11d
xorl %r15d, %r15d
movb (%rdx,%r15), %r10b
cmpb (%rdi,%r15), %r10b
jne 0xf86a
incq %r15
cmpq %r15, %r11
jne 0xf855
movl %r11d, %r15d
movq -0x68(%rsp), %rcx
jmp 0xf8bb
testl %esi, %esi
jle 0xf897
movl %esi, %r14d
xorl %r15d, %r15d
movb (%rdx,%r15), %bl
cmpb (%rdi,%r15), %bl
jne 0xf89a
incq %r15
cmpq %r15, %r14
jne 0xf87b
movl %r14d, %r15d
jmp 0xf89a
xorl %r15d, %r15d
jmp 0xf8bb
xorl %r15d, %r15d
cmpl %esi, %r15d
setl %al
movq -0x68(%rsp), %rcx
cmpl %esi, %ecx
setne %bl
orb %al, %bl
jne 0xf8bb
movl %ecx, (%r10)
movl %ecx, (%r11)
xorl %eax, %eax
jmp 0xfc14
movslq %ebp, %r14
movq %rdi, %r12
subq %r14, %r12
leal -0x1(%rcx), %ebp
movl %r15d, (%r8)
movl $0xfffffffe, -0x4(%r8)  # imm = 0xFFFFFFFE
movslq %ecx, %rax
movq %rax, -0x10(%rsp)
cmpl %esi, %ecx
jle 0xf918
movl %ebp, %ecx
testl %esi, %esi
jle 0xf934
cmpl %ebp, %r14d
movl %ebp, %eax
cmovll %r14d, %eax
decl %eax
movq %r14, %r10
notq %r10
addq %rdi, %r10
movl %ebp, %ecx
movq -0x10(%rsp), %r11
movb -0x1(%rdx,%r11), %bl
cmpb (%r10,%r11), %bl
jne 0xf934
decq %r11
decl %ecx
cmpq %r14, %r11
jg 0xf8ff
movl %eax, %ecx
jmp 0xf934
testl %ecx, %ecx
jle 0xf92f
movl %ecx, %eax
leal -0x1(%rax), %ecx
movb (%rdx,%rcx), %r10b
cmpb (%r12,%rcx), %r10b
jne 0xf934
decl %eax
jg 0xf91e
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %r12, -0x28(%rsp)
movl %r14d, %eax
negl %eax
leaq (%r9,%r14,4), %r9
movslq %eax, %r10
movl %ecx, (%r9,%r10,4)
movq -0x68(%rsp), %rax
leal 0x1(%rax), %r11d
notl %r14d
movslq %r14d, %rcx
movq %r9, -0x58(%rsp)
movl %r11d, -0x5c(%rsp)
movl %r11d, (%r9,%rcx,4)
movl %esi, %ecx
subl %eax, %ecx
incl %ecx
subl %esi, %ebp
movl $0x1, %eax
xorl %r11d, %r11d
movq %r10, -0x50(%rsp)
movq %r10, -0x48(%rsp)
movq %rdi, -0x20(%rsp)
decl %esi
movl %ecx, -0x34(%rsp)
movslq %ecx, %rcx
movq %rcx, -0x8(%rsp)
movl %ebp, -0x30(%rsp)
movslq %ebp, %rbp
leaq -0x1(%r11), %rcx
movq %rcx, -0x18(%rsp)
movl $0xfffffffe, -0x8(%r8,%r11,4) # imm = 0xFFFFFFFE
movq %rax, %r13
addq %rdi, %rax
movl %esi, -0x2c(%rsp)
movslq %esi, %rdi
movl $0xfffffffe, %r10d      # imm = 0xFFFFFFFE
movq %r13, -0x40(%rsp)
movl $0xfffffffe, %r14d      # imm = 0xFFFFFFFE
movq -0x68(%rsp), %rsi
movl %r14d, %r9d
movl %r10d, %ebx
leal 0x1(%r9), %r10d
movq %r8, %r12
movl -0x4(%r8,%r13,4), %r14d
cmpl %r14d, %ebx
movl %r14d, %r15d
cmovgl %ebx, %r15d
cmpl %r9d, %ebx
movl %r10d, %ecx
cmovgl %ebx, %ecx
cmpl %r14d, %r10d
cmovll %r15d, %ecx
cmpq %r13, -0x48(%rsp)
setg %r15b
cmpq -0x50(%rsp), %r13
setg %r8b
orb %r15b, %r8b
jne 0xfa24
movq -0x58(%rsp), %r8
movl (%r8,%r13,4), %r15d
cmpl %r15d, %ecx
jg 0xfbb9
cmpq -0x10(%rsp), %rdi
jle 0xfa4a
cmpl %esi, %ecx
movq %r12, %r8
jge 0xfa6a
movslq %ecx, %rcx
movb (%rdx,%rcx), %r9b
cmpb (%rax,%rcx), %r9b
jne 0xfa6a
incq %rcx
cmpl %ecx, %esi
jne 0xfa35
movl %esi, %ecx
jmp 0xfa6a
movslq %ecx, %r9
cmpq %r9, %rdi
movq %r12, %r8
jle 0xfa6a
movb (%rdx,%r9), %cl
cmpb (%rax,%r9), %cl
jne 0xfa67
incq %r9
cmpq %rdi, %r9
jl 0xfa55
movl %r9d, %ecx
movl %ecx, (%r8,%r13,4)
decq %rax
incq %rdi
leaq -0x1(%r13), %rcx
cmpq %r11, %r13
movq %rcx, %r13
jge 0xf9cf
movq -0x50(%rsp), %rcx
incq %rcx
movq -0x48(%rsp), %rsi
leaq -0x1(%rsi), %r15
movq -0x58(%rsp), %r10
movl -0x5c(%rsp), %eax
movl %eax, -0x8(%r10,%rsi,4)
movq %rcx, -0x50(%rsp)
cmpq %r15, %rcx
movq -0x40(%rsp), %rax
movq -0x8(%rsp), %r11
jl 0xfb8d
movq -0x20(%rsp), %rax
movq -0x50(%rsp), %rcx
leaq (%rax,%rcx), %r12
movq -0x40(%rsp), %rax
movq -0x28(%rsp), %r13
movl -0x5c(%rsp), %ebx
movl %ebx, %ecx
movl %ebx, %esi
leal 0x1(%rcx), %r9d
movl -0x4(%r10,%r11,4), %ebx
cmpl %ebx, %ecx
movl %ebx, %r10d
cmovll %r9d, %r10d
cmpl %esi, %ecx
movl %esi, %edi
cmovll %r9d, %edi
cmpl %ebx, %esi
cmovgl %r10d, %edi
cmpq %r11, -0x18(%rsp)
setg %r14b
cmpq %rax, %r11
setg %r10b
orb %r14b, %r10b
jne 0xfb1d
movl (%r8,%r11,4), %r10d
cmpl %r10d, %edi
jle 0xfbec
leal -0x1(%rdi), %ecx
testq %rbp, %rbp
jle 0xfb4d
movslq %edi, %rdi
cmpq %rdi, %rbp
movq -0x58(%rsp), %r10
jge 0xfb6c
movb -0x1(%rdx,%rdi), %cl
cmpb (%r13,%rdi), %cl
jne 0xfb45
decq %rdi
cmpq %rbp, %rdi
jg 0xfb32
decq %rdi
movq %rdi, %rcx
jmp 0xfb6c
testl %edi, %edi
movq -0x58(%rsp), %r10
jle 0xfb6c
leal -0x1(%rdi), %ecx
movb (%rdx,%rcx), %r9b
cmpb (%r12,%rcx), %r9b
jne 0xfb6c
decl %edi
jg 0xfb56
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, (%r10,%r11,4)
decq %r12
incq %rbp
leaq -0x1(%r11), %rdi
decq %r13
movl %esi, %ecx
cmpq -0x48(%rsp), %r11
movq %rdi, %r11
jge 0xfad9
incq %rax
movl -0x34(%rsp), %ecx
incl %ecx
movl -0x30(%rsp), %ebp
decl %ebp
incq -0x28(%rsp)
movq %r15, -0x48(%rsp)
movq -0x18(%rsp), %r11
movl -0x2c(%rsp), %esi
movq -0x20(%rsp), %rdi
jmp 0xf985
leal 0x1(%r15), %eax
cmpl %r15d, %r9d
cmovll %eax, %r10d
cmpl %r15d, %ebx
cmovgl %ebx, %r10d
movq -0x40(%rsp), %rcx
leal -0x1(,%rcx,2), %ecx
addl %r10d, %r13d
movq 0x38(%rsp), %rax
movl %r13d, (%rax)
movq 0x40(%rsp), %rax
movl %r10d, (%rax)
jmp 0xfc11
addl %eax, %eax
cmpl %r10d, %esi
cmovgel %r10d, %esi
cmpl %r10d, %ecx
cmovll %r9d, %esi
addl %esi, %r11d
movq %rax, %rcx
movq 0x38(%rsp), %rax
movl %r11d, (%rax)
movq 0x40(%rsp), %rax
movl %esi, (%rax)
movq %rcx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq