// File: /workspace/github_c_makefile_star2_O3/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 %rbx
testl %esi, %esi
je 0x183a
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r11d, %r11d
leal 0x3(%r11), %r9d
xorl %r10d, %r10d
xorl %r14d, %r14d
leal (%r11,%r14), %ebx
xorl %eax, %eax
cmpl %esi, %ebx
ja 0x18c4
shll $0x7, %r10d
movl %ebx, %ebx
movzbl (%rdi,%rbx), %ebp
movl %ebp, %ebx
andl $0x7f, %ebx
orl %ebx, %r10d
cmpl $0x3, %r14d
je 0x1748
incl %r14d
testb %bpl, %bpl
js 0x1714
addl %r14d, %r11d
movl %r11d, %r9d
movl %r10d, %r11d
shrl %r11d
addl $-0x3, %r11d
cmpl $0x1, %r11d
ja 0x17d6
testb $0x1, %bl
je 0x18c4
leal 0x3(%r9), %r11d
xorl %eax, %eax
xorl %ebx, %ebx
xorl %r14d, %r14d
leal (%r9,%r14), %ebp
cmpl %esi, %ebp
ja 0x18c4
movl %ebx, %r15d
shll $0x7, %r15d
movl %ebp, %ebx
movzbl (%rdi,%rbx), %ebp
movl %ebp, %ebx
andl $0x7f, %ebx
orl %r15d, %ebx
cmpl $0x3, %r14d
je 0x17a1
incl %r14d
testb %bpl, %bpl
js 0x176c
addl %r14d, %r9d
movl %r9d, %r11d
cmpl $0x2, %ebx
jne 0x18c4
leal 0x2(%r11), %r9d
cmpl %esi, %r9d
ja 0x18c4
movl %r11d, %eax
movzwl (%rdi,%rax), %eax
rolw $0x8, %ax
andl $-0x2, %r10d
cmpl $0x6, %r10d
movzwl %ax, %eax
cmovnel %eax, %r8d
cmovel %eax, %ecx
jmp 0x182c
testb $0x1, %bl
je 0x182c
leal 0x3(%r9), %r10d
xorl %eax, %eax
xorl %r11d, %r11d
xorl %ebx, %ebx
leal (%r9,%rbx), %ebp
cmpl %esi, %ebp
ja 0x18c4
movl %r11d, %r14d
shll $0x7, %r14d
movl %ebp, %r11d
movzbl (%rdi,%r11), %ebp
movl %ebp, %r11d
andl $0x7f, %r11d
orl %r14d, %r11d
cmpl $0x3, %ebx
je 0x181d
incl %ebx
testb %bpl, %bpl
js 0x17e6
addl %ebx, %r9d
movl %r9d, %r10d
addl %r11d, %r10d
movl %r10d, %r9d
cmpl %esi, %r10d
ja 0x18c4
movl %r9d, %r11d
cmpl %esi, %r9d
jne 0x170a
jmp 0x1889
xorl %r8d, %r8d
xorl %ecx, %ecx
jmp 0x1889
cmpl $0x28, %eax
ja 0x1865
movl %eax, %esi
addq 0x10(%rdx), %rsi
addl $0x8, %eax
movl %eax, (%rdx)
jmp 0x1871
cmpl $0x28, %eax
ja 0x1876
movl %eax, %esi
addq 0x10(%rdx), %rsi
addl $0x8, %eax
movl %eax, (%rdx)
jmp 0x1882
movq 0x8(%rdx), %rsi
leaq 0x8(%rsi), %rax
movq %rax, 0x8(%rdx)
movl %r8d, %eax
jmp 0x1884
movq 0x8(%rdx), %rsi
leaq 0x8(%rsi), %rax
movq %rax, 0x8(%rdx)
movl %ecx, %eax
movq (%rsi), %rsi
movl %eax, (%rsi)
movl (%rdx), %eax
cmpq $0x28, %rax
ja 0x189f
movq %rax, %rsi
addq 0x10(%rdx), %rsi
addl $0x8, %eax
movl %eax, (%rdx)
jmp 0x18ab
movq 0x8(%rdx), %rsi
leaq 0x8(%rsi), %rdi
movq %rdi, 0x8(%rdx)
movl (%rsi), %esi
cmpl $0x1, %esi
je 0x1853
cmpl $0x2, %esi
je 0x1841
testl %esi, %esi
jne 0x18c2
movl $0x1, %eax
jmp 0x18c4
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
popq %rbp
retq