// File: cybozu[P]yrmcds/cybozu/ip_address.cpp
// Function: cybozu::ip_address::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void ip_address::parse(const std::string& s) {
    struct addrinfo hints;
    struct addrinfo* res = nullptr;
    std::memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_INET;
    hints.ai_flags = AI_NUMERICHOST;
    int e = getaddrinfo(s.c_str(), nullptr, &hints, &res);
    if( e == 0 ) {
        af = addr_family::ipv4;
        std::memcpy(&addr, res->ai_addr, res->ai_addrlen);
        freeaddrinfo(res);
        return;
    }
    if( e != EAI_ADDRFAMILY && e != EAI_NONAME )
        throw std::runtime_error(gai_strerror(e));

    hints.ai_family = AF_INET6;
    e = getaddrinfo(s.c_str(), nullptr, &hints, &res);
    if( e == 0 ) {
        af = addr_family::ipv6;
        std::memcpy(&addr, res->ai_addr, res->ai_addrlen);
        freeaddrinfo(res);
        return;
    }
    if( e != EAI_ADDRFAMILY && e != EAI_NONAME )
        throw std::runtime_error(gai_strerror(e));
    throw bad_address("Invalid address: " + s);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq $0x0, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x8340
movl $0x2, -0x3c(%rbp)
movl $0x4, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8240
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x40(%rbp), %rdx
leaq -0x48(%rbp), %rcx
callq 0x8800
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jne 0x29ddf
movq -0x90(%rbp), %rdi
movl $0x1, (%rdi)
addq $0x4, %rdi
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x48(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
callq 0x8540
movq -0x48(%rbp), %rdi
callq 0x8850
jmp 0x29fc8
cmpl $-0x9, -0x4c(%rbp)
je 0x29e53
cmpl $-0x2, -0x4c(%rbp)
je 0x29e53
movl $0x10, %edi
callq 0x82f0
movq %rax, -0x98(%rbp)
movq %rax, -0xa0(%rbp)
movl -0x4c(%rbp), %edi
callq 0x8940
movq -0x98(%rbp), %rdi
movq %rax, %rsi
callq 0x8220
jmp 0x29e1c
movq -0xa0(%rbp), %rdi
movq 0x851c6(%rip), %rsi     # 0xaeff0
movq 0x8513f(%rip), %rdx     # 0xaef70
callq 0x8b70
movq -0xa0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x8490
jmp 0x29fd1
movl $0xa, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8240
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x40(%rbp), %rdx
leaq -0x48(%rbp), %rcx
callq 0x8800
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jne 0x29eb5
movq -0x90(%rbp), %rdi
movl $0x2, (%rdi)
addq $0x4, %rdi
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x48(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
callq 0x8540
movq -0x48(%rbp), %rdi
callq 0x8850
jmp 0x29fc8
cmpl $-0x9, -0x4c(%rbp)
je 0x29f29
cmpl $-0x2, -0x4c(%rbp)
je 0x29f29
movl $0x10, %edi
callq 0x82f0
movq %rax, -0xa8(%rbp)
movq %rax, -0xb0(%rbp)
movl -0x4c(%rbp), %edi
callq 0x8940
movq -0xa8(%rbp), %rdi
movq %rax, %rsi
callq 0x8220
jmp 0x29ef2
movq -0xb0(%rbp), %rdi
movq 0x850f0(%rip), %rsi     # 0xaeff0
movq 0x85069(%rip), %rdx     # 0xaef70
callq 0x8b70
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x8490
jmp 0x29fd1
movb $0x1, -0x81(%rbp)
movl $0x10, %edi
callq 0x82f0
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rdx
leaq 0x50dc4(%rip), %rsi     # 0x7ad10
leaq -0x80(%rbp), %rdi
callq 0xe550
jmp 0x29f57
movq -0xb8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x2a640
jmp 0x29f69
movq -0xb8(%rbp), %rdi
movb $0x0, -0x81(%rbp)
leaq 0x844da(%rip), %rsi     # 0xae458
leaq 0x6fb(%rip), %rdx       # 0x2a680
callq 0x8b70
jmp 0x29fda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x29faf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x83f0
testb $0x1, -0x81(%rbp)
jne 0x29fba
jmp 0x29fc6
movq -0xb8(%rbp), %rdi
callq 0x8490
jmp 0x29fd1
addq $0xc0, %rsp
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x8bc0
nopw (%rax,%rax)