// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/lib/net.c
// Function: receiveFtpReply
static boolean receiveFtpReply(int sd, char *cmd, struct dyString **retReply, int *retCode)
/* send command to ftp server and check resulting reply code, 
 * warn and return FALSE if not desired reply.  If retReply is non-NULL, store reply text there. */
{
char *startLastLine = NULL;
struct dyString *rs = newDyString(4*1024);
while (1)
    {
    int readSize = 0;
    while (1)
	{
	char buf[4*1024];
	if (!readReadyWait(sd, NET_FTP_TIMEOUT))
	    {
	    warn("ftp server response timed out > %d microsec", NET_FTP_TIMEOUT);
	    return FALSE;
	    }
	if ((readSize = read(sd, buf, sizeof(buf))) == 0)
	    break;

	dyStringAppendN(rs, buf, readSize);
	if (endsWith(rs->string,"\n"))
	    break;
	}
	
    /* find the start of the last line in the buffer */
    startLastLine = rs->string+strlen(rs->string)-1;
    if (startLastLine >= rs->string)
	if (*startLastLine == '\n') 
	    --startLastLine;
    while ((startLastLine >= rs->string) && (*startLastLine != '\n'))
	--startLastLine;
    ++startLastLine;
	
    if (strlen(startLastLine)>4)
      if (
	isdigit(startLastLine[0]) &&
	isdigit(startLastLine[1]) &&
	isdigit(startLastLine[2]) &&
	startLastLine[3]==' ')
	break;
	
    if (readSize == 0)
	break;  // EOF
    /* must be some text info we can't use, ignore it till we get status code */
    }

int reply = atoi(startLastLine);
if ((reply < 200) || (reply > 399))
    {
    warn("ftp server error on cmd=[%s] response=[%s]",cmd,rs->string);
    return FALSE;
    }
    
if (retReply)
    *retReply = rs;
else
    dyStringFree(&rs);
if (retCode)
    *retCode = reply;
return TRUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1028, %rsp           # imm = 0x1028
movq %rcx, (%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, 0x18(%rsp)
movl %edi, %ebp
movl $0x1000, %edi           # imm = 0x1000
callq 0x264e0
movq %rax, %r12
movq %rax, 0x8(%rsp)
movl %ebp, %edi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x2f372
testl %eax, %eax
je 0x317c6
leaq 0x20(%rsp), %r14
movl $0x1000, %edx           # imm = 0x1000
movl %ebp, %edi
movq %r14, %rsi
callq 0x6aa0
movq %rax, %rbx
testl %ebx, %ebx
je 0x316dd
movq %r12, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x265ea
movq 0x8(%rsp), %r12
movq 0x8(%r12), %rdi
leaq 0x5db91(%rip), %rsi     # 0x8f261
callq 0x21e4c
testl %eax, %eax
je 0x31772
movq 0x8(%r12), %r15
movq %r15, %rdi
callq 0x62d0
leaq (%r15,%rax), %r13
decq %r13
cmpq %r15, %r13
jb 0x31705
addq %r15, %rax
leaq -0x2(%rax), %rcx
cmpb $0xa, -0x1(%rax)
cmoveq %rcx, %r13
cmpq %r15, %r13
jb 0x31716
cmpb $0xa, (%r13)
je 0x31716
decq %r13
jmp 0x31705
leaq 0x1(%r13), %r14
movq %r14, %rdi
callq 0x62d0
cmpq $0x5, %rax
jb 0x31753
callq 0x6790
movq (%rax), %rax
movsbq (%r14), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x31753
movsbq 0x2(%r13), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x31753
movsbq 0x3(%r13), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x31788
testl %ebx, %ebx
je 0x31793
movl %ebp, %edi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x2f372
testl %eax, %eax
leaq 0x20(%rsp), %r14
jne 0x3169c
jmp 0x317c6
movl %ebp, %edi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x2f372
testl %eax, %eax
jne 0x3169c
jmp 0x317c6
testl %ebx, %ebx
je 0x31793
cmpb $0x20, 0x4(%r13)
jne 0x31757
movq %r14, %rdi
callq 0x6bd0
movl %eax, %r14d
leal -0x190(%r14), %eax
cmpl $0xffffff37, %eax       # imm = 0xFFFFFF37
ja 0x317ef
leaq 0x61185(%rip), %rdi     # 0x92938
xorl %ebx, %ebx
movq 0x18(%rsp), %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x26bea
jmp 0x317db
leaq 0x6113f(%rip), %rdi     # 0x9290c
xorl %ebx, %ebx
movl $0xf4240, %esi          # imm = 0xF4240
xorl %eax, %eax
callq 0x26bea
movl %ebx, %eax
addq $0x1028, %rsp           # imm = 0x1028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x317fe
movq %r12, (%rax)
jmp 0x31808
leaq 0x8(%rsp), %rdi
callq 0x2651d
movq (%rsp), %rax
movl $0x1, %ebx
testq %rax, %rax
je 0x317db
movl %r14d, (%rax)
jmp 0x317db