// File: /workspace/github_c_makefile_star2_O1/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 %r9, -0x10(%rsp)
movl %ecx, %r12d
movq %rdi, -0x50(%rsp)
movq 0x38(%r8), %r11
movq 0x40(%r8), %rax
movl %ecx, %r9d
subl %esi, %r9d
jge 0xfa8c
testl %r12d, %r12d
jle 0xfaaf
movl %r12d, %ecx
xorl %edi, %edi
movq -0x50(%rsp), %r10
movb (%rdx,%rdi), %r8b
cmpb (%r10,%rdi), %r8b
jne 0xfae1
incq %rdi
cmpq %rdi, %rcx
jne 0xfa76
movl %ecx, %edi
jmp 0xfae1
testl %esi, %esi
jle 0xfab3
movl %esi, %ecx
xorl %edi, %edi
movq -0x50(%rsp), %r10
movb (%rdx,%rdi), %r8b
cmpb (%r10,%rdi), %r8b
jne 0xfab5
incq %rdi
cmpq %rdi, %rcx
jne 0xfa99
movl %ecx, %edi
jmp 0xfab5
xorl %edi, %edi
jmp 0xfae1
xorl %edi, %edi
cmpl %esi, %edi
setl %cl
cmpl %esi, %r12d
setne %r8b
orb %cl, %r8b
jne 0xfae1
movq 0x38(%rsp), %rax
movl %esi, (%rax)
movq -0x10(%rsp), %rax
movl %esi, (%rax)
movl $0x0, -0x34(%rsp)
jmp 0xfe1f
movq %r11, %rcx
movslq %r9d, %r11
movl %edi, (%rcx)
movq %rcx, -0x48(%rsp)
movl $0xfffffffe, -0x4(%rcx) # imm = 0xFFFFFFFE
movslq %r12d, %rcx
movq %rcx, -0x8(%rsp)
cmpl %esi, %r12d
movl %esi, -0x18(%rsp)
jle 0xfb43
leal -0x1(%r12), %edi
testl %esi, %esi
jle 0xfb6b
cmpl %edi, %r11d
movl %edi, %ecx
cmovll %r11d, %ecx
decl %ecx
movq %r11, %r8
notq %r8
addq -0x50(%rsp), %r8
movq -0x8(%rsp), %r9
movb -0x1(%rdx,%r9), %r10b
cmpb (%r8,%r9), %r10b
jne 0xfb6b
decq %r9
decl %edi
cmpq %r11, %r9
jg 0xfb2a
movl %ecx, %edi
jmp 0xfb6b
testl %r12d, %r12d
jle 0xfb66
movq -0x50(%rsp), %rcx
subq %r11, %rcx
movl %r12d, %r8d
leal -0x1(%r8), %edi
movb (%rdx,%rdi), %r9b
cmpb (%rcx,%rdi), %r9b
jne 0xfb6b
decl %r8d
jg 0xfb53
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl %r11d, %ecx
negl %ecx
leaq (%rax,%r11,4), %rbx
movslq %ecx, %rax
movl %edi, (%rbx,%rax,4)
leal 0x1(%r12), %esi
notl %r11d
movslq %r11d, %rax
movl %esi, -0x14(%rsp)
movl %esi, (%rbx,%rax,4)
movl $0x1, %esi
movq $0x0, -0x20(%rsp)
movl %ecx, -0x2c(%rsp)
movl %ecx, %eax
movq -0x48(%rsp), %r11
movq %rax, -0x28(%rsp)
movq -0x20(%rsp), %rax
leaq -0x1(%rax), %rdi
movl $0xfffffffe, -0x8(%r11,%rax,4) # imm = 0xFFFFFFFE
movq %rsi, -0x40(%rsp)
movslq %esi, %r13
movslq -0x2c(%rsp), %r10
movq %rdi, -0x20(%rsp)
cmpq %r13, %rdi
jg 0xfca5
movl -0x18(%rsp), %ecx
subl %r13d, %ecx
movq -0x50(%rsp), %rsi
addq %r13, %rsi
movslq -0x28(%rsp), %rdi
movslq %ecx, %rbp
movl $0xfffffffe, %r8d       # imm = 0xFFFFFFFE
movl $0xfffffffe, %r14d      # imm = 0xFFFFFFFE
movl %r14d, %r9d
movl %r8d, %r15d
leal 0x1(%r9), %r8d
movl -0x4(%r11,%r13,4), %r14d
cmpl %r14d, %r15d
movl %r14d, %r11d
cmovgl %r15d, %r11d
cmpl %r9d, %r15d
movl %r8d, %ecx
cmovgl %r15d, %ecx
cmpl %r14d, %r8d
cmovll %r11d, %ecx
cmpq %r10, %r13
jl 0xfc3b
cmpq %rdi, %r13
jg 0xfc3b
movl (%rbx,%r13,4), %r11d
cmpl %r11d, %ecx
jg 0xfdae
cmpq -0x8(%rsp), %rbp
jle 0xfc66
cmpl %r12d, %ecx
movq -0x48(%rsp), %r11
jge 0xfc8b
movslq %ecx, %rcx
movb (%rdx,%rcx), %r9b
cmpb (%rsi,%rcx), %r9b
jne 0xfc8b
incq %rcx
cmpl %ecx, %r12d
jne 0xfc4f
movl %r12d, %ecx
jmp 0xfc8b
movslq %ecx, %r9
cmpq %r9, %rbp
movq -0x48(%rsp), %r11
jle 0xfc8b
movb (%rdx,%r9), %cl
cmpb (%rsi,%r9), %cl
jne 0xfc88
incq %r9
cmpq %rbp, %r9
jl 0xfc73
movq %rbp, %r9
movl %r9d, %ecx
movl %ecx, (%r11,%r13,4)
decq %rsi
incq %rbp
leaq -0x1(%r13), %rcx
cmpq %rax, %r13
movq %rcx, %r13
jge 0xfbfa
movq -0x28(%rsp), %rcx
leal 0x1(%rcx), %edi
leal -0x1(%r10), %eax
movl -0x14(%rsp), %r14d
movl %r14d, -0x8(%rbx,%r10,4)
movb $0x1, %r8b
movl %eax, -0x2c(%rsp)
cmpl %eax, %edi
jge 0xfcd0
movq -0x40(%rsp), %rsi
jmp 0xfe12
movl %edi, -0x30(%rsp)
movslq %edi, %r13
movq -0x50(%rsp), %rax
leaq (%rax,%r13), %rdi
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
subl %ecx, %ebp
notl %ecx
movslq -0x40(%rsp), %rsi
movslq %ecx, %r9
movl %r14d, %ecx
movl %r14d, %r8d
leal 0x1(%rcx), %r15d
movl -0x4(%rbx,%r13,4), %r14d
cmpl %r14d, %ecx
movl %r14d, %r11d
cmovll %r15d, %r11d
cmpl %r8d, %ecx
movl %r8d, %eax
cmovll %r15d, %eax
cmpl %r14d, %r8d
cmovgl %r11d, %eax
cmpq %r13, -0x20(%rsp)
jg 0xfd39
cmpq %rsi, %r13
jg 0xfd39
movq -0x48(%rsp), %r11
movl (%r11,%r13,4), %r11d
cmpl %r11d, %eax
jle 0xfdd6
leal -0x1(%rax), %ecx
testq %r9, %r9
jle 0xfd62
cltq
cmpq %rax, %r9
jge 0xfd7c
movb -0x1(%rdx,%rax), %r11b
cmpb -0x1(%rdi,%rax), %r11b
jne 0xfd7c
decq %rax
decl %ecx
cmpq %r9, %rax
jg 0xfd48
movl %ebp, %ecx
jmp 0xfd7c
testl %eax, %eax
jle 0xfd7c
leal -0x1(%rax), %ecx
movb (%rdx,%rcx), %r11b
cmpb (%rdi,%rcx), %r11b
jne 0xfd7c
decl %eax
jg 0xfd66
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, (%rbx,%r13,4)
decq %rdi
incq %r9
leaq -0x1(%r13), %rax
incl %ebp
movl %r8d, %ecx
cmpq %r10, %r13
movq %rax, %r13
jge 0xfcf4
movq -0x48(%rsp), %r11
movq -0x40(%rsp), %rsi
movl -0x30(%rsp), %edi
movb $0x1, %r8b
jmp 0xfe12
movq -0x40(%rsp), %rsi
leal -0x1(,%rsi,2), %esi
leal 0x1(%r11), %eax
cmpl %r11d, %r9d
cmovll %eax, %r8d
cmpl %r11d, %r15d
cmovgl %r15d, %r8d
addl %r8d, %r13d
movq -0x28(%rsp), %rcx
jmp 0xfdf4
movq -0x40(%rsp), %rsi
addl %esi, %esi
cmpl %r11d, %r8d
cmovgel %r11d, %r8d
cmpl %r11d, %ecx
cmovll %r15d, %r8d
addl %r8d, %r13d
movl -0x30(%rsp), %eax
movl %eax, %ecx
movq -0x10(%rsp), %rax
movl %r13d, (%rax)
movq 0x38(%rsp), %rax
movl %r8d, (%rax)
xorl %r8d, %r8d
movl %esi, -0x34(%rsp)
movl %ecx, %edi
movq -0x48(%rsp), %r11
incl %esi
movl %edi, %eax
testb %r8b, %r8b
jne 0xfba5
movl -0x34(%rsp), %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq