// File: /workspace/github_cpp_makefile_star2_O2/nilnilnil[P]autocomplete/deps/mongoose/mongoose.c
// Function: worker_thread
static void worker_thread(struct mg_context *ctx) {
  struct mg_connection *conn;
  int buf_size = atoi(ctx->config[MAX_REQUEST_SIZE]);

  conn = (struct mg_connection *) calloc(1, sizeof(*conn) + buf_size);
  conn->buf_size = buf_size;
  conn->buf = (char *) (conn + 1);
  assert(conn != NULL);

  while (ctx->stop_flag == 0 && consume_socket(ctx, &conn->client)) {
    conn->birth_time = time(NULL);
    conn->ctx = ctx;

    // Fill in IP, port info early so even if SSL setup below fails,
    // error handler would have the corresponding info.
    // Thanks to Johannes Winkelmann for the patch.
    conn->request_info.remote_port = ntohs(conn->client.rsa.u.sin.sin_port);
    memcpy(&conn->request_info.remote_ip,
           &conn->client.rsa.u.sin.sin_addr.s_addr, 4);
    conn->request_info.remote_ip = ntohl(conn->request_info.remote_ip);
    conn->request_info.is_ssl = conn->client.is_ssl;

    if (!conn->client.is_ssl ||
        (conn->client.is_ssl && sslize(conn, SSL_accept))) {
      process_new_connection(conn);
    }

    close_connection(conn);
  }
  free(conn);

  // Signal master that we're done with connection and exiting
  (void) pthread_mutex_lock(&ctx->mutex);
  ctx->num_threads--;
  (void) pthread_cond_signal(&ctx->cond);
  assert(ctx->num_threads >= 0);
  (void) pthread_mutex_unlock(&ctx->mutex);

  DEBUG_TRACE(("exiting"));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x88(%rdi), %rdi
callq 0x5810
movslq %eax, %r14
movl $0x4e0, %r12d           # imm = 0x4E0
leaq (%r14,%r12), %rsi
pushq $0x1
popq %rdi
callq 0x52d0
movq %rax, %r15
movl %r14d, 0x4d0(%rax)
addq %rax, %r12
movq %r12, 0x4c8(%rax)
movq %rax, %rbp
addq $0x468, %rbp            # imm = 0x468
leaq 0xe0(%rbx), %r14
leaq 0x640(%rbx), %r12
leaq 0x138(%rbx), %r13
leaq 0x670(%rbx), %rax
movq %rax, (%rsp)
cmpl $0x0, (%rbx)
jne 0xd394
movq %r14, %rdi
callq 0x5750
movl 0x638(%rbx), %eax
cmpl 0x63c(%rbx), %eax
jne 0xd2ab
cmpl $0x0, (%rbx)
jne 0xd2ab
movq %r12, %rdi
movq %r14, %rsi
callq 0x57c0
jmp 0xd28b
cmpl $0x0, (%rbx)
jne 0xd38c
movslq 0x63c(%rbx), %rax
xorl %edx, %edx
pushq $0x14
popq %rcx
divq %rcx
shll $0x6, %edx
movups (%r13,%rdx), %xmm0
movups 0x10(%r13,%rdx), %xmm1
movups 0x20(%r13,%rdx), %xmm2
movups 0x30(%r13,%rdx), %xmm3
movups %xmm3, 0x30(%rbp)
movups %xmm2, 0x20(%rbp)
movups %xmm1, 0x10(%rbp)
movups %xmm0, (%rbp)
incl 0x63c(%rbx)
movl 0x63c(%rbx), %eax
cmpl $0x15, %eax
jl 0xd30f
addl $-0x14, 0x63c(%rbx)
addl $-0x14, 0x638(%rbx)
jmp 0xd2f4
movq (%rsp), %rdi
callq 0x5030
movq %r14, %rdi
callq 0x5350
xorl %edi, %edi
callq 0x5420
movq %rax, 0x4a8(%r15)
movq %rbx, 0x458(%r15)
movzwl 0x48e(%r15), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x48(%r15)
movl 0x490(%r15), %eax
bswapl %eax
movq %rax, 0x40(%r15)
movl 0x49c(%r15), %eax
movl %eax, 0x50(%r15)
testl %eax, %eax
je 0xd377
movq 0xd49d(%rip), %rsi      # 0x1a808
movq %r15, %rdi
callq 0xdfda
testl %eax, %eax
je 0xd37f
movq %r15, %rdi
callq 0xe031
movq %r15, %rdi
callq 0x10419
jmp 0xd27a
movq %r14, %rdi
callq 0x5350
movq %r15, %rdi
callq 0x55b0
movq %r14, %rdi
callq 0x5750
decl 0xd8(%rbx)
addq $0x108, %rbx            # imm = 0x108
movq %rbx, %rdi
callq 0x5030
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5350