// File: /workspace/github_cpp_makefile_star2_O2/AsherGlick[P]CommentHeader/source/main.cpp
// Function: main
int main(int argv, char * argc[]) {
  initilizeHeaderStyles();
  initilizeFullFlags();

  // parse arguments into a string
  string userInput = "";

  // used to append spaces after the first text argument
  string inputSpaces = "";

  // If there are no arguments, output the help screen
  if (argv <= 1) {
    help();
    return 0;
  }

  // create a vector of the arguments
  vector<string> arguments;
  for (int i = 0; i < argv; i++) {
    arguments.push_back(argc[i]);
  }

  // Loop through all of the arguments
  for (unsigned int i = 1; i < arguments.size(); i++) {
    // Check to see if the input is a flag
    if (arguments[i][0] == '-') {
      // Check to see if the flag is a fulltext flag
      if (arguments[i][1] == '-') {
        string flag = arguments[i];
        flag = flag.substr(2, flag.size() - 2);
        string smallflag = fullFlagCompression[flag];
        if (smallflag == "") {
          cout << "Undefined Argument: " << flag << endl;
          postArgParseHalt = true;
          continue;
        }
        else {
          arguments[i] = "-"+smallflag;
        }
      }
      for (unsigned int j = 1; j < arguments[i].size(); j++) {
        // Grab arguments for width
        if (arguments[i][j] == 'w') {
          if (i+1 >= arguments.size()) {
            cout << "Error: You did not specify a width for your title after using the -w flag" << endl;
            postArgParseHalt = true;
          }
          else {
            titleWidth = atoi(arguments[i + 1].c_str());
            arguments.erase(arguments.begin()+i+1);
          }
        }
        // Grab arguments for length
        else if (arguments[i][j] == 'l') {
          if (i+1 >= arguments.size()) {
            cout << "Error: You did not specify a length for your title after using the -l flag" << endl;
            postArgParseHalt = true;
          }
          else {
            titleLength = atoi(arguments[i + 1].c_str());
            arguments.erase(arguments.begin() + i + 1);
          }
        }
        else if (activateFlag(arguments[i][j])) {}
        else {
          cout << "Undefined flag: " << arguments[i][j] << endl;
          postArgParseHalt = true;  // Stop the program after parsing inputs
        }
      }
    }

    // Take all non flagged input and append it together
    else {
      userInput += inputSpaces + arguments[i];
      inputSpaces = " ";
    }
  }

  // Kill the program if any undefined flags were found
  if (postArgParseHalt) {
    return 1;
  }

  // Prevent the extended input flag and the tital flag from both being active
  if (inputLocationFlagSet && outputFormatFlag != 'f') {
    // extendedInputFlag = false; // TODO should this be replaced?
    cout << "Warning: the input location flag is ignored becasue you are not creating a function title" << endl;
  }

  // A string for containing the extended input's data
  string extendedInputString = "";


  stringstream output;
  // Check to see what type of header needs to be generated
  switch (outputFormatFlag) {
    case 'h':
      help();
      break;
    case 's':
      output << signiture() << endl;
      break;
    case 'b':
      output << bsd(userInput) << endl;
      break;
    case 't':
      output << title(userInput) << endl;
      break;
    case 'f':

      // Check for the input flag
      if (inputLocationFlag == 'a') {
        extendedInputString = "I AM NOT PARSING FROM ARGS PROPERLY"; // TODO: PARSE FROM ARGS
      }
      else if (inputLocationFlag == 'i') {
        extendedInputString = captureExtendedInput();
      }
      else if (inputLocationFlag == 'c') {
        extendedInputString = copyFromClipboard();
      }

      output << headder(userInput, extendedInputString, outputRightWallFlag) << endl;
      break;

    default:
      cout << "ERROR: UNKNOWN FORMAT FLAG FOUND" << endl;
  }

  // Output the results to stdout or to xclip depending on the flag specified
  
  if (outputLocationFlag == 'v') {
    if (copyToClipboard(output.str()) == -1) {
      // Print the output to stdout if xclip is not found
      cout << output.str();
    }
  }
  else if (outputLocationFlag == 'o') {
    cout << output.str();
  }
  else {
    cout << "Invalid outputLocationFlag" << endl;
    cout << output.str();
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2c8, %rsp            # imm = 0x2C8
movq %rsi, %rbx
movl %edi, %r15d
callq 0x36fc
callq 0x76a6
leaq 0x4eb0(%rip), %r14      # 0xcbad
leaq -0xa8(%rbp), %rdi
leaq -0x2f0(%rbp), %rdx
movq %r14, %rsi
callq 0x30f0
leaq -0xc8(%rbp), %rdi
leaq -0x2f0(%rbp), %rdx
movq %r14, %rsi
callq 0x30f0
cmpl $0x1, %r15d
jg 0x7d3b
xorl %ebx, %ebx
callq 0x84c9
jmp 0x8373
xorps %xmm0, %xmm0
leaq -0x60(%rbp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movl %r15d, %r13d
xorl %r14d, %r14d
leaq -0x2f0(%rbp), %r15
leaq -0x88(%rbp), %r12
cmpq %r14, %r13
je 0x7d8b
movq (%rbx,%r14,8), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x30f0
leaq -0x60(%rbp), %rdi
movq %r15, %rsi
callq 0xadf8
movq %r15, %rdi
callq 0x3120
incq %r14
jmp 0x7d5e
pushq $0x1
popq %rax
leaq -0x2f0(%rbp), %rbx
movl %eax, %r14d
movl %r14d, %r14d
movq -0x60(%rbp), %rdx
movq -0x58(%rbp), %rax
subq %rdx, %rax
sarq $0x5, %rax
cmpq %r14, %rax
jbe 0x8012
movq %r14, %r12
shlq $0x5, %r12
movq (%rdx,%r12), %rax
addq %r12, %rdx
cmpb $0x2d, (%rax)
movq %r14, -0x68(%rbp)
jne 0x7e7c
cmpb $0x2d, 0x1(%rax)
jne 0x7f0a
leaq -0x2f0(%rbp), %rbx
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x3310
movq -0x2e8(%rbp), %rcx
addq $-0x2, %rcx
leaq -0x88(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
pushq $0x2
popq %rdx
callq 0x3280
movq %rbx, %rdi
movq %r15, %rsi
callq 0x32e0
movq %r15, %rdi
callq 0x3120
leaq 0xa764(%rip), %rdi      # 0x12588
movq %rbx, %rsi
callq 0xa1f2
movq %r15, %rdi
movq %rax, %rsi
callq 0x3310
movq %r15, %rdi
leaq 0x4d6c(%rip), %rsi      # 0xcbad
callq 0xa1a9
movl %eax, %r14d
testb %al, %al
je 0x7ec8
movq 0xa174(%rip), %rdi      # 0x11fc8
leaq 0x45ea(%rip), %rsi      # 0xc445
callq 0x3260
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3210
movq %rax, %rdi
callq 0x3130
movb $0x1, 0xa73e(%rip)      # 0x125b8
jmp 0x7ef5
movq %rbx, %rdi
leaq -0xc8(%rbp), %rsi
callq 0xa2dc
leaq -0xa8(%rbp), %rdi
movq %rbx, %rsi
callq 0x33e0
movq %rbx, %rdi
callq 0x3120
leaq -0xc8(%rbp), %rdi
leaq 0x416c(%rip), %rsi      # 0xc01c
callq 0x33d0
movq -0x68(%rbp), %r14
incl %r14d
leaq -0x2f0(%rbp), %rbx
jmp 0x7d98
leaq -0x48(%rbp), %r13
movq %r13, %rdi
leaq 0x4bdf(%rip), %rsi      # 0xcab5
movq %r15, %rdx
callq 0xa25b
movq -0x60(%rbp), %rdi
addq %r12, %rdi
movq %r13, %rsi
callq 0x32e0
movq %r13, %rdi
callq 0x3120
movq %r15, %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x3120
testb %r14b, %r14b
jne 0x7eb5
movq -0x68(%rbp), %rax
leal 0x1(%rax), %ebx
movq %rbx, %r15
shlq $0x5, %r15
pushq $0x1
popq %rax
movl %eax, %r13d
movl %r13d, %r13d
movq -0x60(%rbp), %rax
cmpq %r13, 0x8(%rax,%r12)
jbe 0x7eb5
leaq (%rax,%r12), %r14
movq (%r14), %rcx
movzbl (%rcx,%r13), %ecx
cmpl $0x6c, %ecx
je 0x7f81
cmpl $0x77, %ecx
jne 0x7fc7
movq -0x58(%rbp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
leaq 0x4502(%rip), %rsi      # 0xc45a
cmpq %rbx, %rcx
jbe 0x7fb9
movq (%rax,%r15), %rdi
callq 0x3350
movl %eax, 0xa2b4(%rip)      # 0x12220
addq $0x20, %r14
leaq -0x60(%rbp), %rdi
movq %r14, %rsi
callq 0xa2d2
jmp 0x800a
movq -0x58(%rbp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
leaq 0x4511(%rip), %rsi      # 0xc4a4
cmpq %rbx, %rcx
jbe 0x7fb9
movq (%rax,%r15), %rdi
callq 0x3350
movl %eax, 0xa5d9(%rip)      # 0x12580
addq $0x20, %r14
leaq -0x60(%rbp), %rdi
movq %r14, %rsi
callq 0xa2d2
jmp 0x800a
movq 0xa008(%rip), %rdi      # 0x11fc8
callq 0x3260
jmp 0x7ffb
movsbl %cl, %edi
callq 0x798b
testb %al, %al
jne 0x800a
movq 0x9fee(%rip), %rdi      # 0x11fc8
leaq 0x450e(%rip), %rsi      # 0xc4ef
callq 0x3260
movq -0x60(%rbp), %rcx
movq (%rcx,%r12), %rcx
movsbl (%rcx,%r13), %esi
movq %rax, %rdi
callq 0x32c0
movq %rax, %rdi
callq 0x3130
movb $0x1, 0xa5ae(%rip)      # 0x125b8
incl %r13d
jmp 0x7f1e
cmpb $0x0, 0xa59f(%rip)      # 0x125b8
je 0x8023
pushq $0x1
popq %rbx
jmp 0x836a
cmpb $0x1, 0xa550(%rip)      # 0x1257a
jne 0x8050
cmpb $0x66, 0xa1e5(%rip)     # 0x12218
je 0x8050
movq 0x9f8c(%rip), %rdi      # 0x11fc8
leaq 0x44bd(%rip), %rsi      # 0xc500
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq 0x4b56(%rip), %rsi      # 0xcbad
leaq -0x88(%rbp), %rdi
leaq -0x2f0(%rbp), %rdx
callq 0x30f0
leaq -0x2f0(%rbp), %rdi
callq 0x31a0
movzbl 0xa19b(%rip), %eax      # 0x12218
cmpl $0x62, %eax
je 0x8184
cmpl $0x66, %eax
je 0x80f6
cmpl $0x68, %eax
je 0x815a
cmpl $0x73, %eax
je 0x8130
cmpl $0x74, %eax
jne 0x8164
leaq -0x148(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3310
leaq -0x48(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x9238
leaq -0x2e0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x3210
movq %rax, %rdi
callq 0x3130
leaq -0x48(%rbp), %rdi
callq 0x3120
leaq -0x148(%rbp), %rdi
jmp 0x827b
movzbl 0xa11d(%rip), %eax      # 0x1221a
cmpl $0x69, %eax
je 0x81df
cmpl $0x63, %eax
je 0x81d4
cmpl $0x61, %eax
jne 0x8203
leaq 0x443b(%rip), %rsi      # 0xc55a
leaq -0x88(%rbp), %rdi
callq 0x33d0
jmp 0x8203
leaq -0x48(%rbp), %rdi
callq 0x8985
leaq -0x2e0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x3210
movq %rax, %rdi
callq 0x3130
leaq -0x48(%rbp), %rdi
jmp 0x827b
callq 0x84c9
jmp 0x8280
movq 0x9e5d(%rip), %rdi      # 0x11fc8
leaq 0x440c(%rip), %rsi      # 0xc57e
callq 0x3260
movq %rax, %rdi
callq 0x3130
jmp 0x8280
leaq -0x168(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3310
leaq -0x48(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x8c36
leaq -0x2e0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x3210
movq %rax, %rdi
callq 0x3130
leaq -0x48(%rbp), %rdi
callq 0x3120
leaq -0x168(%rbp), %rdi
jmp 0x827b
leaq -0x48(%rbp), %rdi
callq 0x7412
jmp 0x81e8
leaq -0x48(%rbp), %rdi
callq 0x7b4b
leaq -0x88(%rbp), %rdi
leaq -0x48(%rbp), %rbx
movq %rbx, %rsi
callq 0x32e0
movq %rbx, %rdi
callq 0x3120
leaq -0x128(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3310
leaq -0x108(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3310
movsbl 0x9fe9(%rip), %ecx      # 0x12219
leaq -0x48(%rbp), %rdi
leaq -0x128(%rbp), %rsi
leaq -0x108(%rbp), %rdx
callq 0x970d
leaq -0x2e0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x3210
movq %rax, %rdi
callq 0x3130
leaq -0x48(%rbp), %rdi
callq 0x3120
leaq -0x108(%rbp), %rdi
callq 0x3120
leaq -0x128(%rbp), %rdi
callq 0x3120
movzbl 0x9f94(%rip), %eax      # 0x1221b
cmpl $0x6f, %eax
je 0x82ea
cmpl $0x76, %eax
jne 0x830c
leaq -0x2d8(%rbp), %rbx
leaq -0xe8(%rbp), %rdi
movq %rbx, %rsi
callq 0x3370
leaq -0xe8(%rbp), %rdi
callq 0x72d8
movl %eax, %r14d
leaq -0xe8(%rbp), %rdi
callq 0x3120
cmpl $-0x1, %r14d
jne 0x8350
leaq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x3370
movq 0x9ce9(%rip), %rdi      # 0x11fc8
leaq -0x48(%rbp), %rsi
callq 0x3210
jmp 0x8347
leaq -0x2d8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x3370
movq 0x9cc7(%rip), %rdi      # 0x11fc8
leaq -0x48(%rbp), %rsi
callq 0x3210
jmp 0x8347
movq 0x9cb5(%rip), %rdi      # 0x11fc8
leaq 0x4285(%rip), %rsi      # 0xc59f
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq -0x2d8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x3370
movq 0x9c8a(%rip), %rdi      # 0x11fc8
leaq -0x48(%rbp), %rsi
callq 0x3210
leaq -0x48(%rbp), %rdi
callq 0x3120
leaq -0x2f0(%rbp), %rdi
callq 0x31c0
leaq -0x88(%rbp), %rdi
callq 0x3120
xorl %ebx, %ebx
leaq -0x60(%rbp), %rdi
callq 0x684a
leaq -0xc8(%rbp), %rdi
callq 0x3120
leaq -0xa8(%rbp), %rdi
callq 0x3120
movl %ebx, %eax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8445
jmp 0x8445
jmp 0x842e
jmp 0x8445
movq %rax, %rbx
jmp 0x83ed
movq %rax, %rbx
jmp 0x83f9
movq %rax, %rbx
jmp 0x8410
movq %rax, %rbx
jmp 0x8425
jmp 0x8445
jmp 0x8445
jmp 0x8445
jmp 0x8445
jmp 0x842e
jmp 0x8445
jmp 0x842e
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
jmp 0x8435
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x3120
leaq -0x108(%rbp), %rdi
callq 0x3120
leaq -0x128(%rbp), %rdi
jmp 0x8435
jmp 0x8445
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x3120
leaq -0x168(%rbp), %rdi
jmp 0x8435
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x3120
leaq -0x148(%rbp), %rdi
jmp 0x8435
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x3120
jmp 0x8448
movq %rax, %rbx
jmp 0x8454
jmp 0x849d
jmp 0x849d
movq %rax, %rbx
leaq -0x2f0(%rbp), %rdi
callq 0x31c0
leaq -0x88(%rbp), %rdi
jmp 0x8492
movq %rax, %rbx
jmp 0x84a9
movq %rax, %rbx
jmp 0x84b5
jmp 0x846d
jmp 0x849d
jmp 0x8488
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x3120
jmp 0x848b
jmp 0x8488
jmp 0x8488
jmp 0x849d
jmp 0x849d
jmp 0x849d
movq %rax, %rbx
leaq -0x2f0(%rbp), %rdi
callq 0x3120
jmp 0x84a0
jmp 0x849d
jmp 0x849d
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x684a
leaq -0xc8(%rbp), %rdi
callq 0x3120
leaq -0xa8(%rbp), %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x3390