// File: /workspace/github_cpp_makefile_star2_O1/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      # 0x3fd75
callq 0x4370
testq %rax, %rax
je 0x34e79
movq %rax, %r14
leaq 0xb04c(%rip), %rdi      # 0x3fd79
movq %rbx, %rsi
xorl %eax, %eax
callq 0x9d2e
movq %rsp, %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x4620
cmpl $0x1, %eax
jne 0x34e4a
movq (%rsp), %r13
testq %r13, %r13
jle 0x34e34
leaq 0x5383c77(%rip), %rax   # 0x53b89e0
movq (%rax), %r15
incq %r13
addq $0x38, %r15
leaq 0x1468a(%rip), %rbp     # 0x49404
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x4620
cmpl $0x1, %eax
jne 0x34e4a
movl (%r15), %edx
testq %rdx, %rdx
je 0x34dba
movq 0x8(%r15), %rdi
movl $0x4, %esi
movq %r14, %rcx
callq 0x4620
cmpl %eax, (%r15)
jne 0x34e4a
leaq 0x4(%r15), %r12
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r14, %rcx
callq 0x4620
cmpl $0x1, %eax
jne 0x34e4a
movl (%r12), %edx
testq %rdx, %rdx
je 0x34e20
leaq 0x54c5c41(%rip), %rax   # 0x54faa29
movzbl (%rax), %eax
testl %eax, %eax
leaq 0x673c(%rip), %rcx      # 0x3b530
cmovneq 0x131d4(%rip), %rcx     # 0x47fd0
movq 0x10(%r15,%rax,8), %rdi
movq %rbp, %rax
cmovneq 0x1319c(%rip), %rax     # 0x47fa8
movl (%rax), %eax
movq (%rcx,%rax,8), %rsi
movq %r14, %rcx
callq 0x4620
cmpl %eax, 0x4(%r15)
jne 0x34e4a
decq %r13
addq $0x138, %r15            # imm = 0x138
cmpq $0x1, %r13
jg 0x34d7a
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42e0
movq %r14, %rdi
callq 0x42e0
movq %rbx, %rdi
callq 0x4160
leaq 0xaf68(%rip), %rdi      # 0x3fdc9
movq %rbx, %rsi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa38e
leaq 0xaf16(%rip), %rdi      # 0x3fd96
movq %rbx, %rsi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa01c