// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/lib/net.c
// Function: netHttpGetMultiple
int netHttpGetMultiple(char *url, struct slName *queries, void *userData,
		       void (*responseCB)(void *userData, char *req,
					  char *hdr, struct dyString *body))
/* Given an URL which is the base of all requests to be made, and a 
 * linked list of queries to be appended to that base and sent in as 
 * requests, send the requests as a batch and read the HTTP response 
 * headers and bodies.  If not all the requests get responses (i.e. if 
 * the server is ignoring Keep-Alive or is imposing a limit), try again 
 * until we can't connect or until all requests have been served. 
 * For each HTTP response, do a callback. */
{
  struct slName *qStart;
  struct slName *qPtr;
  struct lineFile *lf;
  struct netParsedUrl *npu;
  struct dyString *dyQ    = newDyString(512);
  struct dyString *body;
  char *base;
  char *hdr;
  int qCount;
  int qTotal;
  int numParseFailures;
  int contentLength;
  boolean chunked;
  boolean done;
  boolean keepAlive;

  /* Find out how many queries we'll need to do so we know how many times 
   * it's OK to run into end of file in case server ignores Keep-Alive. */
  qTotal = 0;
  for (qPtr = queries;  qPtr != NULL;  qPtr = qPtr->next)
    {
      qTotal++;
    }

  done = FALSE;
  qCount = 0;
  numParseFailures = 0;
  qStart = queries;
  while ((! done) && (qStart != NULL))
    {
      lf = netHttpLineFileMayOpen(url, &npu);
      if (lf == NULL)
	{
	  done = TRUE;
	  break;
	}
      base = cloneString(npu->file);
      /* Send all remaining requests with keep-alive. */
      for (qPtr = qStart;  qPtr != NULL;  qPtr = qPtr->next)
	{
	  dyStringClear(dyQ);
	  dyStringAppend(dyQ, base);
	  dyStringAppend(dyQ, qPtr->name);
	  strcpy(npu->file, dyQ->string);
	  keepAlive = (qPtr->next == NULL) ? FALSE : TRUE;
	  netHttpGet(lf, npu, keepAlive);
	}
      /* Get as many responses as we can; call responseCB() and 
       * advance qStart for each. */
      for (qPtr = qStart;  qPtr != NULL;  qPtr = qPtr->next)
        {
	  if (lineFileParseHttpHeader(lf, &hdr, &chunked, &contentLength))
	    {
	      body = lineFileSlurpHttpBody(lf, chunked, contentLength);
	      dyStringClear(dyQ);
	      dyStringAppend(dyQ, base);
	      dyStringAppend(dyQ, qPtr->name);
	      responseCB(userData, dyQ->string, hdr, body);
	      qStart = qStart->next;
	      qCount++;
	    }
	  else
	    {
	      if (numParseFailures++ > qTotal) {
		done = TRUE;
	      }
	      break;
	    }
	}
    }

  return qCount;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, %rbx
movq %rdi, 0x28(%rsp)
movl $0x200, %edi            # imm = 0x200
callq 0x261d0
movq %rax, %r13
xorl %ebp, %ebp
movl $0x0, %r14d
testq %rbx, %rbx
je 0x31118
xorl %r14d, %r14d
movq %rbx, %rax
incl %r14d
movq (%rax), %rax
testq %rax, %rax
jne 0x3110d
testq %rbx, %rbx
je 0x31285
xorl %r15d, %r15d
movq $0x0, 0x18(%rsp)
xorl %ebp, %ebp
movl %r14d, 0xc(%rsp)
movq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x30eeb
testq %rax, %rax
je 0x31285
movq %rax, %r12
movl %r15d, 0x8(%rsp)
movq 0x20(%rsp), %rdi
movl $0x1820, %eax           # imm = 0x1820
addq %rax, %rdi
callq 0x1f9f6
movq %rbx, %r15
movq %rax, %rbx
movq %r15, 0x30(%rsp)
movl $0x0, 0x14(%r13)
movq 0x8(%r13), %rax
movb $0x0, (%rax)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x26425
leaq 0x8(%r15), %rsi
movq %r13, %rdi
callq 0x26425
movq 0x20(%rsp), %r14
leaq 0x1820(%r14), %rdi
movq 0x8(%r13), %rsi
callq 0x6680
xorl %edx, %edx
cmpq $0x0, (%r15)
setne %dl
movq %r12, %rdi
movq %r14, %rsi
callq 0x30f75
movq (%r15), %r15
testq %r15, %r15
jne 0x31171
movq %rbx, 0x48(%rsp)
movq 0x30(%rsp), %rbx
movq %rbx, %r15
movq %r12, %rdi
leaq 0x50(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x14(%rsp), %rcx
callq 0x2b8ae
testl %eax, %eax
je 0x31254
movl 0x10(%rsp), %esi
movl 0x14(%rsp), %edx
movq %r12, %rdi
callq 0x2bafc
movq %rax, %r14
movl $0x0, 0x14(%r13)
movq 0x8(%r13), %rax
movb $0x0, (%rax)
movq %r13, %rdi
movq 0x48(%rsp), %rsi
callq 0x26425
leaq 0x8(%r15), %rsi
movq %r13, %rdi
callq 0x26425
movq 0x8(%r13), %rsi
movq 0x50(%rsp), %rdx
movq 0x38(%rsp), %rdi
movq %r14, %rcx
callq *0x40(%rsp)
movq (%rbx), %rbx
incl %ebp
movq (%r15), %r15
testq %r15, %r15
jne 0x311d5
movl 0x8(%rsp), %r15d
jmp 0x31277
movl 0xc(%rsp), %r14d
movq 0x18(%rsp), %rax
cmpl %r14d, %eax
leal 0x1(%rax), %eax
movl 0x8(%rsp), %r15d
movl $0x1, %ecx
cmovgl %ecx, %r15d
movq %rax, 0x18(%rsp)
testl %r15d, %r15d
jne 0x31285
testq %rbx, %rbx
jne 0x31134
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq