// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlrad/transfers.cpp
// Function: writetransfers(char const*, long)
void            writetransfers(const char* const transferfile, const long total_patches)
{
    FILE           *file;

    file = fopen(transferfile, "w+b");
    if (file != NULL)
    {
        unsigned        amtwritten;
        patch_t*        patch;

        Log("Writing transfers file [%s]\n", transferfile);

        amtwritten = fwrite(&total_patches, sizeof(total_patches), 1, file);
        if (amtwritten != 1)
        {
            goto FailedWrite;
        }

        long patchcount = total_patches;
        for (patch = g_patches; patchcount-- > 0; patch++)
        {
            amtwritten = fwrite(&patch->iIndex, sizeof(patch->iIndex), 1, file);
            if (amtwritten != 1)
            {
                goto FailedWrite;
            }

            if (patch->iIndex)
            {
                amtwritten = fwrite(patch->tIndex, sizeof(transfer_index_t), patch->iIndex, file);
                if (amtwritten != patch->iIndex)
                {
                    goto FailedWrite;
                }
            }

            amtwritten = fwrite(&patch->iData, sizeof(patch->iData), 1, file);
            if (amtwritten != 1)
            {
                goto FailedWrite;
            }
            if (patch->iData)
            {
#ifdef HLRAD_HULLU
				if(g_rgb_transfers)
				{
	#ifdef HLRAD_TRANSFERDATA_COMPRESS
			amtwritten = fwrite(patch->tRGBData, vector_size[g_rgbtransfer_compress_type], patch->iData, file);
	#else
			amtwritten = fwrite(patch->tRGBData, sizeof(rgb_transfer_data_t), patch->iData, file);
	#endif
				}
				else
				{
	#ifdef HLRAD_TRANSFERDATA_COMPRESS
			amtwritten = fwrite(patch->tData, float_size[g_transfer_compress_type], patch->iData, file);
	#else
			amtwritten = fwrite(patch->tData, sizeof(transfer_data_t), patch->iData, file);
	#endif
				}
#else
	#ifdef HLRAD_TRANSFERDATA_COMPRESS
				amtwritten = fwrite(patch->tData, float_size[g_transfer_compress_type], patch->iData, file);
	#else
                amtwritten = fwrite(patch->tData, sizeof(transfer_data_t), patch->iData, file);
	#endif
#endif
                if (amtwritten != patch->iData)
                {
                    goto FailedWrite;
                }
            }
        }

        fclose(file);
    }
    else
    {
        Error("Failed to open incremenetal file [%s] for writing\n", transferfile);
    }
    return;

  FailedWrite:
    fclose(file);
    unlink(transferfile);
    //Warning("Failed to generate incremental file [%s] (probably ran out of disk space)\n");
    Warning("Failed to generate incremental file [%s] (probably ran out of disk space)\n", transferfile); //--vluzacn
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq %rsi, (%rsp)
leaq 0xb060(%rip), %rsi      # 0x3ecf5
callq 0x4360
testq %rax, %rax
je 0x33df9
movq %rax, %r14
leaq 0xb04c(%rip), %rdi      # 0x3ecf9
movq %rbx, %rsi
xorl %eax, %eax
callq 0x9c46
movq %rsp, %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4610
cmpl $0x1, %eax
jne 0x33dca
movq (%rsp), %r13
testq %r13, %r13
jle 0x33db4
leaq 0x5383cf7(%rip), %rax   # 0x53b79e0
movq (%rax), %r15
incq %r13
addq $0x38, %r15
leaq 0x1470a(%rip), %rbp     # 0x48404
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x4610
cmpl $0x1, %eax
jne 0x33dca
movl (%r15), %edx
testq %rdx, %rdx
je 0x33d3a
movq 0x8(%r15), %rdi
movl $0x4, %esi
movq %r14, %rcx
callq 0x4610
cmpl %eax, (%r15)
jne 0x33dca
leaq 0x4(%r15), %r12
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r14, %rcx
callq 0x4610
cmpl $0x1, %eax
jne 0x33dca
movl (%r12), %edx
testq %rdx, %rdx
je 0x33da0
leaq 0x54c5cc1(%rip), %rax   # 0x54f9a29
movzbl (%rax), %eax
testl %eax, %eax
leaq 0x679c(%rip), %rcx      # 0x3a510
cmovneq 0x1325c(%rip), %rcx     # 0x46fd8
movq 0x10(%r15,%rax,8), %rdi
movq %rbp, %rax
cmovneq 0x1321c(%rip), %rax     # 0x46fa8
movl (%rax), %eax
movq (%rcx,%rax,8), %rsi
movq %r14, %rcx
callq 0x4610
cmpl %eax, 0x4(%r15)
jne 0x33dca
decq %r13
addq $0x138, %r15            # imm = 0x138
cmpq $0x1, %r13
ja 0x33cfa
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42d0
movq %r14, %rdi
callq 0x42d0
movq %rbx, %rdi
callq 0x4160
leaq 0xaf68(%rip), %rdi      # 0x3ed49
movq %rbx, %rsi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa2a6
leaq 0xaf16(%rip), %rdi      # 0x3ed16
movq %rbx, %rsi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9f34