// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq (%rsi), %rsi
leaq 0x30(%rsp), %rdi
callq 0x45e0
leaq 0x12085(%rip), %rsi     # 0x1c32a
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x5328
leaq 0x30(%rsp), %rdi
pushq $0x3a
popq %rsi
xorl %edx, %edx
callq 0x45a0
cmpq $-0x1, %rax
je 0xa376
leaq 0x30(%rsp), %r15
pushq $0x3a
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x45a0
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x44a0
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0x4560
movq %r15, %rdi
callq 0x4898
leaq 0x30(%rsp), %r15
pushq $0x3a
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x45a0
leaq 0x1(%rax), %rdx
leaq 0x8(%rsp), %rdi
pushq $-0x1
popq %rcx
movq %r15, %rsi
callq 0x44a0
leaq 0x11ea3(%rip), %rsi     # 0x1c1db
leaq 0x8(%rsp), %rdi
xorl %edx, %edx
callq 0x4270
cmpq $-0x1, %rax
jne 0xa4eb
leaq 0x8(%rsp), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x1b536
movl %eax, %ebp
cmpl $0x10000, %eax          # imm = 0x10000
jae 0xa536
leaq 0x8(%rsp), %rdi
callq 0x4898
jmp 0xa3b6
leaq 0x11e5e(%rip), %rsi     # 0x1c1db
leaq 0x30(%rsp), %rdi
xorl %edx, %edx
callq 0x4270
cmpq $-0x1, %rax
je 0xa3a5
movl $0x1f40, %ebp           # imm = 0x1F40
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4240
jmp 0xa3b6
leaq 0x30(%rsp), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x1b536
movl %eax, %ebp
leaq 0xb8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x45e0
leaq 0x8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x45e0
leaq 0x8(%rsp), %r15
movl %ebp, 0x20(%r15)
leaq 0xb8(%rsp), %rdi
callq 0x4898
movq 0x8(%r14), %rdi
movq 0x10(%r14), %rsi
movq %r15, %rdx
callq 0xbe4f
cmpq 0x10(%r14), %rax
jne 0xa49f
leaq 0x98(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x45e0
leaq 0x70(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x45e0
addq $0x8, %r14
leaq 0x70(%rsp), %rsi
movl %ebp, 0x20(%rsi)
movq %r14, %rdi
callq 0xbf78
leaq 0x70(%rsp), %rdi
callq 0x4898
leaq 0x98(%rsp), %rdi
callq 0x4898
movq (%rbx), %rdi
addq $0x20, %rdi
movq %rdi, (%rbx)
leaq 0x124c0(%rip), %rsi     # 0x1c92a
callq 0x61cb
testb %al, %al
jne 0xa4bb
leaq 0x8(%rsp), %rdi
callq 0x4898
leaq 0x50(%rsp), %rdi
callq 0x4898
leaq 0x30(%rsp), %rdi
callq 0x4898
addq $0xd8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x41e0
movq %rax, %r14
leaq 0x11f5d(%rip), %rsi     # 0x1c40e
movq %rax, %rdi
callq 0x4170
jmp 0xa4d5
pushq $0x10
popq %rdi
callq 0x41e0
movq %rax, %r14
leaq 0x11f5d(%rip), %rsi     # 0x1c42a
movq %rax, %rdi
callq 0x4170
movq 0x20b14(%rip), %rsi     # 0x2aff0
movq 0x20acd(%rip), %rdx     # 0x2afb0
movq %r14, %rdi
callq 0x4730
pushq $0x10
popq %rdi
callq 0x41e0
movq %rax, %r14
leaq 0x11f02(%rip), %rsi     # 0x1c3ff
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x52b1
movb $0x1, %bpl
leaq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x46e0
xorl %ebp, %ebp
movq 0x20acb(%rip), %rsi     # 0x2aff0
movq 0x20a84(%rip), %rdx     # 0x2afb0
movq %r14, %rdi
callq 0x4730
jmp 0xa566
pushq $0x10
popq %rdi
callq 0x41e0
movq %rax, %r14
leaq 0x11ec6(%rip), %rsi     # 0x1c40e
movq %rax, %rdi
callq 0x4170
movq 0x20a99(%rip), %rsi     # 0x2aff0
movq 0x20a52(%rip), %rdx     # 0x2afb0
movq %r14, %rdi
callq 0x4730
jmp 0xa582
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x4898
testb %bpl, %bpl
jne 0xa585
jmp 0xa5d4
jmp 0xa582
jmp 0xa5c7
jmp 0xa582
movq %rax, %rbx
movq %r14, %rdi
callq 0x4310
jmp 0xa5d4
jmp 0xa5c7
jmp 0xa5c7
jmp 0xa5d1
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x4898
jmp 0xa5a7
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x4898
jmp 0xa5d4
jmp 0xa5d1
jmp 0xa5d1
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
jmp 0xa5d9
movq %rax, %rbx
jmp 0xa5de
movq %rax, %rbx
jmp 0xa5e8
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x4898
leaq 0x50(%rsp), %rdi
callq 0x4898
leaq 0x30(%rsp), %rdi
callq 0x4898
movq %rbx, %rdi
callq 0x4750