// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_sock_addr_to_str
int mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
                        int flags) {
  int is_v6;
  if (buf == NULL || len <= 0) return 0;
  memset(buf, 0, len);
#if MG_ENABLE_IPV6
  is_v6 = sa->sa.sa_family == AF_INET6;
#else
  is_v6 = 0;
#endif
  if (flags & MG_SOCK_STRINGIFY_IP) {
#if MG_ENABLE_IPV6
    const void *addr = NULL;
    char *start = buf;
    socklen_t capacity = len;
    if (!is_v6) {
      addr = &sa->sin.sin_addr;
    } else {
      addr = (void *) &sa->sin6.sin6_addr;
      if (flags & MG_SOCK_STRINGIFY_PORT) {
        *buf = '[';
        start++;
        capacity--;
      }
    }
    if (inet_ntop(sa->sa.sa_family, addr, start, capacity) == NULL) {
      goto cleanup;
    }
#elif defined(_WIN32) || MG_LWIP || (MG_NET_IF == MG_NET_IF_PIC32)
    /* Only Windoze Vista (and newer) have inet_ntop() */
    char *addr_str = inet_ntoa(sa->sin.sin_addr);
    if (addr_str != NULL) {
      strncpy(buf, inet_ntoa(sa->sin.sin_addr), len - 1);
    } else {
      goto cleanup;
    }
#else
    if (inet_ntop(AF_INET, (void *) &sa->sin.sin_addr, buf, len - 1) == NULL) {
      goto cleanup;
    }
#endif
  }
  if (flags & MG_SOCK_STRINGIFY_PORT) {
    int port = ntohs(sa->sin.sin_port);
    if (flags & MG_SOCK_STRINGIFY_IP) {
      int buf_len = strlen(buf);
      snprintf(buf + buf_len, len - (buf_len + 1), "%s:%d", (is_v6 ? "]" : ""),
               port);
    } else {
      snprintf(buf, len, "%d", port);
    }
  }

  return strlen(buf);

cleanup:
  *buf = '\0';
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xeee5
cmpq $0x0, -0x20(%rbp)
ja 0xeef1
movl $0x0, -0x4(%rbp)
jmp 0xeff5
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rdx
xorl %esi, %esi
callq 0x3260
movl $0x0, -0x28(%rbp)
movl -0x24(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xef3f
movq -0x10(%rbp), %rsi
addq $0x4, %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rax
subq $0x1, %rax
movl %eax, %ecx
movl $0x2, %edi
callq 0x3030
cmpq $0x0, %rax
jne 0xef3d
jmp 0xefe7
jmp 0xef3f
movl -0x24(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xefd9
movq -0x10(%rbp), %rax
movzwl 0x2(%rax), %edi
callq 0x34e0
movzwl %ax, %eax
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xefbe
movq -0x18(%rbp), %rdi
callq 0x3180
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x30(%rbp), %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
movl -0x30(%rbp), %eax
addl $0x1, %eax
cltq
subq %rax, %rsi
movl -0x28(%rbp), %edx
leaq 0x1180f(%rip), %rcx     # 0x207ab
leaq 0x10d60(%rip), %rax     # 0x1fd03
cmpl $0x0, %edx
cmovneq %rax, %rcx
movl -0x2c(%rbp), %r8d
leaq 0x11396(%rip), %rdx     # 0x2034b
movb $0x0, %al
callq 0x31f0
jmp 0xefd7
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x2c(%rbp), %ecx
leaq 0x113ab(%rip), %rdx     # 0x2037b
movb $0x0, %al
callq 0x31f0
jmp 0xefd9
movq -0x18(%rbp), %rdi
callq 0x3180
movl %eax, -0x4(%rbp)
jmp 0xeff5
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop