// File: /workspace/github_c_makefile_star2_O1/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, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, 0x18(%rsp)
movl %edi, %ebp
movl $0x1000, %edi           # imm = 0x1000
callq 0x261d0
movq %rax, (%rsp)
leaq 0x61490(%rip), %r12     # 0x9281c
leaq 0x20(%rsp), %r13
leaq 0x5de09(%rip), %r14     # 0x8f1a1
xorl %r15d, %r15d
xorl %ebx, %ebx
movl %ebp, %edi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x2f00f
testl %eax, %eax
je 0x313ed
movl $0x1000, %edx           # imm = 0x1000
movl %ebp, %edi
movq %r13, %rsi
callq 0x6aa0
movq %rax, %rbx
testl %ebx, %ebx
je 0x31403
movq (%rsp), %rdi
movq %r13, %rsi
movl %ebx, %edx
callq 0x262da
movq (%rsp), %rax
movq 0x8(%rax), %rdi
movq %r14, %rsi
callq 0x21aed
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
leal (%rcx,%rcx,4), %eax
jmp 0x3140a
movq %r12, %rdi
movl $0xf4240, %esi          # imm = 0xF4240
xorl %eax, %eax
callq 0x268ca
movl $0x1, %eax
jmp 0x3140a
movl $0x5, %eax
xorl %ebx, %ebx
testl %eax, %eax
je 0x3139d
cmpl $0x5, %eax
jne 0x314b1
movq (%rsp), %rax
movq 0x8(%rax), %r15
movq %r15, %rdi
callq 0x62d0
leaq (%r15,%rax), %r12
decq %r12
cmpq %r15, %r12
jb 0x31442
addq %r15, %rax
leaq -0x2(%rax), %rcx
cmpb $0xa, -0x1(%rax)
cmoveq %rcx, %r12
cmpq %r15, %r12
jb 0x31453
cmpb $0xa, (%r12)
je 0x31453
decq %r12
jmp 0x31442
leaq 0x1(%r12), %r15
movq %r15, %rdi
callq 0x62d0
cmpq $0x5, %rax
jb 0x314a0
callq 0x6790
movq (%rax), %rax
movsbq (%r15), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x314a0
movsbq 0x2(%r12), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x314a0
movsbq 0x3(%r12), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x314a0
movl $0x3, %eax
cmpb $0x20, 0x4(%r12)
je 0x314aa
xorl %eax, %eax
testl %ebx, %ebx
sete %al
leal (%rax,%rax,2), %eax
leaq 0x6136b(%rip), %r12     # 0x9281c
testl %eax, %eax
je 0x3139b
cmpl $0x3, %eax
jne 0x314f4
movq %r15, %rdi
callq 0x6bd0
movl %eax, %ebx
leal -0x190(%rbx), %eax
cmpl $0xffffff37, %eax       # imm = 0xFFFFFF37
ja 0x314f8
movq (%rsp), %rax
movq 0x8(%rax), %rdx
leaq 0x61364(%rip), %rdi     # 0x92848
xorl %ebp, %ebp
movq 0x18(%rsp), %rsi
xorl %eax, %eax
callq 0x268ca
jmp 0x31524
xorl %ebp, %ebp
jmp 0x31524
movq 0x10(%rsp), %rcx
testq %rcx, %rcx
je 0x3150b
movq (%rsp), %rax
movq %rax, (%rcx)
jmp 0x31513
movq %rsp, %rdi
callq 0x2620d
movq 0x8(%rsp), %rax
movl $0x1, %ebp
testq %rax, %rax
je 0x31524
movl %ebx, (%rax)
movl %ebp, %eax
addq $0x1028, %rsp           # imm = 0x1028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq