// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/mongoose/mongoose.c
// Function: send_http_error
static void send_http_error(struct connection *conn, int code,
                            const char *fmt, ...) {
  const char *message = status_code_to_str(code);
  const char *rewrites = conn->server->config_options[URL_REWRITES];
  char headers[200], body[200];
  struct vec a, b;
  va_list ap;
  int body_len, headers_len, match_code;

  conn->mg_conn.status_code = code;

  // Invoke error handler if it is set
  if (call_user(conn, MG_HTTP_ERROR) == MG_TRUE) {
    close_local_endpoint(conn);
    return;
  }

  // Handle error code rewrites
  while ((rewrites = next_option(rewrites, &a, &b)) != NULL) {
    if ((match_code = atoi(a.ptr)) > 0 && match_code == code) {
      struct mg_connection *c = &conn->mg_conn;
      c->status_code = 302;
      mg_printf(c, "HTTP/1.1 %d Moved\r\n"
                "Location: %.*s?code=%d&orig_uri=%s&query_string=%s\r\n\r\n",
                c->status_code, b.len, b.ptr, code, c->uri,
                c->query_string == NULL ? "" : c->query_string);
      close_local_endpoint(conn);
      return;
    }
  }

  body_len = mg_snprintf(body, sizeof(body), "%d %s\n", code, message);
  if (fmt != NULL) {
    va_start(ap, fmt);
    body_len += mg_vsnprintf(body + body_len, sizeof(body) - body_len, fmt, ap);
    va_end(ap);
  }
  if ((code >= 300 && code <= 399) || code == 204) {
    // 3xx errors do not have body
    body_len = 0;
  }
  headers_len = mg_snprintf(headers, sizeof(headers),
                            "HTTP/1.1 %d %s\r\nContent-Length: %d\r\n"
                            "Content-Type: text/plain\r\n\r\n",
                            code, message, body_len);
  ns_send(conn->ns_conn, headers, headers_len);
  ns_send(conn->ns_conn, body, body_len);
  close_local_endpoint(conn);  // This will write to the log file
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x320, %rsp            # imm = 0x320
testb %al, %al
je 0xb3df7
movaps %xmm0, -0x2a0(%rbp)
movaps %xmm1, -0x290(%rbp)
movaps %xmm2, -0x280(%rbp)
movaps %xmm3, -0x270(%rbp)
movaps %xmm4, -0x260(%rbp)
movaps %xmm5, -0x250(%rbp)
movaps %xmm6, -0x240(%rbp)
movaps %xmm7, -0x230(%rbp)
movq %r9, -0x2a8(%rbp)
movq %r8, -0x2b0(%rbp)
movq %rcx, -0x2b8(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl -0xc(%rbp), %edi
callq 0xb1660
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x2a8(%rax), %rax
movq 0xc8(%rax), %rax
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x284(%rax)
movq -0x8(%rbp), %rdi
movl $0x6d, %esi
callq 0xb7300
cmpl $0x1, %eax
jne 0xb3e67
movq -0x8(%rbp), %rdi
callq 0xb23e0
jmp 0xb40e2
jmp 0xb3e69
movq -0x28(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
leaq -0x1e0(%rbp), %rdx
callq 0xb5ad0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0xb3fba
movq -0x1d0(%rbp), %rdi
callq 0xd440
movl %eax, -0x20c(%rbp)
cmpl $0x0, %eax
jle 0xb3fb5
movl -0x20c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jne 0xb3fb5
movq -0x8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x218(%rbp)
movq -0x218(%rbp), %rax
movl $0x12e, 0x27c(%rax)     # imm = 0x12E
movq -0x218(%rbp), %rax
movq %rax, -0x300(%rbp)
movq -0x218(%rbp), %rax
movl 0x27c(%rax), %eax
movl %eax, -0x2f4(%rbp)
movq -0x1d8(%rbp), %rax
movq %rax, -0x2f0(%rbp)
movq -0x1e0(%rbp), %rax
movq %rax, -0x2e8(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x2dc(%rbp)
movq -0x218(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x2d8(%rbp)
movq -0x218(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0xb3f4e
leaq 0x11c06(%rip), %rax     # 0xc5b4b
movq %rax, -0x308(%rbp)
jmp 0xb3f60
movq -0x218(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x308(%rbp)
movq -0x2d8(%rbp), %r10
movl -0x2dc(%rbp), %r9d
movq -0x2e8(%rbp), %r8
movq -0x2f0(%rbp), %rcx
movl -0x2f4(%rbp), %edx
movq -0x300(%rbp), %rdi
movq -0x308(%rbp), %rax
leaq 0x13562(%rip), %rsi     # 0xc74f9
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0xb0cb0
movq -0x8(%rbp), %rdi
callq 0xb23e0
jmp 0xb40e2
jmp 0xb3e69
leaq -0x1c0(%rbp), %rdi
movl -0xc(%rbp), %ecx
movq -0x20(%rbp), %r8
movl $0xc8, %esi
leaq 0x1356f(%rip), %rdx     # 0xc7543
movb $0x0, %al
callq 0xb3c50
movl %eax, -0x204(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xb4052
leaq -0x200(%rbp), %rax
leaq -0x2d0(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x18, (%rax)
leaq -0x1c0(%rbp), %rdi
movslq -0x204(%rbp), %rax
addq %rax, %rdi
movslq -0x204(%rbp), %rax
movl $0xc8, %esi
subq %rax, %rsi
movq -0x18(%rbp), %rdx
leaq -0x200(%rbp), %rcx
callq 0xb7270
addl -0x204(%rbp), %eax
movl %eax, -0x204(%rbp)
leaq -0x200(%rbp), %rax
cmpl $0x12c, -0xc(%rbp)      # imm = 0x12C
jl 0xb4064
cmpl $0x18f, -0xc(%rbp)      # imm = 0x18F
jle 0xb406d
cmpl $0xcc, -0xc(%rbp)
jne 0xb4077
movl $0x0, -0x204(%rbp)
leaq -0xf0(%rbp), %rdi
movl -0xc(%rbp), %ecx
movq -0x20(%rbp), %r8
movl -0x204(%rbp), %r9d
movl $0xc8, %esi
leaq 0x134b2(%rip), %rdx     # 0xc754a
movb $0x0, %al
callq 0xb3c50
movl %eax, -0x208(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq -0xf0(%rbp), %rsi
movslq -0x208(%rbp), %rdx
callq 0xafce0
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq -0x1c0(%rbp), %rsi
movslq -0x204(%rbp), %rdx
callq 0xafce0
movq -0x8(%rbp), %rdi
callq 0xb23e0
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
nopl (%rax,%rax)