// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/lwip-2.1.2/src/core/ipv6/ip6_addr.c
// Function: ip6addr_ntoa_r
char *
ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen)
{
  u32_t current_block_index, current_block_value, next_block_value;
  s32_t i;
  u8_t zero_flag, empty_block_flag;

#if LWIP_IPV4
  if (ip6_addr_isipv4mappedipv6(addr)) {
    /* This is an IPv4 mapped address */
    ip4_addr_t addr4;
    char *ret;
#define IP4MAPPED_HEADER "::FFFF:"
    char *buf_ip4 = buf + sizeof(IP4MAPPED_HEADER) - 1;
    int buflen_ip4 = buflen - sizeof(IP4MAPPED_HEADER) + 1;
    if (buflen < (int)sizeof(IP4MAPPED_HEADER)) {
      return NULL;
    }
    memcpy(buf, IP4MAPPED_HEADER, sizeof(IP4MAPPED_HEADER));
    addr4.addr = addr->addr[3];
    ret = ip4addr_ntoa_r(&addr4, buf_ip4, buflen_ip4);
    if (ret != buf_ip4) {
      return NULL;
    }
    return buf;
  }
#endif /* LWIP_IPV4 */
  i = 0;
  empty_block_flag = 0; /* used to indicate a zero chain for "::' */

  for (current_block_index = 0; current_block_index < 8; current_block_index++) {
    /* get the current 16-bit block */
    current_block_value = lwip_htonl(addr->addr[current_block_index >> 1]);
    if ((current_block_index & 0x1) == 0) {
      current_block_value = current_block_value >> 16;
    }
    current_block_value &= 0xffff;

    /* Check for empty block. */
    if (current_block_value == 0) {
      if (current_block_index == 7 && empty_block_flag == 1) {
        /* special case, we must render a ':' for the last block. */
        buf[i++] = ':';
        if (i >= buflen) {
          return NULL;
        }
        break;
      }
      if (empty_block_flag == 0) {
        /* generate empty block "::", but only if more than one contiguous zero block,
         * according to current formatting suggestions RFC 5952. */
        next_block_value = lwip_htonl(addr->addr[(current_block_index + 1) >> 1]);
        if ((current_block_index & 0x1) == 0x01) {
            next_block_value = next_block_value >> 16;
        }
        next_block_value &= 0xffff;
        if (next_block_value == 0) {
          empty_block_flag = 1;
          buf[i++] = ':';
          if (i >= buflen) {
            return NULL;
          }
          continue; /* move on to next block. */
        }
      } else if (empty_block_flag == 1) {
        /* move on to next block. */
        continue;
      }
    } else if (empty_block_flag == 1) {
      /* Set this flag value so we don't produce multiple empty blocks. */
      empty_block_flag = 2;
    }

    if (current_block_index > 0) {
      buf[i++] = ':';
      if (i >= buflen) {
        return NULL;
      }
    }

    if ((current_block_value & 0xf000) == 0) {
      zero_flag = 1;
    } else {
      buf[i++] = lwip_xchar(((current_block_value & 0xf000) >> 12));
      zero_flag = 0;
      if (i >= buflen) {
        return NULL;
      }
    }

    if (((current_block_value & 0xf00) == 0) && (zero_flag)) {
      /* do nothing */
    } else {
      buf[i++] = lwip_xchar(((current_block_value & 0xf00) >> 8));
      zero_flag = 0;
      if (i >= buflen) {
        return NULL;
      }
    }

    if (((current_block_value & 0xf0) == 0) && (zero_flag)) {
      /* do nothing */
    }
    else {
      buf[i++] = lwip_xchar(((current_block_value & 0xf0) >> 4));
      zero_flag = 0;
      if (i >= buflen) {
        return NULL;
      }
    }

    buf[i++] = lwip_xchar((current_block_value & 0xf));
    if (i >= buflen) {
      return NULL;
    }
  }

  buf[i] = 0;

  return buf;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x1e175
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x1e175
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl $0xffff0000, %ecx       # imm = 0xFFFF0000
cmpq %rcx, %rax
jne 0x1e175
movq -0x18(%rbp), %rax
addq $0x8, %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
movslq -0x1c(%rbp), %rax
subq $0x8, %rax
addq $0x1, %rax
movl %eax, -0x4c(%rbp)
cmpl $0x8, -0x1c(%rbp)
jge 0x1e125
movq $0x0, -0x8(%rbp)
jmp 0x1e4dc
movq -0x18(%rbp), %rax
movq 0xb940(%rip), %rcx      # 0x29a70
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x48(%rbp), %rsi
movl -0x4c(%rbp), %edx
leaq -0x34(%rbp), %rdi
callq 0x1a670
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x1e168
movq $0x0, -0x8(%rbp)
jmp 0x1e4dc
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1e4dc
movl $0x0, -0x2c(%rbp)
movb $0x0, -0x2e(%rbp)
movl $0x0, -0x20(%rbp)
cmpl $0x8, -0x20(%rbp)
jae 0x1e4c8
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x251f0
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x1e1bb
movl -0x24(%rbp), %eax
shrl $0x10, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
andl $0xffff, %eax           # imm = 0xFFFF
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x1e29e
cmpl $0x7, -0x20(%rbp)
jne 0x1e20f
movzbl -0x2e(%rbp), %eax
cmpl $0x1, %eax
jne 0x1e20f
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movb $0x3a, (%rax,%rcx)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jl 0x1e20a
movq $0x0, -0x8(%rbp)
jmp 0x1e4dc
jmp 0x1e4c8
movzbl -0x2e(%rbp), %eax
cmpl $0x0, %eax
jne 0x1e28c
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x251f0
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
andl $0x1, %eax
cmpl $0x1, %eax
jne 0x1e245
movl -0x28(%rbp), %eax
shrl $0x10, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
andl $0xffff, %eax           # imm = 0xFFFF
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x1e28a
movb $0x1, -0x2e(%rbp)
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movb $0x3a, (%rax,%rcx)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jl 0x1e285
movq $0x0, -0x8(%rbp)
jmp 0x1e4dc
jmp 0x1e4ba
jmp 0x1e29c
movzbl -0x2e(%rbp), %eax
cmpl $0x1, %eax
jne 0x1e29a
jmp 0x1e4ba
jmp 0x1e29c
jmp 0x1e2ad
movzbl -0x2e(%rbp), %eax
cmpl $0x1, %eax
jne 0x1e2ab
movb $0x2, -0x2e(%rbp)
jmp 0x1e2ad
cmpl $0x0, -0x20(%rbp)
jbe 0x1e2e0
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movb $0x3a, (%rax,%rcx)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jl 0x1e2de
movq $0x0, -0x8(%rbp)
jmp 0x1e4dc
jmp 0x1e2e0
movl -0x24(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x0, %eax
jne 0x1e2f3
movb $0x1, -0x2d(%rbp)
jmp 0x1e35f
movl -0x24(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
shrl $0xc, %eax
cmpl $0xa, %eax
jae 0x1e316
movl -0x24(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
shrl $0xc, %eax
addl $0x30, %eax
movl %eax, -0x50(%rbp)
jmp 0x1e32a
movl -0x24(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
shrl $0xc, %eax
addl $0x41, %eax
subl $0xa, %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movb $0x0, -0x2d(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jl 0x1e35d
movq $0x0, -0x8(%rbp)
jmp 0x1e4dc
jmp 0x1e35f
movl -0x24(%rbp), %eax
andl $0xf00, %eax            # imm = 0xF00
cmpl $0x0, %eax
jne 0x1e377
movzbl -0x2d(%rbp), %eax
cmpl $0x0, %eax
je 0x1e377
jmp 0x1e3e3
movl -0x24(%rbp), %eax
andl $0xf00, %eax            # imm = 0xF00
shrl $0x8, %eax
cmpl $0xa, %eax
jae 0x1e39a
movl -0x24(%rbp), %eax
andl $0xf00, %eax            # imm = 0xF00
shrl $0x8, %eax
addl $0x30, %eax
movl %eax, -0x54(%rbp)
jmp 0x1e3ae
movl -0x24(%rbp), %eax
andl $0xf00, %eax            # imm = 0xF00
shrl $0x8, %eax
addl $0x41, %eax
subl $0xa, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movb $0x0, -0x2d(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jl 0x1e3e1
movq $0x0, -0x8(%rbp)
jmp 0x1e4dc
jmp 0x1e3e3
movl -0x24(%rbp), %eax
andl $0xf0, %eax
cmpl $0x0, %eax
jne 0x1e3fb
movzbl -0x2d(%rbp), %eax
cmpl $0x0, %eax
je 0x1e3fb
jmp 0x1e464
movl -0x24(%rbp), %eax
andl $0xf0, %eax
shrl $0x4, %eax
cmpl $0xa, %eax
jae 0x1e41e
movl -0x24(%rbp), %eax
andl $0xf0, %eax
shrl $0x4, %eax
addl $0x30, %eax
movl %eax, -0x58(%rbp)
jmp 0x1e432
movl -0x24(%rbp), %eax
andl $0xf0, %eax
shrl $0x4, %eax
addl $0x41, %eax
subl $0xa, %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movb $0x0, -0x2d(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jl 0x1e462
movq $0x0, -0x8(%rbp)
jmp 0x1e4dc
jmp 0x1e464
movl -0x24(%rbp), %eax
andl $0xf, %eax
cmpl $0xa, %eax
jae 0x1e47d
movl -0x24(%rbp), %eax
andl $0xf, %eax
addl $0x30, %eax
movl %eax, -0x5c(%rbp)
jmp 0x1e48c
movl -0x24(%rbp), %eax
andl $0xf, %eax
addl $0x41, %eax
subl $0xa, %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jl 0x1e4b8
movq $0x0, -0x8(%rbp)
jmp 0x1e4dc
jmp 0x1e4ba
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1e187
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)