// File: /workspace/github_c_makefile_star2_O3/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 0x6d1c9
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 0x68ae8
leaq 0xf5bb(%rip), %rcx      # 0x78068
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x2b0(%rbx), %edi
callq 0xc2b0
jmp 0x68ae8
movq 0x2b0(%rbx), %rax
testq %rax, %rax
je 0x68ae8
orb $0x10, 0xa0(%rax)
movq 0x2b0(%rbx), %rax
movq $0x0, 0x80(%rax)
andb %r15b, %r12b
movl 0x284(%rbx), %eax
testl %eax, %eax
jle 0x68c68
cmpl $0x190, %eax            # imm = 0x190
je 0x68c68
cmpl $0x5, 0x2b8(%rbx)
je 0x68c68
movq 0x2a8(%rbx), %rax
movq 0x40(%rax), %rdi
testq %rdi, %rdi
je 0x68c68
leaq 0x10916(%rip), %rsi     # 0x79442
callq 0xcb90
testq %rax, %rax
je 0x68c68
movq %rax, %r15
xorl %edi, %edi
callq 0xc820
leaq -0x40(%rbp), %rdi
movq %rax, (%rdi)
callq 0xc770
leaq 0x108ee(%rip), %rdx     # 0x79445
leaq -0x80(%rbp), %rdi
movl $0x40, %esi
movq %rax, %rcx
callq 0xc9d0
movq %r15, %rdi
callq 0xcbb0
leaq 0xbd9c(%rip), %rsi      # 0x74913
movq %r14, %rdi
callq 0x67c6a
leaq 0x8c80(%rip), %rsi      # 0x71806
leaq -0xf0(%rbp), %r13
movl $0x64, %ecx
movq %rax, %rdi
movq %r13, %rdx
callq 0x6928c
cmpb $0x0, (%r13)
leaq 0x108d8(%rip), %rax     # 0x79481
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 0xeaa1(%rip), %rax      # 0x77672
leaq 0xcafe(%rip), %rcx      # 0x756d6
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 0x1085d(%rip), %rsi     # 0x7945a
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 0xbcbd(%rip), %rsi      # 0x748e3
movq %r14, %rdi
movq %r15, %rdx
callq 0x6da12
leaq 0xbcc0(%rip), %rsi      # 0x748f8
movq %r14, %rdi
movq %r15, %rdx
callq 0x6da12
movl $0xa, %edi
movq %r15, %rsi
callq 0xc970
movq %r15, %rdi
callq 0xc5b0
movq %r15, %rdi
callq 0xc620
movq %r15, %rdi
callq 0xc4c0
movq (%rbx), %rdi
addq $0x40, %rdi
callq 0x66379
movq 0x2c8(%rbx), %rdi
callq 0xc250
movq 0x2c0(%rbx), %rdi
callq 0xc250
xorl %edx, %edx
movq %rdx, 0x2b0(%rbx)
movl %edx, 0x2b8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x2c0(%rbx)
movups %xmm0, 0x2d0(%rbx)
movq %rdx, 0x2e0(%rbx)
movq (%rbx), %rax
movl $0xffcfffec, %ecx       # imm = 0xFFCFFFEC
andl 0xa0(%rax), %ecx
movl %ecx, 0xa0(%rax)
movl %edx, 0x8c(%rbx)
movq %rdx, 0x2a0(%rbx)
movups %xmm0, 0x10(%r14)
movups %xmm0, (%r14)
movups %xmm0, 0x278(%rbx)
testb %r12b, %r12b
je 0x68cf3
movq %rbx, %rdi
callq 0x6d299
jmp 0x68d0d
cmpq $0x0, 0x60(%rax)
movl $0x10, %edx
movl $0x1, %esi
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