// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/mongoose/mongoose.c
// Function: close_local_endpoint
static void close_local_endpoint(struct connection *conn) {
  struct mg_connection *c = &conn->mg_conn;
  // Must be done before free()
  int keep_alive = should_keep_alive(&conn->mg_conn) &&
    (conn->endpoint_type == EP_FILE || conn->endpoint_type == EP_USER);
  DBG(("%p %d %d %d", conn, conn->endpoint_type, keep_alive,
       conn->ns_conn->flags));

  switch (conn->endpoint_type) {
    case EP_PUT:
    case EP_FILE:
      close(conn->endpoint.fd);
      break;
    case EP_CGI:
    case EP_PROXY:
      if (conn->endpoint.nc != NULL) {
        DBG(("%p %p %p :-)", conn, conn->ns_conn, conn->endpoint.nc));
        conn->endpoint.nc->flags |= NSF_CLOSE_IMMEDIATELY;
        conn->endpoint.nc->user_data = NULL;
      }
      break;
    default: break;
  }

#ifndef MONGOOSE_NO_LOGGING
  if (c->status_code > 0 && conn->endpoint_type != EP_CLIENT &&
      c->status_code != 400) {
    log_access(conn, conn->server->config_options[ACCESS_LOG_FILE]);
  }
#endif

  // Gobble possible POST data sent to the URI handler
  iobuf_free(&conn->ns_conn->recv_iobuf);
  NS_FREE(conn->request);
  NS_FREE(conn->path_info);
  conn->endpoint.nc = NULL;
  conn->request = conn->path_info = NULL;

  conn->endpoint_type = EP_NONE;
  conn->cl = conn->num_bytes_recv = conn->request_len = 0;
  conn->ns_conn->flags &= ~(NSF_FINISHED_SENDING_DATA |
                            NSF_BUFFER_BUT_DONT_SEND | NSF_CLOSE_IMMEDIATELY |
                            MG_HEADERS_SENT | MG_USING_CHUNKED_API);

  // Do not memset() the whole structure, as some of the fields
  // (IP addresses & ports, server_param) must survive. Nullify the rest.
  c->request_method = c->uri = c->http_version = c->query_string = NULL;
  c->num_headers = c->status_code = c->is_websocket = c->content_len = 0;
  c->callback_param = NULL;

  if (keep_alive) {
    on_recv_data(conn);  // Can call us recursively if pipelining is used
  } else {
    conn->ns_conn->flags |= conn->ns_conn->send_iobuf.len == 0 ?
      NSF_CLOSE_IMMEDIATELY : NSF_FINISHED_SENDING_DATA;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
movq %r14, %rdi
callq 0x5dd35
testl %eax, %eax
setne %r12b
movl 0x2b8(%rbx), %eax
movl %eax, %ecx
andl $-0x3, %ecx
cmpl $0x1, %ecx
sete %r15b
decl %eax
cmpl $0x5, %eax
ja 0x59b86
leaq 0xe4fa(%rip), %rcx      # 0x68048
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x2b0(%rbx), %edi
callq 0xc2b0
jmp 0x59b86
movq 0x2b0(%rbx), %rax
testq %rax, %rax
je 0x59b86
orb $0x10, 0xa0(%rax)
movq 0x2b0(%rbx), %rax
andq $0x0, 0x80(%rax)
andb %r15b, %r12b
movl 0x284(%rbx), %eax
testl %eax, %eax
jle 0x59d00
cmpl $0x190, %eax            # imm = 0x190
je 0x59d00
cmpl $0x5, 0x2b8(%rbx)
je 0x59d00
movq 0x2a8(%rbx), %rax
movq 0x40(%rax), %rdi
testq %rdi, %rdi
je 0x59d00
leaq 0xf858(%rip), %rsi      # 0x69422
callq 0xcbb0
testq %rax, %rax
je 0x59d00
movq %rax, %r15
xorl %edi, %edi
callq 0xc850
leaq -0x40(%rbp), %rdi
movq %rax, (%rdi)
callq 0xc7a0
leaq 0xf830(%rip), %rdx      # 0x69425
leaq -0x80(%rbp), %rdi
pushq $0x40
popq %rsi
movq %rax, %rcx
callq 0xca00
movq %r15, %rdi
callq 0xcbd0
leaq 0xace0(%rip), %rsi      # 0x648f3
movq %r14, %rdi
callq 0x58dc0
leaq 0x7bb4(%rip), %rsi      # 0x617d6
leaq -0xf0(%rbp), %r13
pushq $0x64
popq %rcx
movq %rax, %rdi
movq %r13, %rdx
callq 0x5a2ed
cmpb $0x0, (%r13)
leaq 0xf81e(%rip), %rax      # 0x69461
cmoveq %rax, %r13
movq 0x8(%rbx), %r9
movq 0x10(%rbx), %r10
testq %r9, %r9
cmoveq %rax, %r9
testq %r10, %r10
cmoveq %rax, %r10
movq 0x20(%rbx), %r11
testq %r11, %r11
leaq 0xd9e7(%rip), %rax      # 0x67652
leaq 0xba44(%rip), %rcx      # 0x656b6
cmoveq %rax, %rcx
movq %rcx, -0x38(%rbp)
leaq 0x28(%rbx), %rdx
cmoveq %rax, %r11
movl 0x284(%rbx), %eax
movq %rax, -0x30(%rbp)
subq $0x8, %rsp
leaq 0xf7a3(%rip), %rsi      # 0x6943a
movq %r15, %rdi
movq %r13, %rcx
leaq -0x80(%rbp), %r8
xorl %eax, %eax
pushq -0x30(%rbp)
pushq 0x18(%rbx)
pushq %r11
pushq -0x38(%rbp)
pushq %r10
callq 0xc260
addq $0x30, %rsp
leaq 0xac03(%rip), %rsi      # 0x648c3
movq %r14, %rdi
movq %r15, %rdx
callq 0x5e47e
leaq 0xac06(%rip), %rsi      # 0x648d8
movq %r14, %rdi
movq %r15, %rdx
callq 0x5e47e
pushq $0xa
popq %rdi
movq %r15, %rsi
callq 0xc990
movq %r15, %rdi
callq 0xc5c0
movq %r15, %rdi
callq 0xc630
movq %r15, %rdi
callq 0xc4c0
movq (%rbx), %rdi
addq $0x40, %rdi
callq 0x57682
movq 0x2c8(%rbx), %rdi
callq 0xc250
movq 0x2c0(%rbx), %rdi
callq 0xc250
andq $0x0, 0x2b0(%rbx)
andl $0x0, 0x2b8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x2c0(%rbx)
movups %xmm0, 0x2d0(%rbx)
andq $0x0, 0x2e0(%rbx)
movq (%rbx), %rax
movl $0xffcfffec, %ecx       # imm = 0xFFCFFFEC
andl 0xa0(%rax), %ecx
movl %ecx, 0xa0(%rax)
andl $0x0, 0x8c(%rbx)
andq $0x0, 0x2a0(%rbx)
movups %xmm0, 0x10(%r14)
movups %xmm0, (%r14)
movups %xmm0, 0x278(%rbx)
testb %r12b, %r12b
je 0x59d8e
movq %rbx, %rdi
callq 0x5ddba
jmp 0x59da4
cmpq $0x0, 0x60(%rax)
pushq $0x10
popq %rdx
pushq $0x1
popq %rsi
cmovel %edx, %esi
orl %ecx, %esi
movl %esi, 0xa0(%rax)
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq