// File: /workspace/github_c_makefile_star2_O2/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, 0x18(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
movl %edi, %ebp
movl $0x1000, %edi           # imm = 0x1000
callq 0x21bcc
movq %rax, %r12
movq %rax, (%rsp)
movl %ebp, %edi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x2c03a
testl %eax, %eax
je 0x2c1bc
movl $0x1000, %edx           # imm = 0x1000
movl %ebp, %edi
leaq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x6aa0
movq %rax, %r15
testl %r15d, %r15d
je 0x2c0f8
movq %r12, %rdi
movq %rbx, %rsi
movl %r15d, %edx
callq 0x21cc8
movq (%rsp), %r12
movq 0x8(%r12), %rdi
leaq 0x520a2(%rip), %rsi     # 0x7e191
callq 0x1de0f
testl %eax, %eax
je 0x2c0a1
movq 0x8(%r12), %rbx
movq %rbx, %rdi
callq 0x62d0
leaq (%rbx,%rax), %r13
decq %r13
cmpq %rbx, %r13
jb 0x2c120
addq %rbx, %rax
leaq -0x2(%rax), %rcx
cmpb $0xa, -0x1(%rax)
cmoveq %rcx, %r13
cmpq %rbx, %r13
jb 0x2c131
cmpb $0xa, (%r13)
je 0x2c131
decq %r13
jmp 0x2c120
leaq 0x1(%r13), %r14
movq %r14, %rdi
callq 0x62d0
cmpq $0x5, %rax
jb 0x2c16e
callq 0x6790
movq (%rax), %rax
movsbq (%r14), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x2c16e
movsbq 0x2(%r13), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x2c16e
movsbq 0x3(%r13), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x2c179
testl %r15d, %r15d
jne 0x2c0a1
jmp 0x2c189
testl %r15d, %r15d
je 0x2c189
cmpb $0x20, 0x4(%r13)
jne 0x2c0a1
movq %r14, %rdi
callq 0x6bd0
movl %eax, %r14d
leal -0x190(%r14), %eax
cmpl $0xffffff37, %eax       # imm = 0xFFFFFF37
ja 0x2c1e5
leaq 0x5568f(%rip), %rdi     # 0x81838
xorl %ebp, %ebp
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x22186
jmp 0x2c1d1
leaq 0x55649(%rip), %rdi     # 0x8180c
xorl %ebp, %ebp
movl $0xf4240, %esi          # imm = 0xF4240
xorl %eax, %eax
callq 0x22186
movl %ebp, %eax
addq $0x1028, %rsp           # imm = 0x1028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x2c1f4
movq %r12, (%rax)
jmp 0x2c1fc
movq %rsp, %rdi
callq 0x21c07
pushq $0x1
popq %rbp
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x2c1d1
movl %r14d, (%rax)
jmp 0x2c1d1