// File: /workspace/github_c_makefile_star2_O0/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
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x88(%rbp)
movl -0x18(%rbp), %esi
movl -0x1c(%rbp), %edx
movq -0x10(%rbp), %rcx
leaq -0x20(%rbp), %r8
leaq -0x24(%rbp), %r9
callq 0xe070
movl -0x20(%rbp), %eax
imull -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
movslq -0x28(%rbp), %rax
movq %rax, -0x78(%rbp)
movl $0x28, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x80(%rbp)
callq 0x3040
movq %rax, %rcx
movq -0x78(%rbp), %rax
movq %rcx, -0x70(%rbp)
cmpq $0x0, %rax
je 0xddfa
movq -0x70(%rbp), %rax
movq -0x78(%rbp), %rcx
imulq $0x28, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x98(%rbp)
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0xe730
jmp 0xdddc
movq -0x98(%rbp), %rcx
movq -0xa0(%rbp), %rax
addq $0x28, %rax
cmpq %rcx, %rax
movq %rax, -0x90(%rbp)
jne 0xddc7
movq -0x88(%rbp), %rax
movq -0x70(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0x20(%rbp), %eax
subl $0x1, %eax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
cltd
idivl %ecx
movl %eax, -0x38(%rbp)
movl -0x24(%rbp), %eax
subl $0x1, %eax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
cltd
idivl %ecx
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xdec3
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0xdeb3
movq -0x88(%rbp), %rax
movl -0x4c(%rbp), %ecx
imull -0x20(%rbp), %ecx
addl -0x50(%rbp), %ecx
movl %ecx, -0x54(%rbp)
movq -0x48(%rbp), %rsi
movq %rsi, %rcx
addq $0x28, %rcx
movq %rcx, -0x48(%rbp)
movq 0x8(%rax), %rdi
movslq -0x54(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rdi
callq 0xe780
movl -0x38(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0xde4b
movq -0x80(%rbp), %rsi
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
callq 0x3570
jmp 0xe058
jmp 0xdeb5
movl -0x3c(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0xde3c
movq -0x88(%rbp), %rdi
movl -0x18(%rbp), %esi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movl -0x24(%rbp), %r8d
movq 0x8(%rdi), %r9
callq 0xe330
movq -0x88(%rbp), %rax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
movl -0x24(%rbp), %edx
subl $0x1, %edx
imull %edx, %ecx
imull $0x6, %ecx, %ecx
movl %ecx, (%rax)
movslq (%rax), %rax
movl $0x2, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3040
movq %rax, %rcx
movq -0x88(%rbp), %rax
movq %rcx, 0x10(%rax)
movq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xe04f
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xe03f
movl -0x64(%rbp), %eax
imull -0x20(%rbp), %eax
addl -0x68(%rbp), %eax
movw %ax, %cx
movq -0x60(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x60(%rbp)
movw %cx, (%rax)
movl -0x64(%rbp), %eax
addl $0x1, %eax
imull -0x20(%rbp), %eax
addl -0x68(%rbp), %eax
movw %ax, %cx
movq -0x60(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x60(%rbp)
movw %cx, (%rax)
movl -0x64(%rbp), %eax
imull -0x20(%rbp), %eax
addl -0x68(%rbp), %eax
addl $0x1, %eax
movw %ax, %cx
movq -0x60(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x60(%rbp)
movw %cx, (%rax)
movl -0x64(%rbp), %eax
imull -0x20(%rbp), %eax
addl -0x68(%rbp), %eax
addl $0x1, %eax
movw %ax, %cx
movq -0x60(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x60(%rbp)
movw %cx, (%rax)
movl -0x64(%rbp), %eax
addl $0x1, %eax
imull -0x20(%rbp), %eax
addl -0x68(%rbp), %eax
movw %ax, %cx
movq -0x60(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x60(%rbp)
movw %cx, (%rax)
movl -0x64(%rbp), %eax
addl $0x1, %eax
imull -0x20(%rbp), %eax
addl -0x68(%rbp), %eax
addl $0x1, %eax
movw %ax, %cx
movq -0x60(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x60(%rbp)
movw %cx, (%rax)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0xdf54
jmp 0xe041
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xdf3c
addq $0xa0, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x34f0
nopw %cs:(%rax,%rax)