// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: mbuf_insert
size_t mbuf_insert(struct mbuf *a, size_t off, const void *buf, size_t len) {
  char *p = NULL;

  assert(a != NULL);
  assert(a->len <= a->size);
  assert(off <= a->len);

  /* check overflow */
  if (~(size_t) 0 - (size_t) a->buf < len) return 0;

  if (a->len + len <= a->size) {
    memmove(a->buf + off + len, a->buf + off, a->len - off);
    if (buf != NULL) {
      memcpy(a->buf + off, buf, len);
    }
    a->len += len;
  } else {
    size_t new_size = (size_t)((a->len + len) * MBUF_SIZE_MULTIPLIER);
    if ((p = (char *) MBUF_REALLOC(a->buf, new_size)) != NULL) {
      a->buf = p;
      memmove(a->buf + off + len, a->buf + off, a->len - off);
      if (buf != NULL) memcpy(a->buf + off, buf, len);
      a->len += len;
      a->size = new_size;
    } else {
      len = 0;
    }
  }

  return len;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x8779
jmp 0x8798
leaq 0x16dc0(%rip), %rdi     # 0x1f540
leaq 0x16dc3(%rip), %rsi     # 0x1f54a
movl $0x568, %edx            # imm = 0x568
leaq 0x16dc2(%rip), %rcx     # 0x1f555
callq 0x3230
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
ja 0x87ac
jmp 0x87cb
leaq 0x16de2(%rip), %rdi     # 0x1f595
leaq 0x16d90(%rip), %rsi     # 0x1f54a
movl $0x569, %edx            # imm = 0x569
leaq 0x16d8f(%rip), %rcx     # 0x1f555
callq 0x3230
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
ja 0x87db
jmp 0x87fa
leaq 0x16dc5(%rip), %rdi     # 0x1f5a7
leaq 0x16d61(%rip), %rsi     # 0x1f54a
movl $0x56a, %edx            # imm = 0x56A
leaq 0x16d60(%rip), %rcx     # 0x1f555
callq 0x3230
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq $-0x1, %rax
subq %rcx, %rax
cmpq -0x28(%rbp), %rax
jae 0x881e
movq $0x0, -0x8(%rbp)
jmp 0x899e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
addq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
ja 0x8893
movq -0x10(%rbp), %rax
movq (%rax), %rdi
addq -0x18(%rbp), %rdi
addq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
addq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
subq -0x18(%rbp), %rdx
callq 0x3540
cmpq $0x0, -0x20(%rbp)
je 0x887e
movq -0x10(%rbp), %rax
movq (%rax), %rdi
addq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x33b0
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
jmp 0x8996
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
addq %rcx, %rax
movq %rax, %xmm0
movaps 0x16a92(%rip), %xmm1    # 0x1f340
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x16a96(%rip), %xmm1    # 0x1f350
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x16a2f(%rip), %xmm1    # 0x1f300
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x16a1c(%rip), %xmm1    # 0x1f308
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x34d0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x898c
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
addq -0x18(%rbp), %rdi
addq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
addq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
subq -0x18(%rbp), %rdx
callq 0x3540
cmpq $0x0, -0x20(%rbp)
je 0x896e
movq -0x10(%rbp), %rax
movq (%rax), %rdi
addq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x33b0
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x8994
movq $0x0, -0x28(%rbp)
jmp 0x8996
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)