// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1000, %rsp           # imm = 0x1000
leaq 0x540752a(%rip), %r14   # 0x54349f8
xorl %edi, %edi
cmpl $0xffff0, (%r14)        # imm = 0xFFFF0
setb %dil
pushq $0x1b
popq %rsi
callq 0x92cb
leaq 0x6474(%rip), %rdx      # 0x3395e
leaq 0x16e6f(%rip), %rcx     # 0x44360
movq %rsp, %rdi
movl $0x1000, %esi           # imm = 0x1000
xorl %eax, %eax
callq 0x767f
leaq 0x54c9509(%rip), %r15   # 0x54f6a10
cmpb $0x1, (%r15)
jne 0x2d520
movl (%r14), %esi
movq %rsp, %rdi
callq 0x2f9ba
testb %al, %al
jne 0x2d6e8
movl (%r14), %edi
shlq $0x4, %rdi
callq 0x477c
movq %rax, 0x66c959d(%rip)   # 0x66f6ad0
testq %rax, %rax
jne 0x2d55c
leaq 0xc4d5(%rip), %rdi      # 0x39a14
xorl %eax, %eax
callq 0x8790
xorl %edi, %edi
cmpq $0x0, 0x66c9580(%rip)   # 0x66f6ad0
setne %dil
pushq $0x1
popq %rsi
callq 0x92cb
leaq 0xc4ce(%rip), %rdi      # 0x39a31
callq 0x893a
leaq 0x9118(%rip), %rdi      # 0x36687
movq %rax, %rsi
xorl %eax, %eax
callq 0x8790
leaq 0x17f00(%rip), %rax     # 0x45480
movl 0x34(%rax), %edi
leaq 0x17eaa(%rip), %r12     # 0x45434
movzbl (%r12), %esi
leaq 0x29a(%rip), %rdx       # 0x2d830
callq 0x9e41
movl (%r14), %eax
shlq $0x4, %rax
movq 0x66c9527(%rip), %rcx   # 0x66f6ad0
leaq (%rcx,%rax), %rdx
cmpq %rdx, %rcx
jae 0x2d5c0
movslq 0x8(%rcx), %rsi
leaq (%rax,%rsi,4), %rax
addq $0x10, %rcx
jmp 0x2d5ad
movq %rax, %xmm1
punpckldq 0xc413(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xc41b(%rip), %xmm1     # 0x399f0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x6287(%rip), %xmm0     # 0x33870
leaq 0xc4dc(%rip), %rdi      # 0x39acc
leaq 0xc4e8(%rip), %rsi      # 0x39adf
movb $0x1, %al
callq 0x8790
leaq 0xf3(%rip), %rax        # 0x2d6f8
leaq 0x66c953c(%rip), %rcx   # 0x66f6b48
movq %rax, (%rcx)
leaq 0xc3ea(%rip), %rdi      # 0x39a00
callq 0x2fe57
leaq 0x54c9417(%rip), %rax   # 0x54f6a39
leaq 0x94d7(%rip), %rcx      # 0x36b00
leaq 0x94df(%rip), %rdi      # 0x36b0f
cmpb $0x0, (%rax)
cmovneq %rcx, %rdi
leaq 0x3475(%rip), %rbx      # 0x30ab3
cmovneq 0x1693a(%rip), %rbx     # 0x43f80
callq 0x893a
leaq 0x9035(%rip), %rdi      # 0x36687
xorl %ebp, %ebp
movq %rax, %rsi
xorl %eax, %eax
callq 0x8790
movl (%r14), %edi
movzbl (%r12), %esi
movq %rbx, %rdx
callq 0x9e41
movq 0x66c945b(%rip), %rbx   # 0x66f6ad0
testq %rbx, %rbx
je 0x2d6b7
cmpl (%r14), %ebp
jae 0x2d68f
movq (%rbx), %rdi
callq 0x4380
incl %ebp
addq $0x10, %rbx
jmp 0x2d67a
movq 0x66c943a(%rip), %rdi   # 0x66f6ad0
callq 0x479f
testb %al, %al
je 0x2d6a9
andq $0x0, 0x66c9429(%rip)   # 0x66f6ad0
jmp 0x2d6b7
leaq 0xc485(%rip), %rdi      # 0x39b35
xorl %eax, %eax
callq 0x8ea5
callq 0x2ffb1
cmpb $0x1, (%r15)
jne 0x2d6cf
movl (%r14), %esi
movq %rsp, %rdi
callq 0x2f838
jmp 0x2d6d7
movq %rsp, %rdi
callq 0x4170
callq 0x31ab2
leaq 0x9438(%rip), %rdi      # 0x36b1b
callq 0x3018f
addq $0x1000, %rsp           # imm = 0x1000
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq