// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/lib/udc.c
// Function: connInfoGetSocket
static int connInfoGetSocket(struct udcFile *file, char *url, bits64 offset, int size)
/* If ci has an open socket and the given offset matches ci's current offset,
 * reuse ci->socket.  Otherwise close the socket, open a new one, and update ci,
 * or return -1 if there is an error opening a new one. */
{
/* NOTE: This doesn't use HTTP 1.1 keep alive to do multiple request on the
 * same socket.  The only way subsequent random requests on the same socket
 * work is because previous request are open-ended and this can continue
 * reading where it left off.  The HTTP requests are issued as 1.0, even
 * through range requests are a 1.1 feature.
 *
 * For FTP, the serial read approach is essential.  FTP only supports resuming
 * from an offset, but doesn't not support limiting the number of bytes
 * transferred.  All that can be done to stop the transfer is to abort the
 * operation, when then requires reconnecting.
 */ 

struct connInfo *ci = &file->connInfo;
if (ci != NULL && ci->socket > 0 && ci->offset != offset)
    {
    bits64 skipSize = (offset - ci->offset);
    if (skipSize > 0 && skipSize <= MAX_SKIP_TO_SAVE_RECONNECT)
	{
	verbose(4, "skipping %lld bytes @%lld to avoid reconnect\n", skipSize, ci->offset);
	udcReadAndIgnore(&file->ios.net, ci->socket, skipSize);
	ci->offset = offset;
        file->ios.numReuse++;
	}
    else
	{
	verbose(4, "Offset mismatch (ci %lld != new %lld), reopening.\n", ci->offset, offset);
	mustCloseFd(&(ci->socket));
	if (ci->ctrlSocket > 0)
	    mustCloseFd(&(ci->ctrlSocket));
	ZeroVar(ci);
	}
    }
int sd;
if (ci == NULL || ci->socket <= 0)
    {
    file->ios.numConnects++;
    if (ci->redirUrl)
	{
	url = transferParamsToRedirectedUrl(url, ci->redirUrl);
	}
    // IMPORTANT NOTE: byterange is not a real URL parameter, this is a hack to pass
    // the range to the net.c functions, which then parse it.
    char rangeUrl[2048];
    if (ci == NULL)
	{
	safef(rangeUrl, sizeof(rangeUrl), "%s;byterange=%lld-%lld",
	      url, offset, (offset + size - 1));
	sd = netUrlOpen(rangeUrl);
	}
    else
	{
	safef(rangeUrl, sizeof(rangeUrl), "%s;byterange=%lld-", url, offset);
	sd = ci->socket = netUrlOpenSockets(rangeUrl, &(ci->ctrlSocket));
	ci->offset = offset;
	}
    if (sd < 0)
	return -1;
    if (startsWith("http", url))
	{
	char *newUrl = NULL;
	int newSd = 0;
	if (!netSkipHttpHeaderLinesHandlingRedirect(sd, rangeUrl, &newSd, &newUrl))
	    return -1;
	if (newUrl)
	    {
	    freeMem(newUrl); 
	    sd = newSd;
	    if (ci != NULL)
		ci->socket = newSd;
	    }
	}
    }
else
    sd = ci->socket;
return sd;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x850, %rsp            # imm = 0x850
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
addq $0x90, %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x5bcb3
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x5bcb3
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x20(%rbp), %rax
je 0x5bcb3
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
subq 0x8(%rcx), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jbe 0x5bc64
cmpq $0x20000, -0x38(%rbp)   # imm = 0x20000
ja 0x5bc64
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x4, %edi
leaq 0x832ca(%rip), %rsi     # 0xdeee5
movb $0x0, %al
callq 0x60040
movq -0x10(%rbp), %rdi
addq $0xb8, %rdi
addq $0x78, %rdi
movq -0x30(%rbp), %rax
movl (%rax), %esi
movq -0x38(%rbp), %rdx
callq 0x5f0e0
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x160(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x160(%rax)
jmp 0x5bcb1
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x20(%rbp), %rcx
movl $0x4, %edi
leaq 0x83297(%rip), %rsi     # 0xdef13
movb $0x0, %al
callq 0x60040
movq -0x30(%rbp), %rdi
callq 0x2ff60
movq -0x30(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jle 0x5bca3
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
callq 0x2ff60
movq -0x30(%rbp), %rdi
movl $0x20, %esi
callq 0x5d190
jmp 0x5bcb3
cmpq $0x0, -0x30(%rbp)
je 0x5bcc7
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
jg 0x5be30
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x158(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x5bcfd
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x44c60
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x5bd46
leaq -0x840(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x20(%rbp), %r9
movslq -0x24(%rbp), %rax
addq %rax, %r9
subq $0x1, %r9
movl $0x800, %esi            # imm = 0x800
leaq 0x83218(%rip), %rdx     # 0xdef46
movb $0x0, %al
callq 0x31090
leaq -0x840(%rbp), %rdi
callq 0x442f0
movl %eax, -0x3c(%rbp)
jmp 0x5bd91
leaq -0x840(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movl $0x800, %esi            # imm = 0x800
leaq 0x831fc(%rip), %rdx     # 0xdef5d
movb $0x0, %al
callq 0x31090
leaq -0x840(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x10, %rsi
callq 0x43be0
movq -0x30(%rbp), %rcx
movl %eax, (%rcx)
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
cmpl $0x0, -0x3c(%rbp)
jge 0x5bda3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5be3f
movq -0x18(%rbp), %rsi
leaq 0x7ff9c(%rip), %rdi     # 0xdbd4a
callq 0x2d3d0
cmpl $0x0, %eax
je 0x5be2e
movq $0x0, -0x848(%rbp)
movl $0x0, -0x84c(%rbp)
movl -0x3c(%rbp), %edi
leaq -0x840(%rbp), %rsi
leaq -0x84c(%rbp), %rdx
leaq -0x848(%rbp), %rcx
callq 0x44d30
cmpl $0x0, %eax
jne 0x5bdf8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5be3f
cmpq $0x0, -0x848(%rbp)
je 0x5be2c
movq -0x848(%rbp), %rdi
callq 0x40d40
movl -0x84c(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x5be2a
movl -0x84c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
jmp 0x5be2c
jmp 0x5be2e
jmp 0x5be39
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x850, %rsp            # imm = 0x850
popq %rbp
retq
nopl (%rax,%rax)