// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %rsi, 0x8(%rsp)
pushq $0x8
popq %r12
movq %rdi, %r15
movq %rdi, %r14
movzbl (%r14), %ebx
cmpl $0x3a, %ebx
je 0xfd0c
testl %ebx, %ebx
je 0xfd14
cmpl $0x2e, %ebx
je 0xfd21
callq 0x2250
movq (%rax), %rax
testb $0x10, 0x1(%rax,%rbx,2)
jne 0xfd0f
jmp 0xfd14
decl %r12d
incq %r14
jmp 0xfce9
movl $0x0, 0x14(%rsp)
movq %r15, %rbx
jmp 0xfd3d
cmpl $0x5, %r12d
movq %r15, %rbx
je 0xfd34
cmpl $0x2, %r12d
jne 0xfe66
decl %r12d
movb $0x1, %al
movl %eax, 0x14(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %rbx, 0x18(%rsp)
movzbl (%rbx), %ebx
movl %ebp, %r14d
cmpl $0x3a, %ebx
je 0xfd92
testl %ebx, %ebx
je 0xfe6a
callq 0x2250
movq (%rax), %rax
movzbl %bl, %ecx
movzwl (%rax,%rcx,2), %ecx
btl $0xc, %ecx
jae 0xfe6a
movsbl %bl, %eax
btl $0xb, %ecx
jb 0xfdb0
xorl %edx, %edx
btl $0x9, %ecx
setae %dl
shll $0x5, %edx
addl %edx, %eax
addl $-0x57, %eax
jmp 0xfdb3
cmpq $0x0, 0x8(%rsp)
je 0xfdc4
testb $0x1, %r13b
movq 0x18(%rsp), %rbx
jne 0xfdd0
shll $0x10, %r15d
movq 0x8(%rsp), %rax
jmp 0xfddb
addl $-0x30, %eax
movq 0x18(%rsp), %rbx
shll $0x4, %r15d
addl %eax, %r15d
jmp 0xfe5e
movq 0x8(%rsp), %r14
movq 0x18(%rsp), %rbx
jmp 0xfde2
incl %ebp
movq 0x8(%rsp), %rax
orl (%rax,%r14,4), %r15d
movl %r15d, (%rax,%r14,4)
movq %rax, %r14
incl %r13d
cmpl $0x6, %r13d
sete %al
andb 0x14(%rsp), %al
cmpb $0x1, %al
jne 0xfe1c
leaq 0x1(%rbx), %rdi
leaq 0x24(%rsp), %rsi
callq 0xe04a
testq %r14, %r14
je 0xfe0f
testl %eax, %eax
jne 0xfe95
pushq $0x6
popq %r13
testl %eax, %eax
je 0xfe22
jmp 0xfedd
cmpl $0x7, %r13d
ja 0xfe66
cmpb $0x3a, 0x1(%rbx)
jne 0xfe5b
cmpb $0x3a, 0x2(%rbx)
je 0xfe66
incq %rbx
subl $0x1, %r12d
jb 0xfe58
testb $0x1, %r13b
jne 0xfe4b
testq %r14, %r14
je 0xfe4d
movl %ebp, %eax
andl $0x0, (%r14,%rax,4)
jmp 0xfe4d
incl %ebp
incl %r13d
cmpl $0x8, %r13d
jne 0xfe31
jmp 0xfe66
xorl %r12d, %r12d
xorl %r15d, %r15d
incq %rbx
jmp 0xfd45
xorl %eax, %eax
jmp 0xfece
cmpq $0x0, 0x8(%rsp)
je 0xfec5
testb $0x1, %r13b
jne 0xfe87
shll $0x10, %r15d
movq 0x8(%rsp), %rax
movl %r15d, (%rax,%r14,4)
jmp 0xfe90
movq 0x8(%rsp), %rax
orl %r15d, (%rax,%r14,4)
movq %rax, %r14
jmp 0xfea6
movl 0x24(%rsp), %edi
callq 0x12ed7
movl %eax, 0xc(%r14)
pushq $0x7
popq %r13
xorl %ebx, %ebx
cmpq $0x4, %rbx
je 0xfec0
movl (%r14,%rbx,4), %edi
callq 0x12ed7
movl %eax, (%r14,%rbx,4)
incq %rbx
jmp 0xfea8
movb $0x0, 0x10(%r14)
xorl %eax, %eax
cmpl $0x7, %r13d
sete %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rax
jmp 0xfece