// File: /workspace/github_cpp_makefile_star2_O2/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 0xa3ec(%rip), %rsi      # 0x39c3d
callq 0x4370
testq %rax, %rax
je 0x2f985
movq %rax, %r14
leaq 0xa3d8(%rip), %rdi      # 0x39c41
movq %rbx, %rsi
xorl %eax, %eax
callq 0x8790
movq %rsp, %rdi
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x4630
cmpl $0x1, %eax
jne 0x2f956
movq (%rsp), %r13
leaq 0x5385158(%rip), %rax   # 0x53b49f0
movq (%rax), %r15
addq $0x38, %r15
pushq $0x4
popq %r12
testq %r13, %r13
jle 0x2f9a4
movq %r15, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x4630
cmpl $0x1, %eax
jne 0x2f956
movl (%r15), %edx
testq %rdx, %rdx
je 0x2f8e2
movq 0x8(%r15), %rdi
movq %r12, %rsi
movq %r14, %rcx
callq 0x4630
cmpl %eax, (%r15)
jne 0x2f956
leaq 0x4(%r15), %rbp
movq %rbp, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x4630
cmpl $0x1, %eax
jne 0x2f956
movl (%rbp), %edx
testq %rdx, %rdx
je 0x2f947
leaq 0x54c712e(%rip), %rax   # 0x54f6a39
movzbl (%rax), %eax
testl %eax, %eax
leaq 0x5b79(%rip), %rcx      # 0x35490
cmovneq 0x146b9(%rip), %rcx     # 0x43fd8
movq 0x10(%r15,%rax,8), %rdi
leaq 0x15ae9(%rip), %rax     # 0x45414
cmovneq 0x14675(%rip), %rax     # 0x43fa8
movl (%rax), %eax
movq (%rcx,%rax,8), %rsi
movq %r14, %rcx
callq 0x4630
cmpl %eax, 0x4(%r15)
jne 0x2f956
addq $0x138, %r15            # imm = 0x138
decq %r13
jmp 0x2f8a3
movq %r14, %rdi
callq 0x42d0
movq %rbx, %rdi
callq 0x4170
leaq 0xa324(%rip), %rdi      # 0x39c91
movq %rbx, %rsi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ea5
leaq 0xa2d2(%rip), %rdi      # 0x39c5e
movq %rbx, %rsi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b2f
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42d0