// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1000, %rsp           # imm = 0x1000
leaq 0x5404751(%rip), %r15   # 0x54349f8
xorl %edi, %edi
cmpl $0xffff, (%r15)         # imm = 0xFFFF
setb %dil
pushq $0x1b
popq %rsi
callq 0x92cb
leaq 0x369b(%rip), %rdx      # 0x3395e
leaq 0x14096(%rip), %rcx     # 0x44360
movq %rsp, %rdi
movl $0x1000, %esi           # imm = 0x1000
xorl %eax, %eax
callq 0x767f
leaq 0x54c6730(%rip), %r12   # 0x54f6a10
cmpb $0x1, (%r12)
jne 0x302fa
movl (%r15), %esi
movq %rsp, %rdi
callq 0x2f9ba
testb %al, %al
jne 0x3046b
movl (%r15), %ebx
incl %ebx
imull %ebx, %ebx
shrl $0x4, %ebx
incl %ebx
cvtsi2sd %ebx, %xmm0
mulsd 0x355d(%rip), %xmm0     # 0x33870
leaq 0x97b2(%rip), %rdi      # 0x39acc
leaq 0x97be(%rip), %rsi      # 0x39adf
movb $0x1, %al
callq 0x8790
movq %rbx, %rdi
callq 0x477c
movq %rax, 0x66c6809(%rip)   # 0x66f6b40
testq %rax, %rax
jne 0x30360
leaq 0x9b22(%rip), %rdi      # 0x39e65
xorl %eax, %eax
callq 0x8790
xorl %edi, %edi
cmpq $0x0, 0x66c67ec(%rip)   # 0x66f6b40
setne %dil
pushq $0x1
popq %rsi
callq 0x92cb
leaq 0x96ca(%rip), %rdi      # 0x39a31
callq 0x893a
leaq 0x6314(%rip), %rbx      # 0x36687
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x8790
leaq 0x150f9(%rip), %rax     # 0x45480
movl 0x34(%rax), %edi
leaq 0x150a3(%rip), %r13     # 0x45434
movzbl (%r13), %esi
leaq 0x1ac(%rip), %rdx       # 0x30549
callq 0x9e41
leaq 0xd3(%rip), %rax        # 0x3047c
leaq 0x66c6798(%rip), %rcx   # 0x66f6b48
movq %rax, (%rcx)
leaq 0x9646(%rip), %rdi      # 0x39a00
callq 0x2fe57
leaq 0x54c6673(%rip), %rax   # 0x54f6a39
leaq 0x6733(%rip), %rcx      # 0x36b00
leaq 0x673b(%rip), %rdi      # 0x36b0f
cmpb $0x0, (%rax)
cmovneq %rcx, %rdi
leaq 0x6d1(%rip), %r14       # 0x30ab3
cmovneq 0x13b96(%rip), %r14     # 0x43f80
callq 0x893a
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x8790
movl (%r15), %edi
movzbl (%r13), %esi
movq %r14, %rdx
callq 0x9e41
movq 0x66c672d(%rip), %rdi   # 0x66f6b40
testq %rdi, %rdi
je 0x30439
callq 0x479f
testb %al, %al
je 0x3042b
andq $0x0, 0x66c6717(%rip)   # 0x66f6b40
jmp 0x30439
leaq 0x9a98(%rip), %rdi      # 0x39eca
xorl %eax, %eax
callq 0x8ea5
callq 0x2ffb1
cmpb $0x1, (%r12)
jne 0x30452
movl (%r15), %esi
movq %rsp, %rdi
callq 0x2f838
jmp 0x3045a
movq %rsp, %rdi
callq 0x4170
callq 0x31ab2
leaq 0x66b5(%rip), %rdi      # 0x36b1b
callq 0x3018f
addq $0x1000, %rsp           # imm = 0x1000
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq