// File: /workspace/github_c_makefile_star2_O1/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 0x5086(%rip), %rsi      # 0x7695c
movq %rdi, -0x38(%rbp)
callq 0x69863
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
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl $0x2f, %esi
callq 0xc5f0
testq %rax, %rax
je 0x71985
movq %rax, %rbx
movq %rax, %r14
subq %r15, %r14
cmpq $0x1fff, %r14           # imm = 0x1FFF
jg 0x7198b
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0xc0e0
movb $0x0, -0x2160(%rbp,%r14)
movq %r13, %rdi
leaq -0xd0(%rbp), %rsi
callq 0xcb70
testl %eax, %eax
je 0x71974
movq %r13, %rdi
movl $0x1ed, %esi            # imm = 0x1ED
callq 0xc310
testl %eax, %eax
jne 0x7198b
movq %rbx, %rdi
incq %rdi
cmpb $0x0, 0x1(%rbx)
jne 0x71918
xorl %r12d, %r12d
jmp 0x7198b
movl $0x1, %r12d
cmpl $-0x1, %r12d
je 0x719cb
testl %r12d, %r12d
jne 0x71a02
movq -0x30(%rbp), %rbx
movl 0x284(%rbx), %edx
leaq 0x9e25(%rip), %rsi      # 0x7b7cc
movq -0x38(%rbp), %rdi
xorl %eax, %eax
callq 0x69675
movq %rbx, %rdi
addq $0x2138, %rsp           # imm = 0x2138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6a615
callq 0xcb20
movl (%rax), %edi
callq 0xc8c0
leaq 0x9e01(%rip), %rdx      # 0x7b7df
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 0x6c73d
movq -0x40(%rbp), %r13
testq %r13, %r13
movq -0x30(%rbp), %r12
je 0x71afd
movq %r15, %rdi
movl $0x242, %esi            # imm = 0x242
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0xcd20
movl %eax, 0x2b0(%r12)
testl %eax, %eax
js 0x71b1f
movl $0x4, 0x2b8(%r12)
xorl %ebx, %ebx
movl %eax, %edi
movl $0x2, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0xc220
leaq 0x9d8c(%rip), %rsi      # 0x7b7eb
movq -0x38(%rbp), %r15
movq %r15, %rdi
callq 0x69863
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 0x71b6b
leaq 0x9986(%rip), %rsi      # 0x7b429
leaq -0x2160(%rbp), %rdx
leaq -0xd0(%rbp), %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0xc100
testl %eax, %eax
jle 0x71b6b
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 0x71b58
incq %rax
jmp 0x71b60
movq %r12, %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 0x6c73d
callq 0xcb20
movl (%rax), %edi
callq 0xc8c0
leaq 0x9786(%rip), %rdx      # 0x7b2b8
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 0x6c73d
movq 0x2d8(%r12), %rax
subq %rcx, %rax
movq %rax, 0x2d8(%r12)
movl 0x284(%r12), %edx
leaq 0x9c7f(%rip), %rsi      # 0x7b7f9
movq %r15, %rdi
xorl %eax, %eax
callq 0x69675
addq $0x2138, %rsp           # imm = 0x2138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq