// File: FreeSlave[P]vhlt/hlrad/vismatrix.cpp
// Function: MakeScalesVismatrix()
void            MakeScalesVismatrix()
{
    char            transferfile[_MAX_PATH];

    hlassume(g_num_patches < MAX_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();
        g_CheckVisBit = CheckVisBitVismatrix;

#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);
        DumpTransfersMemoryUsage();
#ifdef HLRAD_OPAQUE_STYLE_BOUNCE
		CreateFinalStyleArrays ("dynamic shadow array");
#endif
    }
}

// Assembly:
subq $0x1008, %rsp           # imm = 0x1008
leaq 0x540710a(%rip), %rax   # 0x546da08
cmpl $0xffff, (%rax)         # imm = 0xFFFF
setb %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x1b, %esi
callq 0xbf00
movq %rsp, %rdi
movl $0x1000, %esi           # imm = 0x1000
leaq 0x5158(%rip), %rdx      # 0x6ba7e
leaq 0x16a33(%rip), %rcx     # 0x7d360
movb $0x0, %al
callq 0x94e0
leaq 0x54c90e5(%rip), %rax   # 0x552fa20
testb $0x1, (%rax)
je 0x6695b
movq %rsp, %rdi
leaq 0x54070be(%rip), %rax   # 0x546da08
movl (%rax), %eax
movl %eax, %esi
callq 0x65770
testb $0x1, %al
jne 0x66a4f
callq 0x66a60
leaq 0x66c91f1(%rip), %rax   # 0x672fb58
leaq 0x1d2(%rip), %rcx       # 0x66b40
movq %rcx, (%rax)
leaq 0xb138(%rip), %rdi      # 0x71ab0
callq 0x65f30
leaq 0x54c90c5(%rip), %rax   # 0x552fa49
testb $0x1, (%rax)
je 0x669cb
leaq 0x81c0(%rip), %rdi      # 0x6eb50
callq 0xb2f0
movq %rax, %rsi
leaq 0x7cfe(%rip), %rdi      # 0x6e69d
movb $0x0, %al
callq 0xb0d0
leaq 0x540705b(%rip), %rax   # 0x546da08
movl (%rax), %edi
leaq 0x17a7e(%rip), %rax     # 0x7e434
movb (%rax), %al
leaq 0x1ba1(%rip), %rdx      # 0x68560
andb $0x1, %al
movzbl %al, %esi
callq 0xd2a0
jmp 0x66a0b
leaq 0x818d(%rip), %rdi      # 0x6eb5f
callq 0xb2f0
movq %rax, %rsi
leaq 0x7cbc(%rip), %rdi      # 0x6e69d
movb $0x0, %al
callq 0xb0d0
leaq 0x5407019(%rip), %rax   # 0x546da08
movl (%rax), %edi
leaq 0x17a3c(%rip), %rax     # 0x7e434
movb (%rax), %al
leaq 0xb5f(%rip), %rdx       # 0x67560
andb $0x1, %al
movzbl %al, %esi
callq 0xd2a0
callq 0x66c80
callq 0x66240
leaq 0x54c9004(%rip), %rax   # 0x552fa20
testb $0x1, (%rax)
je 0x66a36
movq %rsp, %rdi
leaq 0x5406fdd(%rip), %rax   # 0x546da08
movl (%rax), %eax
movl %eax, %esi
callq 0x65520
jmp 0x66a3e
movq %rsp, %rdi
callq 0x4180
callq 0x69480
leaq 0x8121(%rip), %rdi      # 0x6eb6b
callq 0x66600
addq $0x1008, %rsp           # imm = 0x1008
retq
nopw (%rax,%rax)