// File: /workspace/github_c_makefile_star2_O0/vlenhart[P]q3bsp/patch.cpp
// Function: PatchSurface::FindSize(int, int, LightMapVertex const*, int&, int&) const
bool PatchSurface::FindSize(int controlx,int controly,const LightMapVertex *cp,int &sizex,int &sizey) const
{
  /* Find non-coincident pairs in u direction */

  bool found=false;

  const LightMapVertex *a=0;
  const LightMapVertex *b=0;

  for (int v=0; v <controly; v++)
  {
	  for (int u=0; u < controlx; u+=2)
  	{

	    a = &cp[v * controlx + u];
	    b = &cp[v * controlx + u + 2];

      if ( a->mPos.x != b->mPos.x ||
           a->mPos.y != b->mPos.y ||
           a->mPos.z != b->mPos.z )
	    {
    		found = true;
	    	break;
	    }
   	}
  	if (found) break;
  }

  if (!found)
  {
    printf("Bad mesh control points\n");
    return false;
  }

  /* Find subdivision level in u */
  int levelx = FindLevel(a[0].mPos,a[1].mPos,b[0].mPos);
  sizex = (LEVEL_WIDTH(levelx) - 1) * ((controlx-1) / 2) + 1;


  for (int u=0; u <controlx; u++)
  {
	  for (int v=0; v < controly; v+=2)
  	{

	    a = &cp[v * controlx + u];
	    b = &cp[ ((v+2) * controlx) + u ];

      if ( a->mPos.x != b->mPos.x ||
           a->mPos.y != b->mPos.y ||
           a->mPos.z != b->mPos.z )
	    {
    		found = true;
	    	break;
	    }
   	}
  	if (found) break;
  }

  if (!found)
  {
    printf("Bad mesh control points\n");
    return false;
  }

  /* Find subdivision level in u */
  int levely = FindLevel(a[0].mPos,a[1].mPos,b[0].mPos);
  sizey = (LEVEL_WIDTH(levely) - 1) * ((controly-1) / 2) + 1;

  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movb $0x0, -0x31(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xe178
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xe160
movq -0x20(%rbp), %rax
movl -0x4c(%rbp), %ecx
imull -0x14(%rbp), %ecx
addl -0x50(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movl -0x4c(%rbp), %ecx
imull -0x14(%rbp), %ecx
addl -0x50(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movss (%rax), %xmm0
movq -0x48(%rbp), %rax
ucomiss (%rax), %xmm0
jne 0xe14a
jp 0xe14a
movq -0x40(%rbp), %rax
movss 0x4(%rax), %xmm0
movq -0x48(%rbp), %rax
ucomiss 0x4(%rax), %xmm0
jne 0xe14a
jp 0xe14a
movq -0x40(%rbp), %rax
movss 0x8(%rax), %xmm0
movq -0x48(%rbp), %rax
ucomiss 0x8(%rax), %xmm0
jne 0xe14a
jp 0xe14a
jmp 0xe150
movb $0x1, -0x31(%rbp)
jmp 0xe160
jmp 0xe152
movl -0x50(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x50(%rbp)
jmp 0xe0c4
testb $0x1, -0x31(%rbp)
je 0xe168
jmp 0xe178
jmp 0xe16a
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xe0b1
testb $0x1, -0x31(%rbp)
jne 0xe195
leaq 0x1ba0f(%rip), %rdi     # 0x29b94
movb $0x0, %al
callq 0x3060
movb $0x0, -0x1(%rbp)
jmp 0xe317
movq -0x68(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq $0x28, %rdx
movq -0x48(%rbp), %rcx
callq 0xe450
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %ecx
addl $0x1, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
addl $0x1, %ecx
subl $0x1, %ecx
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl $0x2, %esi
cltd
idivl %esi
imull %eax, %ecx
addl $0x1, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xe2ae
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xe296
movq -0x20(%rbp), %rax
movl -0x5c(%rbp), %ecx
imull -0x14(%rbp), %ecx
addl -0x58(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movl -0x5c(%rbp), %ecx
addl $0x2, %ecx
imull -0x14(%rbp), %ecx
addl -0x58(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movss (%rax), %xmm0
movq -0x48(%rbp), %rax
ucomiss (%rax), %xmm0
jne 0xe280
jp 0xe280
movq -0x40(%rbp), %rax
movss 0x4(%rax), %xmm0
movq -0x48(%rbp), %rax
ucomiss 0x4(%rax), %xmm0
jne 0xe280
jp 0xe280
movq -0x40(%rbp), %rax
movss 0x8(%rax), %xmm0
movq -0x48(%rbp), %rax
ucomiss 0x8(%rax), %xmm0
jne 0xe280
jp 0xe280
jmp 0xe286
movb $0x1, -0x31(%rbp)
jmp 0xe296
jmp 0xe288
movl -0x5c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x5c(%rbp)
jmp 0xe1fa
testb $0x1, -0x31(%rbp)
je 0xe29e
jmp 0xe2ae
jmp 0xe2a0
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0xe1e7
testb $0x1, -0x31(%rbp)
jne 0xe2c8
leaq 0x1b8d9(%rip), %rdi     # 0x29b94
movb $0x0, %al
callq 0x3060
movb $0x0, -0x1(%rbp)
jmp 0xe317
movq -0x68(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq $0x28, %rdx
movq -0x48(%rbp), %rcx
callq 0xe450
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %ecx
addl $0x1, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
addl $0x1, %ecx
subl $0x1, %ecx
movl -0x18(%rbp), %eax
subl $0x1, %eax
movl $0x2, %esi
cltd
idivl %esi
imull %eax, %ecx
addl $0x1, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)