// File: 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:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq 0x30(%rsp), %rdi
leaq 0xc7ab(%rip), %rsi      # 0x71ce5
callq 0x4390
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x65720
movq 0x30(%rsp), %rsi
leaq 0xc78d(%rip), %rdi      # 0x71ce9
movb $0x0, %al
callq 0xb0d0
movq 0x20(%rsp), %rcx
leaq 0x28(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x4640
movl %eax, 0x1c(%rsp)
cmpl $0x1, 0x1c(%rsp)
je 0x6558c
jmp 0x65735
movq 0x28(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x5388463(%rip), %rax   # 0x53eda00
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rsp)
cmpq $0x0, %rax
jle 0x65714
movq 0x10(%rsp), %rdi
addq $0x38, %rdi
movq 0x20(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4640
movl %eax, 0x1c(%rsp)
cmpl $0x1, 0x1c(%rsp)
je 0x655ed
jmp 0x65735
movq 0x10(%rsp), %rax
cmpl $0x0, 0x38(%rax)
je 0x65633
movq 0x10(%rsp), %rax
movq 0x40(%rax), %rdi
movq 0x10(%rsp), %rax
movl 0x38(%rax), %eax
movl %eax, %edx
movq 0x20(%rsp), %rcx
movl $0x4, %esi
callq 0x4640
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movq 0x10(%rsp), %rcx
cmpl 0x38(%rcx), %eax
je 0x65631
jmp 0x65735
jmp 0x65633
movq 0x10(%rsp), %rdi
addq $0x3c, %rdi
movq 0x20(%rsp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4640
movl %eax, 0x1c(%rsp)
cmpl $0x1, 0x1c(%rsp)
je 0x65660
jmp 0x65735
movq 0x10(%rsp), %rax
cmpl $0x0, 0x3c(%rax)
je 0x656fd
leaq 0x54ca3d3(%rip), %rax   # 0x552fa49
testb $0x1, (%rax)
je 0x656b4
movq 0x10(%rsp), %rax
movq 0x50(%rax), %rdi
leaq 0x18d8d(%rip), %rax     # 0x7e418
movl (%rax), %eax
movl %eax, %ecx
leaq 0x805a(%rip), %rax      # 0x6d6f0
movq (%rax,%rcx,8), %rsi
movq 0x10(%rsp), %rax
movl 0x3c(%rax), %eax
movl %eax, %edx
movq 0x20(%rsp), %rcx
callq 0x4640
movl %eax, 0x1c(%rsp)
jmp 0x656eb
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rdi
leaq 0x18d50(%rip), %rax     # 0x7e414
movl (%rax), %eax
movl %eax, %ecx
leaq 0x8001(%rip), %rax      # 0x6d6d0
movq (%rax,%rcx,8), %rsi
movq 0x10(%rsp), %rax
movl 0x3c(%rax), %eax
movl %eax, %edx
movq 0x20(%rsp), %rcx
callq 0x4640
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movq 0x10(%rsp), %rcx
cmpl 0x3c(%rcx), %eax
je 0x656fb
jmp 0x65735
jmp 0x656fd
jmp 0x656ff
movq 0x10(%rsp), %rax
addq $0x138, %rax            # imm = 0x138
movq %rax, 0x10(%rsp)
jmp 0x655a5
movq 0x20(%rsp), %rdi
callq 0x4310
jmp 0x65733
movq 0x30(%rsp), %rsi
leaq 0xc5da(%rip), %rdi      # 0x71d06
movb $0x0, %al
callq 0xb580
jmp 0x6575c
movq 0x20(%rsp), %rdi
callq 0x4310
movq 0x30(%rsp), %rdi
callq 0x4180
movq 0x30(%rsp), %rsi
leaq 0xc5e4(%rip), %rdi      # 0x71d39
movb $0x0, %al
callq 0xb9f0
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)