// File: solaldunckel[P]webserv/srcs/Config/ServerConfig.cpp
// Function: ServerConfig::listen(__gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>&)
void ServerConfig::listen(std::vector<std::string>::iterator &it) {
  std::string str = *it;
  std::string ip = "0.0.0.0";
  uint32_t port = 8000;

  if (str.find(':') != std::string::npos) {
    ip = str.substr(0, str.find(':'));

    std::string port_str = str.substr(str.find(':') + 1);

    if (port_str.find_first_not_of("0123456789") != std::string::npos) {
      throw std::runtime_error("invalid port :" + port_str);
    }

    port = ft::stoi(port_str);
    if (port > 65535)
      throw std::runtime_error("duplicate value in 'listen'");
  }
  else if (str.find_first_not_of("0123456789") != std::string::npos) {
    ip = str;
  }
  else
    port = ft::stoi(str);

  Listen list(ip, port);

  if (std::find(listens_.begin(), listens_.end(), list) != listens_.end())
    throw std::runtime_error("duplicate value in 'listen'");
    // throw webserv_exception("duplicate listen " + ip + ":" + port);

  listens_.push_back(Listen(ip, port));

  if (*++it != ";")
    throw std::runtime_error("double value in 'listen'");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x10(%rbp), %rdi
callq 0x92b0
movq %rax, %rsi
leaq -0x30(%rbp), %rdi
callq 0x5200
leaq -0x51(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x5960
movq -0x188(%rbp), %rdx
leaq 0x2c30b(%rip), %rsi     # 0x4333c
leaq -0x50(%rbp), %rdi
callq 0x6be0
jmp 0x1703c
leaq -0x51(%rbp), %rdi
callq 0x55e0
movl $0x1f40, -0x68(%rbp)    # imm = 0x1F40
leaq -0x30(%rbp), %rdi
movl $0x3a, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x5730
cmpq $-0x1, %rax
je 0x172bc
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0x198(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
movl $0x3a, %esi
callq 0x5730
movq -0x1a0(%rbp), %rsi
movq -0x198(%rbp), %rdx
movq %rax, %rcx
leaq -0x88(%rbp), %rdi
callq 0x55a0
jmp 0x170a7
leaq -0x50(%rbp), %rdi
leaq -0x88(%rbp), %rsi
movq %rsi, -0x1b0(%rbp)
callq 0x56d0
movq -0x1b0(%rbp), %rdi
callq 0x5aa8
xorl %eax, %eax
movl %eax, %edx
leaq -0x30(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
movl $0x3a, %esi
callq 0x5730
movq -0x1a8(%rbp), %rsi
movq %rax, %rdx
incq %rdx
leaq -0xa8(%rbp), %rdi
movq $-0x1, %rcx
callq 0x55a0
jmp 0x17105
leaq -0xa8(%rbp), %rdi
leaq 0x2c0c8(%rip), %rsi     # 0x431db
xorl %eax, %eax
movl %eax, %edx
callq 0x52f0
cmpq $-0x1, %rax
je 0x17202
movb $0x1, -0xc9(%rbp)
movl $0x10, %edi
callq 0x5250
movq %rax, -0x1b8(%rbp)
leaq 0x2c2df(%rip), %rsi     # 0x43424
leaq -0xc8(%rbp), %rdi
leaq -0xa8(%rbp), %rdx
callq 0x6ad0
jmp 0x1715a
movq -0x1b8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x58c0
jmp 0x1716f
movq -0x1b8(%rbp), %rdi
movb $0x0, -0xc9(%rbp)
movq 0x44e6c(%rip), %rsi     # 0x5bff0
movq 0x44e0d(%rip), %rdx     # 0x5bf98
callq 0x5920
jmp 0x175e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x51(%rbp), %rdi
callq 0x55e0
jmp 0x175d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x175cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x171e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x5aa8
testb $0x1, -0xc9(%rbp)
jne 0x171f1
jmp 0x171fd
movq -0x1b8(%rbp), %rdi
callq 0x53b0
jmp 0x172ab
xorl %eax, %eax
movl %eax, %esi
leaq -0xa8(%rbp), %rdi
movl $0xa, %edx
callq 0x41890
movl %eax, -0x1bc(%rbp)
jmp 0x1721f
movl -0x1bc(%rbp), %eax
movl %eax, -0x68(%rbp)
cmpl $0xffff, -0x68(%rbp)    # imm = 0xFFFF
jbe 0x1729d
movl $0x10, %edi
callq 0x5250
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1c8(%rbp)
leaq 0x2c1e4(%rip), %rsi     # 0x43433
callq 0x51d0
jmp 0x17256
movq -0x1c8(%rbp), %rdi
movq 0x44d8c(%rip), %rsi     # 0x5bff0
movq 0x44d2d(%rip), %rdx     # 0x5bf98
callq 0x5920
jmp 0x175e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x172ab
movq -0x1c8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
callq 0x53b0
jmp 0x172ab
leaq -0xa8(%rbp), %rdi
callq 0x5aa8
jmp 0x1730c
leaq -0xa8(%rbp), %rdi
callq 0x5aa8
jmp 0x175cb
leaq -0x30(%rbp), %rdi
leaq 0x2bf14(%rip), %rsi     # 0x431db
xorl %eax, %eax
movl %eax, %edx
callq 0x52f0
cmpq $-0x1, %rax
je 0x172e7
leaq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x5050
jmp 0x172e5
jmp 0x1730a
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
movl $0xa, %edx
callq 0x41890
movl %eax, -0x1cc(%rbp)
jmp 0x17301
movl -0x1cc(%rbp), %eax
movl %eax, -0x68(%rbp)
jmp 0x1730c
leaq -0x118(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x5200
jmp 0x1731e
movl -0x68(%rbp), %edx
leaq -0xf8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x18cf0
jmp 0x17336
leaq -0x118(%rbp), %rdi
callq 0x5aa8
movq -0x190(%rbp), %rdi
addq $0x8, %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x136d0
movq -0x1e0(%rbp), %rdi
movq %rax, -0x128(%rbp)
callq 0x13740
movq %rax, -0x130(%rbp)
movq -0x128(%rbp), %rdi
movq -0x130(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
callq 0x18d20
movq %rax, -0x1d8(%rbp)
jmp 0x17396
movq -0x190(%rbp), %rdi
movq -0x1d8(%rbp), %rax
movq %rax, -0x120(%rbp)
addq $0x8, %rdi
callq 0x13740
movq %rax, -0x138(%rbp)
leaq -0x120(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x13700
testb $0x1, %al
jne 0x173d7
jmp 0x17466
movl $0x10, %edi
callq 0x5250
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1e8(%rbp)
leaq 0x2c03e(%rip), %rsi     # 0x43433
callq 0x51d0
jmp 0x173fc
movq -0x1e8(%rbp), %rdi
movq 0x44be6(%rip), %rsi     # 0x5bff0
movq 0x44b87(%rip), %rdx     # 0x5bf98
callq 0x5920
jmp 0x175e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x5aa8
jmp 0x175cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x175bf
movq -0x1e8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
callq 0x53b0
jmp 0x175bf
movq -0x190(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x1f0(%rbp)
leaq -0x180(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x5200
jmp 0x1748a
movl -0x68(%rbp), %edx
leaq -0x160(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x18cf0
jmp 0x174a2
movq -0x1f0(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x18d70
jmp 0x174b7
leaq -0x160(%rbp), %rdi
callq 0xcba0
leaq -0x180(%rbp), %rdi
callq 0x5aa8
movq -0x10(%rbp), %rdi
callq 0x92d0
movq %rax, %rdi
callq 0x92b0
movq %rax, %rdi
leaq 0x2c47d(%rip), %rsi     # 0x43967
callq 0x9360
movb %al, -0x1f1(%rbp)
jmp 0x174f7
movb -0x1f1(%rbp), %al
testb $0x1, %al
jne 0x17506
jmp 0x17598
movl $0x10, %edi
callq 0x5250
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x200(%rbp)
leaq 0x2bf2b(%rip), %rsi     # 0x4344f
callq 0x51d0
jmp 0x1752b
movq -0x200(%rbp), %rdi
movq 0x44ab7(%rip), %rsi     # 0x5bff0
movq 0x44a58(%rip), %rdx     # 0x5bf98
callq 0x5920
jmp 0x175e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x17570
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x160(%rbp), %rdi
callq 0xcba0
leaq -0x180(%rbp), %rdi
callq 0x5aa8
jmp 0x175bf
movq -0x200(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
callq 0x53b0
jmp 0x175bf
leaq -0xf8(%rbp), %rdi
callq 0xcba0
leaq -0x50(%rbp), %rdi
callq 0x5aa8
leaq -0x30(%rbp), %rdi
callq 0x5aa8
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
leaq -0xf8(%rbp), %rdi
callq 0xcba0
leaq -0x50(%rbp), %rdi
callq 0x5aa8
leaq -0x30(%rbp), %rdi
callq 0x5aa8
movq -0x60(%rbp), %rdi
callq 0x5950
nopw %cs:(%rax,%rax)