// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: parse_mqtt
MG_INTERNAL int parse_mqtt(struct mbuf *io, struct mg_mqtt_message *mm) {
  uint8_t header;
  size_t len = 0, len_len = 0;
  const char *p, *end;
  unsigned char lc = 0;
  int cmd;

  if (io->len < 2) return -1;
  header = io->buf[0];
  cmd = header >> 4;

  /* decode mqtt variable length */
  len = len_len = 0;
  p = io->buf + 1;
  while ((size_t)(p - io->buf) < io->len) {
    lc = *((const unsigned char *) p++);
    len += (lc & 0x7f) << 7 * len_len;
    len_len++;
    if (!(lc & 0x80)) break;
    if (len_len > 4) return -2;
  }

  end = p + len;
  if (lc & 0x80 || len > (io->len - (p - io->buf))) {
    return -1;
  }

  mm->cmd = cmd;
  mm->qos = MG_MQTT_GET_QOS(header);

  switch (cmd) {
    case MG_MQTT_CMD_CONNECT: {
      p = scanto(p, &mm->protocol_name);
      if (p > end - 4) return -2;
      mm->protocol_version = *(uint8_t *) p++;
      mm->connect_flags = *(uint8_t *) p++;
      mm->keep_alive_timer = getu16(p);
      p += 2;
      if (p >= end) return -2;
      p = scanto(p, &mm->client_id);
      if (p > end) return -2;
      if (mm->connect_flags & MG_MQTT_HAS_WILL) {
        if (p >= end) return -2;
        p = scanto(p, &mm->will_topic);
      }
      if (mm->connect_flags & MG_MQTT_HAS_WILL) {
        if (p >= end) return -2;
        p = scanto(p, &mm->will_message);
      }
      if (mm->connect_flags & MG_MQTT_HAS_USER_NAME) {
        if (p >= end) return -2;
        p = scanto(p, &mm->user_name);
      }
      if (mm->connect_flags & MG_MQTT_HAS_PASSWORD) {
        if (p >= end) return -2;
        p = scanto(p, &mm->password);
      }
      if (p != end) return -2;

      LOG(LL_DEBUG,
          ("%d %2x %d proto [%.*s] client_id [%.*s] will_topic [%.*s] "
           "will_msg [%.*s] user_name [%.*s] password [%.*s]",
           (int) len, (int) mm->connect_flags, (int) mm->keep_alive_timer,
           (int) mm->protocol_name.len, mm->protocol_name.p,
           (int) mm->client_id.len, mm->client_id.p, (int) mm->will_topic.len,
           mm->will_topic.p, (int) mm->will_message.len, mm->will_message.p,
           (int) mm->user_name.len, mm->user_name.p, (int) mm->password.len,
           mm->password.p));
      break;
    }
    case MG_MQTT_CMD_CONNACK:
      if (end - p < 2) return -2;
      mm->connack_ret_code = p[1];
      break;
    case MG_MQTT_CMD_PUBACK:
    case MG_MQTT_CMD_PUBREC:
    case MG_MQTT_CMD_PUBREL:
    case MG_MQTT_CMD_PUBCOMP:
    case MG_MQTT_CMD_SUBACK:
      mm->message_id = getu16(p);
      break;
    case MG_MQTT_CMD_PUBLISH: {
      p = scanto(p, &mm->topic);
      if (p > end) return -2;
      if (mm->qos > 0) {
        if (end - p < 2) return -2;
        mm->message_id = getu16(p);
        p += 2;
      }
      mm->payload.p = p;
      mm->payload.len = end - p;
      break;
    }
    case MG_MQTT_CMD_SUBSCRIBE:
      if (end - p < 2) return -2;
      mm->message_id = getu16(p);
      p += 2;
      /*
       * topic expressions are left in the payload and can be parsed with
       * `mg_mqtt_next_subscribe_topic`
       */
      mm->payload.p = p;
      mm->payload.len = end - p;
      break;
    default:
      /* Unhandled command */
      break;
  }

  mm->len = end - io->buf;
  return mm->len;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movb $0x0, -0x69(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x2, 0x8(%rax)
jae 0x1cd47
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x1d2a8
movq -0x38(%rbp), %rax
movq (%rax), %rax
movb (%rax), %al
movb %al, -0x41(%rbp)
movzbl -0x41(%rbp), %eax
sarl $0x4, %eax
movl %eax, -0x70(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
subq %rcx, %rax
movq -0x38(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x1cdf1
movq -0x60(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x60(%rbp)
movb (%rax), %al
movb %al, -0x69(%rbp)
movzbl -0x69(%rbp), %eax
andl $0x7f, %eax
imulq $0x7, -0x58(%rbp), %rcx
shll %cl, %eax
cltq
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movzbl -0x69(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x1cddc
jmp 0x1cdf1
cmpq $0x4, -0x58(%rbp)
jbe 0x1cdef
movl $0xfffffffe, -0x2c(%rbp) # imm = 0xFFFFFFFE
jmp 0x1d2a8
jmp 0x1cd7c
movq -0x60(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movzbl -0x69(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x1ce2d
movq -0x50(%rbp), %rax
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x60(%rbp), %rdx
movq -0x38(%rbp), %rsi
movq (%rsi), %rsi
subq %rsi, %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jbe 0x1ce39
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x1d2a8
movl -0x70(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, (%rax)
movzbl -0x41(%rbp), %ecx
andl $0x6, %ecx
shrl %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x70(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x78(%rbp)
subl $0x8, %eax
ja 0x1d285
movq -0x78(%rbp), %rax
leaq 0x2537(%rip), %rcx      # 0x1f3a8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x60(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x38, %rsi
callq 0x1d2c0
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
jbe 0x1ceac
movl $0xfffffffe, -0x2c(%rbp) # imm = 0xFFFFFFFE
jmp 0x1d2a8
movq -0x60(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x60(%rbp)
movb (%rax), %cl
movq -0x40(%rbp), %rax
movb %cl, 0x34(%rax)
movq -0x60(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x60(%rbp)
movb (%rax), %cl
movq -0x40(%rbp), %rax
movb %cl, 0x35(%rax)
movq -0x60(%rbp), %rdi
callq 0x1d310
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, 0x36(%rax)
movq -0x60(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
jb 0x1cf12
movl $0xfffffffe, -0x2c(%rbp) # imm = 0xFFFFFFFE
jmp 0x1d2a8
movq -0x60(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x48, %rsi
callq 0x1d2c0
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
jbe 0x1cf3d
movl $0xfffffffe, -0x2c(%rbp) # imm = 0xFFFFFFFE
jmp 0x1d2a8
movq -0x40(%rbp), %rax
movzbl 0x35(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1cf78
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
jb 0x1cf63
movl $0xfffffffe, -0x2c(%rbp) # imm = 0xFFFFFFFE
jmp 0x1d2a8
movq -0x60(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x58, %rsi
callq 0x1d2c0
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
movzbl 0x35(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1cfb3
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
jb 0x1cf9e
movl $0xfffffffe, -0x2c(%rbp) # imm = 0xFFFFFFFE
jmp 0x1d2a8
movq -0x60(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x68, %rsi
callq 0x1d2c0
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
movzbl 0x35(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x1cff0
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
jb 0x1cfdb
movl $0xfffffffe, -0x2c(%rbp) # imm = 0xFFFFFFFE
jmp 0x1d2a8
movq -0x60(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x78, %rsi
callq 0x1d2c0
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
movzbl 0x35(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x1d02e
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
jb 0x1d016
movl $0xfffffffe, -0x2c(%rbp) # imm = 0xFFFFFFFE
jmp 0x1d2a8
movq -0x60(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x88, %rsi
callq 0x1d2c0
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
je 0x1d044
movl $0xfffffffe, -0x2c(%rbp) # imm = 0xFFFFFFFE
jmp 0x1d2a8
jmp 0x1d046
movl $0x3, %edi
leaq 0x45be(%rip), %rsi      # 0x21610
leaq 0x24f1(%rip), %rdx      # 0x1f54a
callq 0x4650
cmpl $0x0, %eax
je 0x1d147
movq -0x50(%rbp), %rax
movl %eax, %esi
movq -0x40(%rbp), %rax
movzbl 0x35(%rax), %edx
movq -0x40(%rbp), %rax
movzwl 0x36(%rax), %ecx
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rax
movl %eax, %r8d
movq -0x40(%rbp), %rax
movq 0x38(%rax), %r9
movq -0x40(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x40(%rbp), %rdi
movq 0x48(%rdi), %rdi
movq %rdi, -0x88(%rbp)
movq -0x40(%rbp), %rdi
movq 0x60(%rdi), %rdi
movl %edi, %r13d
movq -0x40(%rbp), %rdi
movq 0x58(%rdi), %r12
movq -0x40(%rbp), %rdi
movq 0x70(%rdi), %rdi
movl %edi, %r15d
movq -0x40(%rbp), %rdi
movq 0x68(%rdi), %r14
movq -0x40(%rbp), %rdi
movq 0x80(%rdi), %rdi
movl %edi, %ebx
movq -0x40(%rbp), %rdi
movq 0x78(%rdi), %r11
movq -0x40(%rbp), %rdi
movq 0x90(%rdi), %rdi
movl %edi, %r10d
movq -0x40(%rbp), %rdi
movq 0x88(%rdi), %rdi
movq %rdi, -0x80(%rbp)
leaq 0x4515(%rip), %rdi      # 0x2161b
movl %eax, (%rsp)
movq -0x88(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x80(%rbp), %rax
movl %r13d, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movl %r15d, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movl %ebx, 0x30(%rsp)
movq %r11, 0x38(%rsp)
movl %r10d, 0x40(%rsp)
movq %rax, 0x48(%rsp)
movb $0x0, %al
callq 0x47a0
jmp 0x1d149
jmp 0x1d287
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
subq %rcx, %rax
cmpq $0x2, %rax
jge 0x1d16b
movl $0xfffffffe, -0x2c(%rbp) # imm = 0xFFFFFFFE
jmp 0x1d2a8
movq -0x60(%rbp), %rax
movb 0x1(%rax), %cl
movq -0x40(%rbp), %rax
movb %cl, 0x30(%rax)
jmp 0x1d287
movq -0x60(%rbp), %rdi
callq 0x1d310
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, 0x32(%rax)
jmp 0x1d287
movq -0x60(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x10, %rsi
callq 0x1d2c0
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
jbe 0x1d1c2
movl $0xfffffffe, -0x2c(%rbp) # imm = 0xFFFFFFFE
jmp 0x1d2a8
movq -0x40(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jle 0x1d209
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
subq %rcx, %rax
cmpq $0x2, %rax
jge 0x1d1e9
movl $0xfffffffe, -0x2c(%rbp) # imm = 0xFFFFFFFE
jmp 0x1d2a8
movq -0x60(%rbp), %rdi
callq 0x1d310
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, 0x32(%rax)
movq -0x60(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %rax
subq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x28(%rax)
jmp 0x1d287
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
subq %rcx, %rax
cmpq $0x2, %rax
jge 0x1d244
movl $0xfffffffe, -0x2c(%rbp) # imm = 0xFFFFFFFE
jmp 0x1d2a8
movq -0x60(%rbp), %rdi
callq 0x1d310
movw %ax, %cx
movq -0x40(%rbp), %rax
movw %cx, 0x32(%rax)
movq -0x60(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %rax
subq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x28(%rax)
jmp 0x1d287
jmp 0x1d287
movq -0x68(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)