// File: ChristalC[P]Online-Outlier-Detection/p2_helper.cpp
// Function: readInput(int&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
bool readInput(int& window_size, string& host, string& port) {
  string holder;
  vector<string> read_input;

  // Neglect all comment lines
  do {
    if (getline(cin, holder)) {
      read_input = splitString(holder);
    }
    else {
      return false;
    }
  } while (read_input.size() == 0);

  // Read the first line as window_size. 
  // If a number is read, update the window_size
  // If it is not a number, return false
  if (isWindowSize(read_input)) {
    window_size = stoi(read_input[0], NULL, 10);
  }
  else {
    cout << "Window size is incorrect!\n";
    return false;
  }

  // Neglect comment lines
  do {
    if (getline(cin, holder)) {
      read_input = splitString(holder);
    }
    else {
      return false;
    }
  } while (read_input.size() == 0);

  // Read the second line as host and port, marked by a ':' in between
  // If correctly read, update host and port
  // If not, return false
  if (read_input.size() != 1) {
    cout << "Input host:port is invalid!\n";
    return false;
  }
  holder = read_input[0];
  int pos_colon = holder.find_first_of(":");
  if (pos_colon == string::npos) {
    cout << "Port not specified!" << endl;
    return false;
  }
  host = holder.substr(0, pos_colon);
  port = holder.substr(pos_colon + 1);

  // Check if port is a number, if not, return false
  if (!isNum(port)) {
    cout << "Invalid port entered\n";
    return false;
  }
  
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3370
leaq -0x58(%rbp), %rdi
callq 0x98e0
movq 0xabd0(%rip), %rdi      # 0x13fe0
leaq -0x40(%rbp), %rsi
callq 0x3080
movq %rax, -0x150(%rbp)
jmp 0x9422
movq -0x150(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3330
movb %al, -0x151(%rbp)
jmp 0x9440
movb -0x151(%rbp), %al
testb $0x1, %al
jne 0x944c
jmp 0x94c2
leaq -0xa0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3100
jmp 0x945e
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x8df0
jmp 0x9470
leaq -0x58(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x9af0
leaq -0x80(%rbp), %rdi
callq 0x9970
leaq -0xa0(%rbp), %rdi
callq 0x31a0
jmp 0x94d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x981d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x31a0
jmp 0x981d
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa4(%rbp)
jmp 0x97fd
jmp 0x94d7
leaq -0x58(%rbp), %rdi
callq 0x99d0
cmpq $0x0, %rax
je 0x9409
leaq -0x58(%rbp), %rdi
callq 0x8fb0
movb %al, -0x152(%rbp)
jmp 0x94fb
movb -0x152(%rbp), %al
testb $0x1, %al
jne 0x9507
jmp 0x9545
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x160(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x99f0
movq -0x160(%rbp), %rsi
movq %rax, %rdi
movl $0xa, %edx
callq 0x9b20
movl %eax, -0x158(%rbp)
jmp 0x9537
movl -0x158(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
jmp 0x956d
movq 0xaa7c(%rip), %rdi      # 0x13fc8
leaq 0x3b6f(%rip), %rsi      # 0xd0c2
callq 0x3280
jmp 0x955a
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa4(%rbp)
jmp 0x97fd
jmp 0x956f
movq 0xaa6a(%rip), %rdi      # 0x13fe0
leaq -0x40(%rbp), %rsi
callq 0x3080
movq %rax, -0x168(%rbp)
jmp 0x9588
movq -0x168(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3330
movb %al, -0x169(%rbp)
jmp 0x95a6
movb -0x169(%rbp), %al
testb $0x1, %al
jne 0x95b2
jmp 0x9620
leaq -0xe0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3100
jmp 0x95c4
leaq -0xc0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x8df0
jmp 0x95d9
leaq -0x58(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x9af0
leaq -0xc0(%rbp), %rdi
callq 0x9970
leaq -0xe0(%rbp), %rdi
callq 0x31a0
jmp 0x9633
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x31a0
jmp 0x981d
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa4(%rbp)
jmp 0x97fd
jmp 0x9635
leaq -0x58(%rbp), %rdi
callq 0x99d0
cmpq $0x0, %rax
je 0x956f
leaq -0x58(%rbp), %rdi
callq 0x99d0
cmpq $0x1, %rax
je 0x967f
movq 0xa96a(%rip), %rdi      # 0x13fc8
leaq 0x3a78(%rip), %rsi      # 0xd0dd
callq 0x3280
jmp 0x966c
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa4(%rbp)
jmp 0x97fd
xorl %eax, %eax
movl %eax, %esi
leaq -0x58(%rbp), %rdi
callq 0x99f0
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x3040
jmp 0x969a
leaq -0x40(%rbp), %rdi
leaq 0x3a55(%rip), %rsi      # 0xd0fa
xorl %eax, %eax
movl %eax, %edx
callq 0x3110
movl %eax, -0xe4(%rbp)
movslq -0xe4(%rbp), %rax
cmpq $-0x1, %rax
jne 0x9705
movq 0xa900(%rip), %rdi      # 0x13fc8
leaq 0x3a2d(%rip), %rsi      # 0xd0fc
callq 0x3280
movq %rax, -0x178(%rbp)
jmp 0x96dd
movq -0x178(%rbp), %rdi
movq 0xa8c5(%rip), %rsi      # 0x13fb0
callq 0x32d0
jmp 0x96f2
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa4(%rbp)
jmp 0x97fd
movslq -0xe4(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x108(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x32b0
jmp 0x9722
movq -0x18(%rbp), %rdi
leaq -0x108(%rbp), %rsi
movq %rsi, -0x180(%rbp)
callq 0x3310
movq -0x180(%rbp), %rdi
callq 0x31a0
movl -0xe4(%rbp), %eax
incl %eax
movslq %eax, %rdx
leaq -0x128(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movq $-0x1, %rcx
callq 0x32b0
jmp 0x9769
movq -0x20(%rbp), %rdi
leaq -0x128(%rbp), %rsi
movq %rsi, -0x188(%rbp)
callq 0x3310
movq -0x188(%rbp), %rdi
callq 0x31a0
movq -0x20(%rbp), %rsi
leaq -0x148(%rbp), %rdi
callq 0x3100
jmp 0x979e
leaq -0x148(%rbp), %rdi
callq 0x9060
xorb $-0x1, %al
movb %al, -0x189(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x31a0
movb -0x189(%rbp), %al
testb $0x1, %al
jne 0x97ca
jmp 0x97ef
movq 0xa7f7(%rip), %rdi      # 0x13fc8
leaq 0x3938(%rip), %rsi      # 0xd110
callq 0x3280
jmp 0x97df
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa4(%rbp)
jmp 0x97fd
movb $0x1, -0x1(%rbp)
movl $0x1, -0xa4(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x9970
leaq -0x40(%rbp), %rdi
callq 0x31a0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x9970
leaq -0x40(%rbp), %rdi
callq 0x31a0
movq -0x60(%rbp), %rdi
callq 0x3450
nopl (%rax,%rax)