// File: /workspace/github_c_makefile_star2_O3/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 0x10331
testl %r14d, %r14d
je 0x10338
cmpl $0x2e, %r14d
je 0x10345
callq 0x2250
movq (%rax), %rax
testb $0x10, 0x1(%rax,%r14,2)
jne 0x10333
jmp 0x10338
decl %ebp
incq %r15
jmp 0x1030a
movl $0x0, 0x10(%rsp)
movq %rbx, %r14
jmp 0x1035e
cmpl $0x5, %ebp
movq %rbx, %r14
je 0x10356
cmpl $0x2, %ebp
jne 0x10489
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 0x103b4
testl %r14d, %r14d
je 0x1048d
callq 0x2250
movq (%rax), %rax
movzbl %r14b, %ecx
movzwl (%rax,%rcx,2), %ecx
btl $0xc, %ecx
jae 0x1048d
movsbl %r14b, %eax
btl $0xb, %ecx
jb 0x103d3
xorl %edx, %edx
btl $0x9, %ecx
setae %dl
shll $0x5, %edx
addl %edx, %eax
addl $-0x57, %eax
jmp 0x103d6
cmpq $0x0, 0x8(%rsp)
je 0x103e5
movl %r15d, %eax
testb $0x1, %r12b
movq %rbx, %r14
jne 0x103ef
shll $0x10, %r13d
movq 0x8(%rsp), %rbx
jmp 0x103fb
addl $-0x30, %eax
movq %rbx, %r14
shll $0x4, %r13d
addl %eax, %r13d
jmp 0x10481
movq %rbx, %r14
movq 0x8(%rsp), %rbx
jmp 0x103ff
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 0x1043b
leaq 0x1(%r14), %rdi
leaq 0x14(%rsp), %rsi
callq 0xe673
testq %rbx, %rbx
je 0x1042c
testl %eax, %eax
jne 0x104bb
movl $0x6, %r12d
testl %eax, %eax
je 0x10441
jmp 0x10502
cmpl $0x7, %r12d
ja 0x10489
cmpb $0x3a, 0x1(%r14)
jne 0x1047e
cmpb $0x3a, 0x2(%r14)
je 0x10489
incq %r14
subl $0x1, %ebp
jb 0x1047c
testb $0x1, %r12b
jne 0x1046e
testq %rbx, %rbx
je 0x10471
movl %r15d, %eax
movl $0x0, (%rbx,%rax,4)
jmp 0x10471
incl %r15d
incl %r12d
cmpl $0x8, %r12d
jne 0x10452
jmp 0x10489
xorl %ebp, %ebp
xorl %r13d, %r13d
incq %r14
jmp 0x10367
xorl %eax, %eax
jmp 0x104f3
cmpq $0x0, 0x8(%rsp)
je 0x104ea
testb $0x1, %r12b
jne 0x104ad
shll $0x10, %r13d
movl %r15d, %eax
movq 0x8(%rsp), %rbx
movl %r13d, (%rbx,%rax,4)
jmp 0x104cd
movl %r15d, %eax
movq 0x8(%rsp), %rbx
orl %r13d, (%rbx,%rax,4)
jmp 0x104cd
movl 0x14(%rsp), %edi
callq 0x135bb
movl %eax, 0xc(%rbx)
movl $0x7, %r12d
xorl %r14d, %r14d
movl (%rbx,%r14,4), %edi
callq 0x135bb
movl %eax, (%rbx,%r14,4)
incq %r14
cmpq $0x4, %r14
jne 0x104d0
movb $0x0, 0x10(%rbx)
xorl %eax, %eax
cmpl $0x7, %r12d
sete %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %eax
jmp 0x104f3