// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_handle_chunked
MG_INTERNAL size_t mg_handle_chunked(struct mg_connection *nc,
                                     struct http_message *hm, char *buf,
                                     size_t blen) {
  struct mg_http_proto_data *pd = mg_http_get_proto_data(nc);
  char *data;
  size_t i, n, data_len, body_len, zero_chunk_received = 0;
  /* Find out piece of received data that is not yet reassembled */
  body_len = (size_t) pd->chunk.body_len;
  assert(blen >= body_len);

  /* Traverse all fully buffered chunks */
  for (i = body_len;
       (n = mg_http_parse_chunk(buf + i, blen - i, &data, &data_len)) > 0;
       i += n) {
    /* Collapse chunk data to the rest of HTTP body */
    memmove(buf + body_len, data, data_len);
    body_len += data_len;
    hm->body.len = body_len;

    if (data_len == 0) {
      zero_chunk_received = 1;
      i += n;
      break;
    }
  }

  if (i > body_len) {
    /* Shift unparsed content to the parsed body */
    assert(i <= blen);
    memmove(buf + body_len, buf + i, blen - i);
    memset(buf + body_len + blen - i, 0, i - body_len);
    nc->recv_mbuf.len -= i - body_len;
    pd->chunk.body_len = body_len;

    /* Send MG_EV_HTTP_CHUNK event */
    nc->flags &= ~MG_F_DELETE_CHUNK;
    mg_call(nc, nc->handler, nc->user_data, MG_EV_HTTP_CHUNK, hm);

    /* Delete processed data if user set MG_F_DELETE_CHUNK flag */
    if (nc->flags & MG_F_DELETE_CHUNK) {
      memset(buf, 0, body_len);
      memmove(buf, buf + body_len, blen - i);
      nc->recv_mbuf.len -= body_len;
      hm->body.len = 0;
      pd->chunk.body_len = 0;
    }

    if (zero_chunk_received) {
      /* Total message size is len(body) + len(headers) */
      hm->message.len =
          (size_t) pd->chunk.body_len + blen - i + (hm->body.p - hm->message.p);
    }
  }

  return body_len;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x109b0
movq %rax, -0x28(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x50(%rbp), %rax
jb 0x115b5
jmp 0x115d4
leaq 0xeeba(%rip), %rdi      # 0x20476
leaq 0xdf87(%rip), %rsi      # 0x1f54a
movl $0x17d2, %edx           # imm = 0x17D2
leaq 0xeeb8(%rip), %rcx      # 0x20487
callq 0x3230
movq -0x50(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
addq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
subq -0x38(%rbp), %rsi
leaq -0x30(%rbp), %rdx
leaq -0x48(%rbp), %rcx
callq 0x19c70
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jbe 0x11660
movq -0x18(%rbp), %rdi
addq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x3540
movq -0x48(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
cmpq $0x0, -0x48(%rbp)
jne 0x1164d
movq $0x1, -0x58(%rbp)
movq -0x40(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x11660
jmp 0x1164f
movq -0x40(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x115dc
movq -0x38(%rbp), %rax
cmpq -0x50(%rbp), %rax
jbe 0x117de
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
ja 0x1167a
jmp 0x11699
leaq 0xee5e(%rip), %rdi      # 0x204df
leaq 0xdec2(%rip), %rsi      # 0x1f54a
movl $0x17e6, %edx           # imm = 0x17E6
leaq 0xedf3(%rip), %rcx      # 0x20487
callq 0x3230
movq -0x18(%rbp), %rdi
addq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
subq -0x38(%rbp), %rdx
callq 0x3540
movq -0x18(%rbp), %rdi
addq -0x50(%rbp), %rdi
addq -0x20(%rbp), %rdi
xorl %eax, %eax
subq -0x38(%rbp), %rax
addq %rax, %rdi
movq -0x38(%rbp), %rdx
subq -0x50(%rbp), %rdx
xorl %esi, %esi
callq 0x3260
movq -0x38(%rbp), %rdx
subq -0x50(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x48(%rax)
movq -0x50(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rcx
andq $-0x2001, %rcx          # imm = 0xDFFF
movq %rcx, 0xc8(%rax)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdx
movq -0x10(%rbp), %r8
movl $0x66, %ecx
callq 0xa8e0
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
andq $0x2000, %rax           # imm = 0x2000
cmpq $0x0, %rax
je 0x117a8
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rdx
xorl %esi, %esi
callq 0x3260
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq -0x50(%rbp), %rsi
movq -0x20(%rbp), %rdx
subq -0x38(%rbp), %rdx
callq 0x3540
movq -0x50(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x30(%rax)
cmpq $0x0, -0x58(%rbp)
je 0x117dc
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rcx
addq -0x20(%rbp), %rcx
subq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rdx
movq (%rdx), %rdx
subq %rdx, %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x117de
movq -0x50(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)