// File: FreeSlave[P]vhlt/hlrad/sparse.cpp
// Function: MakeScalesSparseVismatrix()
void            MakeScalesSparseVismatrix()
{
    char            transferfile[_MAX_PATH];

    hlassume(g_num_patches < MAX_SPARSE_VISMATRIX_PATCHES, assume_MAX_PATCHES);

#ifdef ZHLT_DEFAULTEXTENSION_FIX
	safe_snprintf(transferfile, _MAX_PATH, "%s.inc", g_Mapname);
#else
    safe_strncpy(transferfile, g_source, _MAX_PATH);
    StripExtension(transferfile);
    DefaultExtension(transferfile, ".inc");
#endif

    if (!g_incremental || !readtransfers(transferfile, g_num_patches))
    {
        // determine visibility between g_patches
        BuildVisMatrix();
        DumpVismatrixInfo();
        g_CheckVisBit = CheckVisBitSparse;

#ifdef HLRAD_HULLU
	#ifdef HLRAD_TRANSPARENCY_CPP
        CreateFinalTransparencyArrays("custom shadow array");
	#else
        if((s_max_transparency_count*sizeof(transparency_t))>=(1024 * 1024))
        	Log("%-20s: %5.1f megs\n", "custom shadow array", (s_max_transparency_count*sizeof(transparency_t)) / (1024 * 1024.0));
        else if(s_transparency_count)
        	Log("%-20s: %5.1f kilos\n", "custom shadow array", (s_max_transparency_count*sizeof(transparency_t)) / 1024.0);
	#endif
#endif
        
#ifndef HLRAD_HULLU
        NamedRunThreadsOn(g_num_patches, g_estimate, MakeScales);
#else
	if(g_rgb_transfers)
		{NamedRunThreadsOn(g_num_patches, g_estimate, MakeRGBScales);}
	else
		{NamedRunThreadsOn(g_num_patches, g_estimate, MakeScales);}
#endif
        FreeVisMatrix();
#ifdef HLRAD_HULLU
	#ifdef HLRAD_TRANSPARENCY_CPP
        FreeTransparencyArrays();
	#endif
#endif

#ifndef HLRAD_NOSWAP
        // invert the transfers for gather vs scatter
#ifndef HLRAD_HULLU
        NamedRunThreadsOnIndividual(g_num_patches, g_estimate, SwapTransfers);
#else
	if(g_rgb_transfers)
		{NamedRunThreadsOnIndividual(g_num_patches, g_estimate, SwapRGBTransfers);}
	else
		{NamedRunThreadsOnIndividual(g_num_patches, g_estimate, SwapTransfers);}
#endif
#endif /*HLRAD_NOSWAP*/
        if (g_incremental)
        {
            writetransfers(transferfile, g_num_patches);
        }
        else
        {
            _unlink(transferfile);
        }
        // release visibility matrix
        DumpTransfersMemoryUsage();
#ifdef HLRAD_OPAQUE_STYLE_BOUNCE
		CreateFinalStyleArrays ("dynamic shadow array");
#endif
    }
}

// Assembly:
subq $0x1008, %rsp           # imm = 0x1008
leaq 0x540c5fa(%rip), %rax   # 0x546da08
cmpl $0xffff0, (%rax)        # imm = 0xFFFF0
setb %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x1b, %esi
callq 0xbf00
movq %rsp, %rdi
movl $0x1000, %esi           # imm = 0x1000
leaq 0xa648(%rip), %rdx      # 0x6ba7e
leaq 0x1bf23(%rip), %rcx     # 0x7d360
movb $0x0, %al
callq 0x94e0
leaq 0x54ce5d5(%rip), %rax   # 0x552fa20
testb $0x1, (%rax)
je 0x6146b
movq %rsp, %rdi
leaq 0x540c5ae(%rip), %rax   # 0x546da08
movl (%rax), %eax
movl %eax, %esi
callq 0x65770
testb $0x1, %al
jne 0x61564
callq 0x61570
callq 0x61610
leaq 0x66ce6dc(%rip), %rax   # 0x672fb58
leaq 0x25d(%rip), %rcx       # 0x616e0
movq %rcx, (%rax)
leaq 0x10623(%rip), %rdi     # 0x71ab0
callq 0x65f30
leaq 0x54ce5b0(%rip), %rax   # 0x552fa49
testb $0x1, (%rax)
je 0x614e0
leaq 0xd6ab(%rip), %rdi      # 0x6eb50
callq 0xb2f0
movq %rax, %rsi
leaq 0xd1e9(%rip), %rdi      # 0x6e69d
movb $0x0, %al
callq 0xb0d0
leaq 0x540c546(%rip), %rax   # 0x546da08
movl (%rax), %edi
leaq 0x1cf69(%rip), %rax     # 0x7e434
movb (%rax), %al
leaq 0x708c(%rip), %rdx      # 0x68560
andb $0x1, %al
movzbl %al, %esi
callq 0xd2a0
jmp 0x61520
leaq 0xd678(%rip), %rdi      # 0x6eb5f
callq 0xb2f0
movq %rax, %rsi
leaq 0xd1a7(%rip), %rdi      # 0x6e69d
movb $0x0, %al
callq 0xb0d0
leaq 0x540c504(%rip), %rax   # 0x546da08
movl (%rax), %edi
leaq 0x1cf27(%rip), %rax     # 0x7e434
movb (%rax), %al
leaq 0x604a(%rip), %rdx      # 0x67560
andb $0x1, %al
movzbl %al, %esi
callq 0xd2a0
callq 0x61830
callq 0x66240
leaq 0x54ce4ef(%rip), %rax   # 0x552fa20
testb $0x1, (%rax)
je 0x6154b
movq %rsp, %rdi
leaq 0x540c4c8(%rip), %rax   # 0x546da08
movl (%rax), %eax
movl %eax, %esi
callq 0x65520
jmp 0x61553
movq %rsp, %rdi
callq 0x4180
callq 0x69480
leaq 0xd60c(%rip), %rdi      # 0x6eb6b
callq 0x66600
addq $0x1008, %rsp           # imm = 0x1008
retq
nopl (%rax)