// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/mongoose/mongoose.c
// Function: handle_put
static void handle_put(struct connection *conn, const char *path) {
  file_stat_t st;
  const char *range, *cl_hdr = mg_get_header(&conn->mg_conn, "Content-Length");
  int64_t r1, r2;
  int rc;

  conn->mg_conn.status_code = !stat(path, &st) ? 200 : 201;
  if ((rc = put_dir(path)) == 0) {
    mg_printf(&conn->mg_conn, "HTTP/1.1 %d OK\r\n\r\n",
              conn->mg_conn.status_code);
    close_local_endpoint(conn);
  } else if (rc == -1) {
    send_http_error(conn, 500, "put_dir: %s", strerror(errno));
  } else if (cl_hdr == NULL) {
    send_http_error(conn, 411, NULL);
  } else if ((conn->endpoint.fd =
              open(path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0644)) < 0) {
    send_http_error(conn, 500, "open(%s): %s", path, strerror(errno));
  } else {
    DBG(("PUT [%s] %lu", path, (unsigned long) conn->ns_conn->recv_iobuf.len));
    conn->endpoint_type = EP_PUT;
    ns_set_close_on_exec(conn->endpoint.fd);
    range = mg_get_header(&conn->mg_conn, "Content-Range");
    conn->cl = to64(cl_hdr);
    r1 = r2 = 0;
    if (range != NULL && parse_range_header(range, &r1, &r2) > 0) {
      conn->mg_conn.status_code = 206;
      lseek(conn->endpoint.fd, r1, SEEK_SET);
      conn->cl = r2 > r1 ? r2 - r1 + 1: conn->cl - r1;
    }
    mg_printf(&conn->mg_conn, "HTTP/1.1 %d OK\r\nContent-Length: 0\r\n\r\n",
              conn->mg_conn.status_code);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2138, %rsp           # imm = 0x2138
movq %rsi, %r15
movq %rdi, %rbx
addq $0x8, %rdi
leaq 0x4d2d(%rip), %rsi      # 0x74964
movq %rdi, -0x38(%rbp)
callq 0x67c6a
movq %rax, -0x40(%rbp)
leaq -0x160(%rbp), %rsi
movq %r15, %rdi
callq 0xcb70
cmpl $0x1, %eax
movl $0xc9, %eax
sbbl $0x0, %eax
movq %rbx, -0x30(%rbp)
movl %eax, 0x284(%rbx)
leaq 0x1(%r15), %rdi
leaq -0x2160(%rbp), %r13
leaq -0xd0(%rbp), %r12
movl $0x2f, %esi
callq 0xc5f0
testq %rax, %rax
je 0x6fd4e
movq %rax, %rbx
movq %rax, %r14
subq %r15, %r14
cmpq $0x1fff, %r14           # imm = 0x1FFF
jg 0x6fd17
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0xc0e0
movb $0x0, -0x2160(%rbp,%r14)
movq %r13, %rdi
movq %r12, %rsi
callq 0xcb70
testl %eax, %eax
je 0x6fcd6
movq %r13, %rdi
movl $0x1ed, %esi            # imm = 0x1ED
callq 0xc310
testl %eax, %eax
jne 0x6fd17
movq %rbx, %rdi
incq %rdi
cmpb $0x0, 0x1(%rbx)
jne 0x6fc7a
movq -0x30(%rbp), %rbx
movl 0x284(%rbx), %edx
leaq 0x9ad9(%rip), %rsi      # 0x797cc
movq -0x38(%rbp), %rdi
xorl %eax, %eax
callq 0x67a83
movq %rbx, %rdi
addq $0x2138, %rsp           # imm = 0x2138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x68a64
callq 0xcb20
movl (%rax), %edi
callq 0xc8c0
leaq 0x9ab5(%rip), %rdx      # 0x797df
movq -0x30(%rbp), %rdi
movl $0x1f4, %esi            # imm = 0x1F4
movq %rax, %rcx
xorl %eax, %eax
addq $0x2138, %rsp           # imm = 0x2138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6ae64
movq -0x40(%rbp), %r13
testq %r13, %r13
je 0x6fe49
movq %r15, %rdi
movl $0x242, %esi            # imm = 0x242
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0xcd20
movq -0x30(%rbp), %r12
movl %eax, 0x2b0(%r12)
testl %eax, %eax
js 0x6fe6c
movl $0x4, 0x2b8(%r12)
xorl %ebx, %ebx
movl %eax, %edi
movl $0x2, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0xc220
leaq 0x9a40(%rip), %rsi      # 0x797eb
movq -0x38(%rbp), %r15
movq %r15, %rdi
callq 0x67c6a
movq %rax, %r14
movq %r13, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0xc8b0
movq %rax, 0x2d8(%r12)
movq %rbx, -0xd0(%rbp)
movq %rbx, -0x2160(%rbp)
testq %r14, %r14
je 0x6feb8
leaq 0x963a(%rip), %rsi      # 0x79429
leaq -0x2160(%rbp), %rdx
leaq -0xd0(%rbp), %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0xc100
testl %eax, %eax
jle 0x6feb8
movl $0xce, 0x284(%r12)
movl 0x2b0(%r12), %edi
movq -0x2160(%rbp), %rsi
xorl %edx, %edx
callq 0xca40
movq -0xd0(%rbp), %rax
movq -0x2160(%rbp), %rcx
cmpq %rcx, %rax
jle 0x6fea5
incq %rax
jmp 0x6fead
movq -0x30(%rbp), %rdi
movl $0x19b, %esi            # imm = 0x19B
xorl %edx, %edx
xorl %eax, %eax
addq $0x2138, %rsp           # imm = 0x2138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6ae64
callq 0xcb20
movl (%rax), %edi
callq 0xc8c0
leaq 0x9439(%rip), %rdx      # 0x792b8
movq %r12, %rdi
movl $0x1f4, %esi            # imm = 0x1F4
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
addq $0x2138, %rsp           # imm = 0x2138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6ae64
movq 0x2d8(%r12), %rax
subq %rcx, %rax
movq %rax, 0x2d8(%r12)
movl 0x284(%r12), %edx
leaq 0x9932(%rip), %rsi      # 0x797f9
movq %r15, %rdi
xorl %eax, %eax
callq 0x67a83
addq $0x2138, %rsp           # imm = 0x2138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq