// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1060, %rsp           # imm = 0x1060
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x1000, %edi           # imm = 0x1000
callq 0x35020
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x8(%rbp), %edi
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x45e00
cmpl $0x0, %eax
jne 0x45ed8
leaq 0x96804(%rip), %rdi     # 0xdc6c4
movl $0xf4240, %esi          # imm = 0xF4240
movb $0x0, %al
callq 0x358e0
movl $0x0, -0x4(%rbp)
jmp 0x460e0
movl -0x8(%rbp), %edi
leaq -0x1040(%rbp), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x6a90
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
jne 0x45ef6
jmp 0x45f26
movq -0x30(%rbp), %rdi
leaq -0x1040(%rbp), %rsi
movl -0x34(%rbp), %edx
callq 0x351f0
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x93101(%rip), %rsi     # 0xd9019
callq 0x2d9a0
cmpl $0x0, %eax
je 0x45f24
jmp 0x45f26
jmp 0x45ea7
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x1050(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x62c0
movq %rax, %rcx
movq -0x1050(%rbp), %rax
addq %rcx, %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jb 0x45f7f
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x45f7d
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x45f7f
jmp 0x45f81
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rdx
xorl %eax, %eax
cmpq 0x8(%rdx), %rcx
movb %al, -0x1051(%rbp)
jb 0x45faa
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
setne %al
movb %al, -0x1051(%rbp)
movb -0x1051(%rbp), %al
testb $0x1, %al
jne 0x45fb6
jmp 0x45fc4
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x45f81
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x62c0
cmpq $0x4, %rax
jbe 0x46052
callq 0x6780
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x46050
callq 0x6780
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movsbl 0x1(%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x46050
callq 0x6780
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movsbl 0x2(%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x46050
movq -0x28(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x20, %eax
jne 0x46050
jmp 0x4605f
jmp 0x46052
cmpl $0x0, -0x34(%rbp)
jne 0x4605a
jmp 0x4605f
jmp 0x45ea0
movq -0x28(%rbp), %rdi
callq 0x6bd0
movl %eax, -0x1044(%rbp)
cmpl $0xc8, -0x1044(%rbp)
jl 0x46086
cmpl $0x18f, -0x1044(%rbp)   # imm = 0x18F
jle 0x460a9
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x96657(%rip), %rdi     # 0xdc6f0
movb $0x0, %al
callq 0x358e0
movl $0x0, -0x4(%rbp)
jmp 0x460e0
cmpq $0x0, -0x18(%rbp)
je 0x460bd
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x460c6
leaq -0x30(%rbp), %rdi
callq 0x35080
cmpq $0x0, -0x20(%rbp)
je 0x460d9
movl -0x1044(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1060, %rsp           # imm = 0x1060
popq %rbp
retq
nopl (%rax)