// File: /workspace/github_c_makefile_star2_O1/agl[P]obstcp/libobstcp.c
// Function: advert_parse
static int
advert_parse(const uint8_t *advert, const unsigned length, va_list ap) {
  unsigned j = 0;
  int tlsport = 0, obsport = 0;
  uint16_t port;
  uint32_t v, type;

  for (;;) {
    if (j == length) break;
    if (!varint_get(&type, advert, length, &j)) return 0;
    switch (type >> 1) {
    case OBSTCP_KIND_OBSPORT:
    case OBSTCP_KIND_TLSPORT:
      if (!(type & 1)) return 0;
      if (!varint_get(&v, advert, length, &j)) return 0;
      if (v != 2) return 0;
      if (j + 2 > length) return 0;
      memcpy(&port, advert + j, 2);
      j += 2;
      port = ntohs(port);
      if (type >> 1 == OBSTCP_KIND_OBSPORT) {
        obsport = port;
      } else {
        tlsport = port;
      }
      break;
    default:
      if (type & 1) {
        if (!varint_get(&v, advert, length, &j)) return 0;
        if (j + v > length) return 0;
        j += v;
      }
    }
  }

  for (;;) {
    const int type = va_arg(ap, int);
    int *iptr;

    switch (type) {
    case OBSTCP_ADVERT_END:
      return 1;
    case OBSTCP_ADVERT_OBSPORT:
      iptr = va_arg(ap, int *);
      *iptr = obsport;
      break;
    case OBSTCP_ADVERT_TLSPORT:
      iptr = va_arg(ap, int *);
      *iptr = tlsport;
      break;
    default:
      return 0;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
testl %esi, %esi
je 0x190d
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %eax, %eax
leal 0x3(%rax), %r10d
xorl %ebp, %ebp
xorl %r14d, %r14d
leal (%rax,%r14), %ebx
cmpl %esi, %ebx
ja 0x17ec
movl %ebp, %r12d
shll $0x7, %r12d
movl %ebx, %r15d
movzbl (%rdi,%r15), %r15d
movl %r15d, %ebp
andl $0x7f, %ebp
orl %r12d, %ebp
cmpl $0x3, %r14d
je 0x17e7
incl %r14d
testb %r15b, %r15b
js 0x17b3
addl %r14d, %eax
movl %eax, %r10d
movl %ebp, %r9d
jmp 0x17ef
movl %ebx, %r10d
xorl %eax, %eax
cmpl %esi, %ebx
ja 0x19b0
movl %r9d, %ebx
shrl %ebx
addl $-0x3, %ebx
cmpl $0x1, %ebx
ja 0x184b
testb $0x1, %r9b
je 0x19b0
leal 0x3(%r10), %r14d
xorl %ebx, %ebx
xorl %eax, %eax
leal (%r10,%rax), %ebp
cmpl %esi, %ebp
ja 0x1896
movl %ebx, %r12d
shll $0x7, %r12d
movl %ebp, %ebx
movzbl (%rdi,%rbx), %r15d
movl %r15d, %ebx
andl $0x7f, %ebx
orl %r12d, %ebx
cmpl $0x3, %eax
je 0x189c
incl %eax
testb %r15b, %r15b
js 0x1818
addl %eax, %r10d
movl %r10d, %r14d
jmp 0x189c
testb $0x1, %r9b
jne 0x1859
movl %r11d, %ebx
jmp 0x18fc
leal 0x3(%r10), %ebp
xorl %ebx, %ebx
xorl %eax, %eax
leal (%r10,%rax), %r14d
cmpl %esi, %r14d
ja 0x18de
movl %ebx, %r12d
shll $0x7, %r12d
movl %r14d, %ebx
movzbl (%rdi,%rbx), %r15d
movl %r15d, %ebx
andl $0x7f, %ebx
orl %r12d, %ebx
cmpl $0x3, %eax
je 0x18e4
incl %eax
testb %r15b, %r15b
js 0x1861
addl %eax, %r10d
movl %r10d, %ebp
jmp 0x18e4
movl %ebp, %r14d
movl %r11d, %ebx
xorl %eax, %eax
cmpl %esi, %ebp
ja 0x19b0
cmpl $0x2, %ebx
jne 0x19b0
leal 0x2(%r14), %r10d
cmpl %esi, %r10d
ja 0x19b0
movl %r14d, %eax
movzwl (%rdi,%rax), %eax
rolw $0x8, %ax
movl %r9d, %r11d
andl $-0x2, %r11d
cmpl $0x6, %r11d
movzwl %ax, %eax
cmovnel %eax, %r8d
cmovel %eax, %ecx
jmp 0x18fc
movl %r14d, %ebp
movl %r11d, %ebx
xorl %eax, %eax
cmpl %esi, %r14d
ja 0x19b0
addl %ebx, %ebp
movl %ebp, %r10d
cmpl %esi, %ebp
ja 0x19b0
movl %ebx, %r11d
movl %r10d, %eax
cmpl %esi, %r10d
jne 0x17aa
jmp 0x1912
xorl %r8d, %r8d
xorl %ecx, %ecx
movl (%rdx), %edi
cmpq $0x28, %rdi
ja 0x1928
movq %rdi, %rsi
addq 0x10(%rdx), %rsi
addl $0x8, %edi
movl %edi, (%rdx)
jmp 0x1934
movq 0x8(%rdx), %rsi
leaq 0x8(%rsi), %rdi
movq %rdi, 0x8(%rdx)
movl (%rsi), %esi
testl %esi, %esi
je 0x1970
cmpl $0x2, %esi
je 0x195a
cmpl $0x1, %esi
jne 0x1979
movl (%rdx), %edi
cmpq $0x28, %rdi
ja 0x1993
movq %rdi, %rsi
addq 0x10(%rdx), %rsi
addl $0x8, %edi
movl %edi, (%rdx)
jmp 0x199f
movl (%rdx), %edi
cmpq $0x28, %rdi
ja 0x197f
movq %rdi, %rsi
addq 0x10(%rdx), %rsi
addl $0x8, %edi
movl %edi, (%rdx)
jmp 0x198b
movl $0x1, %eax
xorl %esi, %esi
jmp 0x19a7
xorl %esi, %esi
xorl %eax, %eax
jmp 0x19a7
movq 0x8(%rdx), %rsi
leaq 0x8(%rsi), %rdi
movq %rdi, 0x8(%rdx)
movq (%rsi), %rsi
movl %r8d, (%rsi)
jmp 0x19a4
movq 0x8(%rdx), %rsi
leaq 0x8(%rsi), %rdi
movq %rdi, 0x8(%rdx)
movq (%rsi), %rsi
movl %ecx, (%rsi)
movb $0x1, %sil
testb %sil, %sil
jne 0x1912
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq