// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq (%rsi), %rax
leaq 0x60(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x50(%rsp), %rdi
callq 0x6bac
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x19861(%rip), %rsi     # 0x25340
leaq 0x19861(%rip), %rdx     # 0x25347
leaq 0x30(%rsp), %rdi
callq 0x578e
leaq 0x50(%rsp), %rdi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x4580
cmpq $-0x1, %rax
je 0xbbe2
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x4580
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x4480
leaq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0x4560
movq (%r15), %rdi
leaq 0x18(%rsp), %r12
cmpq %r12, %rdi
je 0xbb5d
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x4580
leaq 0x1(%rax), %rdx
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x4480
leaq 0x19661(%rip), %rsi     # 0x251f1
leaq 0x8(%rsp), %rdi
movl $0xa, %ecx
xorl %edx, %edx
callq 0x4720
cmpq $-0x1, %rax
jne 0xbe19
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x244f4
movl %eax, %ebp
cmpl $0x10000, %eax          # imm = 0x10000
jae 0xbe66
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0xbc29
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0xbc29
leaq 0x19608(%rip), %rsi     # 0x251f1
leaq 0x50(%rsp), %rdi
movl $0xa, %ecx
xorl %edx, %edx
callq 0x4720
cmpq $-0x1, %rax
je 0xbc16
movl $0x1f40, %ebp           # imm = 0x1F40
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x4230
jmp 0xbc29
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x244f4
movl %eax, %ebp
leaq 0xc8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rdi
callq 0x6bac
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0xb8(%rsp), %rsi
movq 0xc0(%rsp), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x6bac
movl %ebp, 0x28(%rsp)
movq 0xb8(%rsp), %rdi
cmpq %r12, %rdi
je 0xbc97
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x8(%r14), %rdi
movq 0x10(%r14), %rsi
leaq 0x8(%rsp), %rdx
callq 0xda4b
cmpq 0x10(%r14), %rax
jne 0xbdc9
leaq 0xa8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %rdi
callq 0x6bac
leaq 0x80(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x98(%rsp), %rsi
movq 0xa0(%rsp), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0x6bac
addq $0x8, %r14
leaq 0x70(%rsp), %rsi
movl %ebp, 0x20(%rsi)
movq %r14, %rdi
callq 0xdba2
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0xbd31
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x98(%rsp), %rdi
cmpq %r12, %rdi
je 0xbd4e
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x4460
movq (%rbx), %rdi
addq $0x20, %rdi
movq %rdi, (%rbx)
leaq 0x19c2c(%rip), %rsi     # 0x2598b
callq 0x40f0
testl %eax, %eax
jne 0xbde7
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0xbd7f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xbd9b
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xbdb7
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4460
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x41d0
movq %rax, %r14
leaq 0x19647(%rip), %rsi     # 0x25424
movq %rax, %rdi
callq 0x4170
jmp 0xbe03
movl $0x10, %edi
callq 0x41d0
movq %rax, %r14
leaq 0x19645(%rip), %rsi     # 0x25440
movq %rax, %rdi
callq 0x4170
movq 0x261e6(%rip), %rsi     # 0x31ff0
movq 0x26197(%rip), %rdx     # 0x31fa8
movq %r14, %rdi
callq 0x4750
movl $0x10, %edi
callq 0x41d0
movq %rax, %r14
leaq 0x195e8(%rip), %rsi     # 0x25415
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x567a
movb $0x1, %bpl
leaq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x46d0
xorl %ebp, %ebp
movq 0x2619b(%rip), %rsi     # 0x31ff0
movq 0x2614c(%rip), %rdx     # 0x31fa8
movq %r14, %rdi
callq 0x4750
jmp 0xbe98
movl $0x10, %edi
callq 0x41d0
movq %rax, %r14
leaq 0x195aa(%rip), %rsi     # 0x25424
movq %rax, %rdi
callq 0x4170
movq 0x26167(%rip), %rsi     # 0x31ff0
movq 0x26118(%rip), %rdx     # 0x31fa8
movq %r14, %rdi
callq 0x4750
movq %rax, %rbx
jmp 0xbece
movq %rax, %rbx
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xbec9
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0xbec9
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0xbef9
movq %r14, %rdi
callq 0x4300
jmp 0xbef9
jmp 0xbf80
jmp 0xbedf
movq %rax, %rbx
movq %r14, %rdi
callq 0x4300
jmp 0xbf4d
jmp 0xbf80
jmp 0xbf80
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
jne 0xbf57
jmp 0xbf83
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0xbf29
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0xbf29
jmp 0xbf4a
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r12, %rdi
je 0xbf4d
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0xbf4d
jmp 0xbf4a
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0xbf83
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0xbf83
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r12, %rdi
je 0xbf83
movq 0xc8(%rsp), %rsi
jmp 0xbf5c
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xbf9f
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xbfbb
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4460
movq %rbx, %rdi
callq 0x4780
movq %rax, %rbx
jmp 0xbf9f