// File: /workspace/github_c_makefile_star2_O1/FH0[P]tun_direct/lwip-2.1.2/src/core/ipv6/ip6_addr.c
// Function: ip6addr_aton
int
ip6addr_aton(const char *cp, ip6_addr_t *addr)
{
  u32_t addr_index, zero_blocks, current_block_index, current_block_value;
  const char *s;
#if LWIP_IPV4
  int check_ipv4_mapped = 0;
#endif /* LWIP_IPV4 */

  /* Count the number of colons, to count the number of blocks in a "::" sequence
     zero_blocks may be 1 even if there are no :: sequences */
  zero_blocks = 8;
  for (s = cp; *s != 0; s++) {
    if (*s == ':') {
      zero_blocks--;
#if LWIP_IPV4
    } else if (*s == '.') {
      if ((zero_blocks == 5) ||(zero_blocks == 2)) {
        check_ipv4_mapped = 1;
        /* last block could be the start of an IPv4 address */
        zero_blocks--;
      } else {
        /* invalid format */
        return 0;
      }
      break;
#endif /* LWIP_IPV4 */
    } else if (!lwip_isxdigit(*s)) {
      break;
    }
  }

  /* parse each block */
  addr_index = 0;
  current_block_index = 0;
  current_block_value = 0;
  for (s = cp; *s != 0; s++) {
    if (*s == ':') {
      if (addr) {
        if (current_block_index & 0x1) {
          addr->addr[addr_index++] |= current_block_value;
        }
        else {
          addr->addr[addr_index] = current_block_value << 16;
        }
      }
      current_block_index++;
#if LWIP_IPV4
      if (check_ipv4_mapped) {
        if (current_block_index == 6) {
          ip4_addr_t ip4;
          int ret = ip4addr_aton(s + 1, &ip4);
          if (ret) {
            if (addr) {
              addr->addr[3] = lwip_htonl(ip4.addr);
              current_block_index++;
              goto fix_byte_order_and_return;
            }
            return 1;
          }
        }
      }
#endif /* LWIP_IPV4 */
      current_block_value = 0;
      if (current_block_index > 7) {
        /* address too long! */
        return 0;
      }
      if (s[1] == ':') {
        if (s[2] == ':') {
          /* invalid format: three successive colons */
          return 0;
        }
        s++;
        /* "::" found, set zeros */
        while (zero_blocks > 0) {
          zero_blocks--;
          if (current_block_index & 0x1) {
            addr_index++;
          } else {
            if (addr) {
              addr->addr[addr_index] = 0;
            }
          }
          current_block_index++;
          if (current_block_index > 7) {
            /* address too long! */
            return 0;
          }
        }
      }
    } else if (lwip_isxdigit(*s)) {
      /* add current digit */
      current_block_value = (current_block_value << 4) +
          (lwip_isdigit(*s) ? (u32_t)(*s - '0') :
          (u32_t)(10 + (lwip_islower(*s) ? *s - 'a' : *s - 'A')));
    } else {
      /* unexpected digit, space? CRLF? */
      break;
    }
  }

  if (addr) {
    if (current_block_index & 0x1) {
      addr->addr[addr_index++] |= current_block_value;
    }
    else {
      addr->addr[addr_index] = current_block_value << 16;
    }
#if LWIP_IPV4
fix_byte_order_and_return:
#endif
    /* convert to network byte order. */
    for (addr_index = 0; addr_index < 4; addr_index++) {
      addr->addr[addr_index] = lwip_htonl(addr->addr[addr_index]);
    }

    ip6_addr_clear_zone(addr);
  }

  if (current_block_index != 7) {
    return 0;
  }

  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, 0x8(%rsp)
movl $0x8, %ebp
movq %rdi, %rbx
movq %rdi, %r15
movzbl (%r15), %r14d
cmpl $0x3a, %r14d
je 0x107e9
testl %r14d, %r14d
je 0x107f0
cmpl $0x2e, %r14d
je 0x107fd
callq 0x2250
movq (%rax), %rax
testb $0x10, 0x1(%rax,%r14,2)
jne 0x107eb
jmp 0x107f0
decl %ebp
incq %r15
jmp 0x107c2
movl $0x0, 0x10(%rsp)
movq %rbx, %r14
jmp 0x10816
cmpl $0x5, %ebp
movq %rbx, %r14
je 0x1080e
cmpl $0x2, %ebp
jne 0x10956
decl %ebp
movb $0x1, %al
movl %eax, 0x10(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %r14, %rbx
movzbl (%r14), %r14d
cmpl $0x3a, %r14d
je 0x1086c
testl %r14d, %r14d
je 0x10967
callq 0x2250
movq (%rax), %rax
movzbl %r14b, %ecx
movzwl (%rax,%rcx,2), %ecx
btl $0xc, %ecx
jae 0x10967
movsbl %r14b, %eax
btl $0xb, %ecx
jb 0x1088b
xorl %edx, %edx
btl $0x9, %ecx
setae %dl
shll $0x5, %edx
addl %edx, %eax
addl $-0x57, %eax
jmp 0x1088e
cmpq $0x0, 0x8(%rsp)
je 0x1089d
movl %r15d, %eax
testb $0x1, %r12b
movq %rbx, %r14
jne 0x108a7
shll $0x10, %r13d
movq 0x8(%rsp), %rbx
jmp 0x108b3
addl $-0x30, %eax
movq %rbx, %r14
shll $0x4, %r13d
addl %eax, %r13d
jmp 0x1094e
movq %rbx, %r14
movq 0x8(%rsp), %rbx
jmp 0x108b7
incl %r15d
movq 0x8(%rsp), %rbx
orl (%rbx,%rax,4), %r13d
movl %r13d, (%rbx,%rax,4)
incl %r12d
cmpl $0x6, %r12d
sete %al
andb 0x10(%rsp), %al
cmpb $0x1, %al
jne 0x10908
leaq 0x1(%r14), %rdi
leaq 0x14(%rsp), %rsi
callq 0xe907
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
movl $0x6, %r12d
testq %rbx, %rbx
je 0x10904
testl %eax, %eax
je 0x10904
movl 0x14(%rsp), %edi
callq 0x13c57
movl %eax, 0xc(%rbx)
movl $0x8, %ecx
movl $0x7, %r12d
testl %ecx, %ecx
jne 0x10987
cmpl $0x7, %r12d
ja 0x10956
cmpb $0x3a, 0x1(%r14)
jne 0x1094b
cmpb $0x3a, 0x2(%r14)
je 0x10956
incq %r14
subl $0x1, %ebp
jb 0x10949
testb $0x1, %r12b
jne 0x1093b
testq %rbx, %rbx
je 0x1093e
movl %r15d, %eax
movl $0x0, (%rbx,%rax,4)
jmp 0x1093e
incl %r15d
incl %r12d
cmpl $0x8, %r12d
jne 0x1091f
jmp 0x10956
xorl %ebp, %ebp
xorl %r13d, %r13d
incq %r14
jmp 0x1081f
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0x8(%rsp)
je 0x109bc
testb $0x1, %r12b
jne 0x10993
shll $0x10, %r13d
movl %r15d, %eax
movq 0x8(%rsp), %rbx
movl %r13d, (%rbx,%rax,4)
jmp 0x1099f
movl $0x1, %eax
cmpl $0x8, %ecx
jne 0x10958
jmp 0x1099f
movl %r15d, %eax
movq 0x8(%rsp), %rbx
orl %r13d, (%rbx,%rax,4)
xorl %r14d, %r14d
movl (%rbx,%r14,4), %edi
callq 0x13c57
movl %eax, (%rbx,%r14,4)
incq %r14
cmpq $0x4, %r14
jne 0x109a2
movb $0x0, 0x10(%rbx)
xorl %eax, %eax
cmpl $0x7, %r12d
sete %al
jmp 0x10958