// File: /workspace/github_c_makefile_star2_O1/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 0x6ed8f
testl %eax, %eax
je 0x6a64e
movl 0x2b8(%rbx), %eax
andl $-0x3, %eax
cmpl $0x1, %eax
sete %r12b
jmp 0x6a651
xorl %r12d, %r12d
movl 0x2b8(%rbx), %eax
decl %eax
cmpl $0x5, %eax
ja 0x6a6a0
leaq 0xfa03(%rip), %rcx      # 0x7a068
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x2b0(%rbx), %edi
callq 0xc2b0
jmp 0x6a6a0
movq 0x2b0(%rbx), %rax
testq %rax, %rax
je 0x6a6a0
orb $0x10, 0xa0(%rax)
movq 0x2b0(%rbx), %rax
movq $0x0, 0x80(%rax)
movl 0x284(%rbx), %eax
testl %eax, %eax
jle 0x6a821
cmpl $0x190, %eax            # imm = 0x190
je 0x6a821
cmpl $0x5, 0x2b8(%rbx)
je 0x6a821
movq 0x2a8(%rbx), %rax
movq 0x40(%rax), %rdi
testq %rdi, %rdi
je 0x6a6e7
leaq 0x10d65(%rip), %rsi     # 0x7b442
callq 0xcb90
movq %rax, %r15
jmp 0x6a6ea
xorl %r15d, %r15d
testq %r15, %r15
je 0x6a821
xorl %edi, %edi
callq 0xc820
leaq -0x40(%rbp), %rdi
movq %rax, (%rdi)
callq 0xc770
leaq 0x10d38(%rip), %rdx     # 0x7b445
leaq -0x80(%rbp), %rdi
movl $0x40, %esi
movq %rax, %rcx
callq 0xc9d0
movq %r15, %rdi
callq 0xcbb0
leaq 0xc1de(%rip), %rsi      # 0x7690b
movq %r14, %rdi
callq 0x69863
leaq 0x90ca(%rip), %rsi      # 0x73806
leaq -0xf0(%rbp), %r13
movl $0x64, %ecx
movq %rax, %rdi
movq %r13, %rdx
callq 0x6ae99
cmpb $0x0, (%r13)
leaq 0x10d22(%rip), %rax     # 0x7b481
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 0xeee0(%rip), %rax      # 0x79667
movl %r12d, -0x2c(%rbp)
leaq 0xcf39(%rip), %r12      # 0x776cb
cmoveq %rax, %r12
leaq 0x28(%rbx), %rdx
cmoveq %rax, %r11
movl 0x284(%rbx), %eax
movq %rax, -0x38(%rbp)
subq $0x8, %rsp
leaq 0x10ca7(%rip), %rsi     # 0x7b45a
movq %r15, %rdi
movq %r13, %rcx
leaq -0x80(%rbp), %r8
xorl %eax, %eax
pushq -0x38(%rbp)
pushq 0x18(%rbx)
pushq %r11
pushq %r12
movl -0x2c(%rbp), %r12d
pushq %r10
callq 0xc260
addq $0x30, %rsp
leaq 0xc0fc(%rip), %rsi      # 0x768db
movq %r14, %rdi
movq %r15, %rdx
callq 0x6f68a
leaq 0xc0ff(%rip), %rsi      # 0x768f0
movq %r14, %rdi
movq %r15, %rdx
callq 0x6f68a
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 0x67f29
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 0x6a8ac
movq %rbx, %rdi
callq 0x6ee5f
jmp 0x6a8c6
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