// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_parse_chunk
static size_t mg_http_parse_chunk(char *buf, size_t len, char **chunk_data,
                                  size_t *chunk_len) {
  unsigned char *s = (unsigned char *) buf;
  size_t n = 0; /* scanned chunk length */
  size_t i = 0; /* index in s */

  /* Scan chunk length. That should be a hexadecimal number. */
  while (i < len && isxdigit(s[i])) {
    n *= 16;
    n += (s[i] >= '0' && s[i] <= '9') ? s[i] - '0' : tolower(s[i]) - 'a' + 10;
    i++;
  }

  /* Skip new line */
  if (i == 0 || i + 2 > len || s[i] != '\r' || s[i + 1] != '\n') {
    return 0;
  }
  i += 2;

  /* Record where the data is */
  *chunk_data = (char *) s + i;
  *chunk_len = n;

  /* Skip data */
  i += n;

  /* Skip new line */
  if (i == 0 || i + 2 > len || s[i] != '\r' || s[i + 1] != '\n') {
    return 0;
  }
  return i + 2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rcx
xorl %eax, %eax
cmpq -0x18(%rbp), %rcx
movb %al, -0x41(%rbp)
jae 0x19cd8
callq 0x36a0
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
setne %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x19ce1
jmp 0x19d5b
movq -0x38(%rbp), %rax
shlq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x30, %eax
jl 0x19d23
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x39, %eax
jg 0x19d23
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
subl $0x30, %eax
movl %eax, -0x48(%rbp)
jmp 0x19d3d
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %edi
callq 0x3410
subl $0x61, %eax
addl $0xa, %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
cltq
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x19ca0
cmpq $0x0, -0x40(%rbp)
je 0x19d93
movq -0x40(%rbp), %rax
addq $0x2, %rax
cmpq -0x18(%rbp), %rax
ja 0x19d93
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xd, %eax
jne 0x19d93
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl 0x1(%rax,%rcx), %eax
cmpl $0xa, %eax
je 0x19da0
movq $0x0, -0x8(%rbp)
jmp 0x19e20
movq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rcx
addq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x19e0a
movq -0x40(%rbp), %rax
addq $0x2, %rax
cmpq -0x18(%rbp), %rax
ja 0x19e0a
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xd, %eax
jne 0x19e0a
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl 0x1(%rax,%rcx), %eax
cmpl $0xa, %eax
je 0x19e14
movq $0x0, -0x8(%rbp)
jmp 0x19e20
movq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)