// File: /workspace/github_cpp_makefile_star2_O1/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 0x54030cd(%rip), %r15   # 0x54389e8
xorl %edi, %edi
cmpl $0xffff, (%r15)         # imm = 0xFFFF
setb %dil
movl $0x1b, %esi
callq 0xa7c9
leaq 0x40c5(%rip), %rdx      # 0x399fe
leaq 0x12a10(%rip), %rcx     # 0x48350
movq %rsp, %rdi
movl $0x1000, %esi           # imm = 0x1000
xorl %eax, %eax
callq 0x88fb
leaq 0x54c50aa(%rip), %r12   # 0x54faa00
cmpb $0x1, (%r12)
jne 0x35970
movl (%r15), %esi
movq %rsp, %rdi
callq 0x34e98
testb %al, %al
jne 0x35ae6
movl (%r15), %ebx
incl %ebx
imull %ebx, %ebx
shrl $0x4, %ebx
incl %ebx
cvtsi2sd %ebx, %xmm0
mulsd 0x3f87(%rip), %xmm0     # 0x39910
leaq 0xa27c(%rip), %rdi      # 0x3fc0c
leaq 0xa288(%rip), %rsi      # 0x3fc1f
movb $0x1, %al
callq 0x9d2e
movq %rbx, %rdi
callq 0x492c
movq %rax, 0x66c5183(%rip)   # 0x66fab30
testq %rax, %rax
jne 0x359d8
leaq 0xa5e4(%rip), %rdi      # 0x3ff9d
xorl %eax, %eax
callq 0x9d2e
xorl %edi, %edi
cmpq $0x0, 0x66c5166(%rip)   # 0x66fab30
setne %dil
movl $0x1, %esi
callq 0xa7c9
leaq 0xa192(%rip), %rdi      # 0x3fb71
callq 0x9e7a
leaq 0x6d94(%rip), %rbx      # 0x3c77f
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x9d2e
leaq 0x13a71(%rip), %rax     # 0x49470
movl 0x34(%rax), %edi
leaq 0x13a1b(%rip), %r13     # 0x49424
movzbl (%r13), %esi
leaq 0x1ad(%rip), %rdx       # 0x35bc2
callq 0xb446
leaq 0xd6(%rip), %rax        # 0x35af7
leaq 0x66c5110(%rip), %rcx   # 0x66fab38
movq %rax, (%rcx)
leaq 0xa10e(%rip), %rdi      # 0x3fb40
callq 0x35430
leaq 0x54c4feb(%rip), %rax   # 0x54faa29
leaq 0x71b7(%rip), %rcx      # 0x3cbfc
leaq 0x71bf(%rip), %rdi      # 0x3cc0b
cmpb $0x0, (%rax)
cmovneq %rcx, %rdi
leaq 0x7c5(%rip), %r14       # 0x3621f
cmovneq 0x1251e(%rip), %r14     # 0x47f80
callq 0x9e7a
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x9d2e
movl (%r15), %edi
movzbl (%r13), %esi
movq %r14, %rdx
callq 0xb446
movq 0x66c50a5(%rip), %rdi   # 0x66fab30
testq %rdi, %rdi
je 0x35ab4
callq 0x4951
testb %al, %al
je 0x35aa6
movq $0x0, 0x66c508c(%rip) # 0x66fab30
jmp 0x35ab4
leaq 0xa555(%rip), %rdi      # 0x40002
xorl %eax, %eax
callq 0xa38e
callq 0x355ca
cmpb $0x1, (%r12)
jne 0x35acd
movl (%r15), %esi
movq %rsp, %rdi
callq 0x34cfc
jmp 0x35ad5
movq %rsp, %rdi
callq 0x4160
callq 0x374fd
leaq 0x7136(%rip), %rdi      # 0x3cc17
callq 0x357db
addq $0x1000, %rsp           # imm = 0x1000
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq