// File: /workspace/github_c_makefile_star2_O3/vlenhart[P]q3bsp/patch.cpp
// Function: PatchSurface::PatchSurface(LightMapVertex const*, int, int, int)
PatchSurface::PatchSurface(const LightMapVertex *cp,
                           int npoints,
                           int controlx,
                           int controly)
{
  int sizex,sizey;
  FindSize(controlx,controly,cp,sizex,sizey);

  int size = sizex*sizey;
  mPoints = new LightMapVertex[size];

  int stepx = (sizex-1) / (controlx-1);
  int stepy = (sizey-1) / (controly-1);
  const LightMapVertex *control = cp;

  for (int y=0; y<sizey; y+=stepy)
  {
    for (int x=0; x<sizex; x+=stepx)
    {
      int p = y*sizex+x;
      mPoints[p] = *control++;
    }
  }


  FillPatch(controlx,controly,sizex,sizey,mPoints);

  mCount = (sizex-1)*(sizey-1)*6;

  if ( 1 )
  {
    mIndices = new unsigned short[mCount];
    unsigned short *foo = mIndices;
    for (int y=0; y < sizey-1; ++y)
    {
    	for (int x = 0; x < sizex-1; ++x)
    	{
        *foo++ = y*sizex+x;
        *foo++ = (y+1)*sizex+x;
        *foo++ = y*sizex+x+1;

        *foo++ = y*sizex+x+1;
        *foo++ = (y+1)*sizex+x;
        *foo++ = (y+1)*sizex+x+1;
    	}
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, %edx
movq %rsi, %r14
movq %rdi, %r12
leaq -0x50(%rbp), %rbx
leaq -0x4c(%rbp), %r15
movq %rcx, -0x38(%rbp)
movl %ecx, %esi
movq %rdx, -0x40(%rbp)
movq %r14, %rcx
movq %rbx, %r8
movq %r15, %r9
callq 0x7f00
movslq (%rbx), %rbx
movslq (%r15), %r13
movl %r13d, %eax
imull %ebx, %eax
cltq
movl $0x28, %ecx
mulq %rcx
movq $-0x1, %rcx
cmovoq %rcx, %rax
movq %rax, %rdi
callq 0x2040
leal -0x1(%rbx), %edi
leal -0x1(%r13), %r15d
movq %rax, 0x8(%r12)
movq %r13, -0x48(%rbp)
testq %r13, %r13
movl %edi, -0x30(%rbp)
jle 0x7e5a
movq -0x40(%rbp), %r9
leal -0x1(%r9), %ecx
movl %r15d, -0x2c(%rbp)
movl %r15d, %eax
cltd
idivl %ecx
movl %eax, %ecx
movq -0x38(%rbp), %r10
leal -0x1(%r10), %esi
movl %edi, %eax
cltd
idivl %esi
cltq
movslq %ecx, %rcx
movq %rbx, %rdx
imulq %rcx, %rdx
shlq $0x3, %rdx
leaq (%rdx,%rdx,4), %r15
leaq (,%rax,8), %rsi
leaq (%rsi,%rsi,4), %r13
movl $0x24, %edi
xorl %r8d, %r8d
movq %r9, %rdx
movq %r10, %rsi
testl %ebx, %ebx
jle 0x7e3f
movq %rdi, %r9
xorl %r10d, %r10d
movq 0x8(%r12), %r11
movss (%r14), %xmm0
movss %xmm0, -0x24(%r11,%r9)
movss 0x4(%r14), %xmm0
movss %xmm0, -0x20(%r11,%r9)
movss 0x8(%r14), %xmm0
movss %xmm0, -0x1c(%r11,%r9)
movups 0xc(%r14), %xmm0
movups %xmm0, -0x18(%r11,%r9)
movss 0x1c(%r14), %xmm0
movss %xmm0, -0x8(%r11,%r9)
movss 0x20(%r14), %xmm0
movss %xmm0, -0x4(%r11,%r9)
movss 0x24(%r14), %xmm0
addq $0x28, %r14
movss %xmm0, (%r11,%r9)
addq %rax, %r10
addq %r13, %r9
cmpq %rbx, %r10
jl 0x7dd4
addq %rcx, %r8
addq %r15, %rdi
cmpq -0x48(%rbp), %r8
jl 0x7dca
movq 0x8(%r12), %rax
movl -0x2c(%rbp), %r15d
jmp 0x7e62
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rsi
movq %r12, %rdi
movl %ebx, %ecx
movq -0x48(%rbp), %r13
movl %r13d, %r8d
movq %rax, %r9
callq 0x8044
movl %r15d, %eax
movl -0x30(%rbp), %r14d
imull %r14d, %eax
leal (%rax,%rax), %ecx
leal (%rcx,%rcx,2), %ecx
movl %ecx, (%r12)
movslq %ecx, %rdi
addq %rdi, %rdi
testl %eax, %eax
movq $-0x1, %rax
cmovsq %rax, %rdi
callq 0x2040
movq %rax, 0x10(%r12)
cmpl $0x2, %r13d
jl 0x7ef0
xorl %ecx, %ecx
cmpl $0x1, %ebx
jle 0x7ee9
movl %ecx, %edx
imull %ebx, %edx
incl %ecx
movl %ebx, %esi
imull %ecx, %esi
movl %r14d, %edi
movw %dx, (%rax)
movw %si, 0x2(%rax)
incl %edx
movw %dx, 0x4(%rax)
movw %dx, 0x6(%rax)
movw %si, 0x8(%rax)
incl %esi
movw %si, 0xa(%rax)
addq $0xc, %rax
decl %edi
jne 0x7ec4
jmp 0x7eeb
incl %ecx
cmpl %r15d, %ecx
jne 0x7eb0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop