// File: /workspace/github_c_makefile_star2_O0/vlenhart[P]q3bsp/q3bsp.cpp
// Function: Quake3BSP::ReadLightmaps(void const*)
void Quake3BSP::ReadLightmaps(const void *mem)
{
  assert( mOk );

  int lsize;
  int lcount;
  const unsigned char *maps = (const unsigned char *) mHeader.LumpInfo(Q3_LIGHTMAPS,mem,lsize,lcount);
  unsigned char *lmaps = new unsigned char[lcount];
  memcpy(lmaps,maps,lcount);

  for (int j=0; j<lcount; j++)
  {
    unsigned int c = lmaps[j];
    lmaps[j] = (unsigned char) c;
  }

  #define LMWID 128
  #define LMHIT 128
  #define LMSIZE (LMWID*LMHIT*3)

  int texcount = lcount / LMSIZE;

  unsigned char *map = lmaps;

  for (int i=0; i<texcount; i++)
  {
    char scratch[256];
    sprintf(scratch,"%slm%s%02d",mLmPrefix.Get(),mCodeName.Get(),i);
    String sname = scratch;
    if (mUsePng) {
      String bname = sname+".png";
      stbi_write_png(bname.c_str(), LMWID, LMHIT, 3, map, LMWID*3);
    } else {
      String bname = sname+".bmp";
      stbi_write_bmp(bname.c_str(), LMWID, LMHIT, 3, map);
    }
    map+=LMSIZE;
  }


  delete lmaps;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1d0(%rbp)
testb $0x1, (%rax)
je 0xf535
jmp 0xf554
leaq 0x1a6f2(%rip), %rdi     # 0x29c2e
leaq 0x1a6ef(%rip), %rsi     # 0x29c32
movl $0x1a3, %edx            # imm = 0x1A3
leaq 0x1a980(%rip), %rcx     # 0x29ecf
callq 0x31c0
movq -0x1d0(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rdx
movl $0xe, %esi
leaq -0x14(%rbp), %rcx
leaq -0x18(%rbp), %r8
callq 0xff80
movq %rax, -0x20(%rbp)
movslq -0x18(%rbp), %rdi
callq 0x3040
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
movslq -0x18(%rbp), %rdx
callq 0x3230
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xf5d0
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movb %al, %dl
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xf59e
movl -0x18(%rbp), %eax
movl $0xc000, %ecx           # imm = 0xC000
cltd
idivl %ecx
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xf7f8
movq -0x1d0(%rbp), %rdi
addq $0x1f0, %rdi            # imm = 0x1F0
callq 0xdd00
movq -0x1d0(%rbp), %rdi
movq %rax, -0x1e8(%rbp)
addq $0x10, %rdi
callq 0xdd00
movq -0x1e8(%rbp), %rdx
movq %rax, %rcx
movl -0x44(%rbp), %r8d
leaq 0x1aa51(%rip), %rsi     # 0x2a089
xorl %eax, %eax
leaq -0x150(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x30a0
leaq -0x171(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x3500
movq -0x1e0(%rbp), %rsi
movq -0x1d8(%rbp), %rdx
leaq -0x170(%rbp), %rdi
callq 0x92b0
jmp 0xf67c
leaq -0x171(%rbp), %rdi
callq 0x32e0
movq -0x1d0(%rbp), %rax
testb $0x1, 0x1e8(%rax)
je 0xf752
leaq 0x1a858(%rip), %rdx     # 0x29efb
leaq -0x1a8(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x9360
jmp 0xf6b8
leaq -0x1a8(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
movq -0x40(%rbp), %r8
movl $0x80, %edx
movl $0x3, %ecx
movl $0x180, %r9d            # imm = 0x180
movl %edx, %esi
callq 0x6a00
jmp 0xf6e4
leaq -0x1a8(%rbp), %rdi
callq 0x3180
jmp 0xf7c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x180(%rbp)
movl %eax, -0x184(%rbp)
leaq -0x171(%rbp), %rdi
callq 0x32e0
jmp 0xf823
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x180(%rbp)
movl %eax, -0x184(%rbp)
jmp 0xf7ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x180(%rbp)
movl %eax, -0x184(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x3180
jmp 0xf7ea
leaq 0x1a7a7(%rip), %rdx     # 0x29f00
leaq -0x1c8(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x9360
jmp 0xf76e
leaq -0x1c8(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
movq -0x40(%rbp), %r8
movl $0x80, %edx
movl $0x3, %ecx
movl %edx, %esi
callq 0x4340
jmp 0xf794
leaq -0x1c8(%rbp), %rdi
callq 0x3180
jmp 0xf7c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x180(%rbp)
movl %eax, -0x184(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x3180
jmp 0xf7ea
movq -0x40(%rbp), %rax
addq $0xc000, %rax           # imm = 0xC000
movq %rax, -0x40(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x3180
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xf5ed
leaq -0x170(%rbp), %rdi
callq 0x3180
jmp 0xf823
movq -0x28(%rbp), %rax
movq %rax, -0x1f0(%rbp)
cmpq $0x0, %rax
je 0xf81a
movq -0x1f0(%rbp), %rdi
movl $0x1, %esi
callq 0x32b0
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
movq -0x180(%rbp), %rdi
callq 0x34f0
nop