// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/lib/net.c
// Function: sendFtpDataToPipeThread
static void *sendFtpDataToPipeThread(void *threadParams)
/* This is to be executed by the child process after the fork in netGetOpenFtpSockets.
 * It keeps the ftp control socket alive while reading from the ftp data socket
 * and writing to the pipe to the parent process, which closes the ftp sockets
 * and reads from the pipe. */
{

struct netConnectFtpParams *params = threadParams;

pthread_detach(params->thread);  // this thread will never join back with it's progenitor

char buf[32768];
int rd = 0;
long long dataPos = 0; 
if (params->npu.byteRangeStart != -1)
    dataPos = params->npu.byteRangeStart;
while((rd = read(params->sdata, buf, 32768)) > 0) 
    {
    if (params->npu.byteRangeEnd != -1 && (dataPos + rd) > params->npu.byteRangeEnd)
	rd = params->npu.byteRangeEnd - dataPos + 1;
    int wt = write(params->pipefd[1], buf, rd);
    if (wt == -1 && params->npu.byteRangeEnd != -1)
	{
	// errAbort in child process is messy; let reader complain if
	// trouble.  If byterange was open-ended, we will hit this point
	// when the parent stops reading and closes the pipe.
	errnoWarn("error writing ftp data to pipe");
	break;
	}
    dataPos += rd;
    if (params->npu.byteRangeEnd != -1 && dataPos >= params->npu.byteRangeEnd)
	break;	    
    }
if (rd == -1)
    // Again, avoid abort in child process.
    errnoWarn("error reading ftp socket");
close(params->pipefd[1]);  /* we are done with it */
close(params->sd);
close(params->sdata);
return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x8030, %rsp           # imm = 0x8030
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x6490
movl $0x0, -0x8014(%rbp)
movq $0x0, -0x8020(%rbp)
movq -0x10(%rbp), %rax
cmpq $-0x1, 0x2838(%rax)
je 0x461f8
movq -0x10(%rbp), %rax
movq 0x2838(%rax), %rax
movq %rax, -0x8020(%rbp)
jmp 0x461fa
movq -0x10(%rbp), %rax
movl 0x14(%rax), %edi
leaq -0x8010(%rbp), %rsi
movl $0x8000, %edx           # imm = 0x8000
callq 0x6a90
movl %eax, -0x8014(%rbp)
cmpl $0x0, %eax
jle 0x462ee
movq -0x10(%rbp), %rax
cmpq $-0x1, 0x2840(%rax)
je 0x46269
movq -0x8020(%rbp), %rax
movslq -0x8014(%rbp), %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
cmpq 0x2840(%rcx), %rax
jle 0x46269
movq -0x10(%rbp), %rax
movq 0x2840(%rax), %rax
subq -0x8020(%rbp), %rax
addq $0x1, %rax
movl %eax, -0x8014(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %edi
leaq -0x8010(%rbp), %rsi
movslq -0x8014(%rbp), %rdx
callq 0x6250
movl %eax, -0x8024(%rbp)
cmpl $-0x1, -0x8024(%rbp)
jne 0x462b0
movq -0x10(%rbp), %rax
cmpq $-0x1, 0x2840(%rax)
je 0x462b0
leaq 0x966c7(%rip), %rdi     # 0xdc96e
movb $0x0, %al
callq 0x35bd0
jmp 0x462ee
movslq -0x8014(%rbp), %rax
addq -0x8020(%rbp), %rax
movq %rax, -0x8020(%rbp)
movq -0x10(%rbp), %rax
cmpq $-0x1, 0x2840(%rax)
je 0x462e9
movq -0x8020(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x2840(%rcx), %rax
jl 0x462e9
jmp 0x462ee
jmp 0x461fa
cmpl $-0x1, -0x8014(%rbp)
jne 0x46305
leaq 0x9668f(%rip), %rdi     # 0xdc98d
movb $0x0, %al
callq 0x35bd0
movq -0x10(%rbp), %rax
movl 0xc(%rax), %edi
callq 0x6e90
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x6e90
movq -0x10(%rbp), %rax
movl 0x14(%rax), %edi
callq 0x6e90
xorl %eax, %eax
addq $0x8030, %rsp           # imm = 0x8030
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop