// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
leaq 0x4(%rsp), %r15
andl $0x0, (%r15)
xorl %eax, %eax
movl $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
xorl %r13d, %r13d
cmpl %ebp, %eax
je 0x1852
leaq 0x14(%rsp), %rdi
movq %r14, %rsi
movl %ebp, %edx
movq %r15, %rcx
callq 0x32cb
testl %eax, %eax
je 0x18dc
movl 0x14(%rsp), %r12d
movl %r12d, %eax
shrl %eax
addl $-0x3, %eax
cmpl $0x1, %eax
jbe 0x17e1
testb $0x1, %r12b
jne 0x17b1
movl 0x4(%rsp), %eax
jmp 0x1771
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movl %ebp, %edx
movq %r15, %rcx
callq 0x32cb
testl %eax, %eax
je 0x18dc
movl 0x10(%rsp), %eax
addl 0x4(%rsp), %eax
cmpl %ebp, %eax
ja 0x18dc
movl %eax, 0x4(%rsp)
jmp 0x1771
testb $0x1, %r12b
je 0x18dc
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movl %ebp, %edx
movq %r15, %rcx
callq 0x32cb
testl %eax, %eax
je 0x18dc
cmpl $0x2, 0x10(%rsp)
jne 0x18dc
movl 0x4(%rsp), %ecx
leal 0x2(%rcx), %eax
cmpl %ebp, %eax
ja 0x18dc
movzwl (%r14,%rcx), %ecx
rolw $0x8, %cx
movl %eax, 0x4(%rsp)
andl $-0x2, %r12d
cmpl $0x6, %r12d
movzwl %cx, %ecx
movl 0xc(%rsp), %edx
cmovnel %ecx, %edx
movl %edx, 0xc(%rsp)
movl 0x8(%rsp), %edx
cmovel %ecx, %edx
movl %edx, 0x8(%rsp)
jmp 0x1771
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %edi
jmp 0x189f
cmpl $0x28, %eax
ja 0x187c
addq 0x10(%rbx), %rcx
addl $0x8, %eax
movl %eax, (%rbx)
jmp 0x1888
cmpl $0x28, %eax
ja 0x188c
addq 0x10(%rbx), %rcx
addl $0x8, %eax
movl %eax, (%rbx)
jmp 0x1898
movq 0x8(%rbx), %rcx
leaq 0x8(%rcx), %rax
movq %rax, 0x8(%rbx)
movl %esi, %eax
jmp 0x189a
movq 0x8(%rbx), %rcx
leaq 0x8(%rcx), %rax
movq %rax, 0x8(%rbx)
movl %edi, %eax
movq (%rcx), %rcx
movl %eax, (%rcx)
movl (%rbx), %eax
cmpq $0x28, %rax
ja 0x18b5
movq %rax, %rcx
addq 0x10(%rbx), %rcx
addl $0x8, %eax
movl %eax, (%rbx)
jmp 0x18c1
movq 0x8(%rbx), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rbx)
movl (%rcx), %edx
movl %eax, %ecx
cmpl $0x1, %edx
je 0x186c
cmpl $0x2, %edx
je 0x185c
testl %edx, %edx
jne 0x18d9
pushq $0x1
popq %r13
jmp 0x18dc
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq