// File: /workspace/github_cpp_makefile_star2_O1/BUSEC[P]RPKI_Downgrade_Detector/./exp.cpp
// Function: UnknownToInvalid(ROAGroup*, ROAGroup*, std::vector<ROA*, std::allocator<ROA*>>*)
vector<UnknownToInvalidDowngrade> UnknownToInvalid( ROAGroup* newPrefixes, ROAGroup* oldPrefixes, vector<ROA*>* rNews){
  vector<UnknownToInvalidDowngrade> downgrades;
  
  unordered_map<int, PrefixRange*> notValidToValidPrefixes; // This map is every Prefix which was invalid/unknown in old and is valid in new
  NotValidToValid( *newPrefixes, *oldPrefixes, &notValidToValidPrefixes);

  // Find those AS \in A, where A is all the ASes which created newly valid prefixes.
  // A should just much smaller than the set of all ASes.
  vector<int> A;

  // Save all the keys of notValidToValidPrefixes, done to maintain consistant notion between paper and program. A = notValidToValidPrefixes.keys()
  for(unordered_map<int,PrefixRange*>::iterator i = notValidToValidPrefixes.begin(); i != notValidToValidPrefixes.end(); ++i) A.push_back(i->first);
  
  vector<ROA*> rNewlyValid;
  map<ROA*, PrefixRange*> unknownToKnownByR;
  // Compute all the ROAs that creately newly valid prefixes, since we need to compute 
  // unknown to known to do this lets save the result and reuse it below.

  const PrefixRange* oldUnknown = oldPrefixes->getUnknown(); 

  for( ROA* r: *rNews){  
    PrefixRange* rUnknownToKnown = new PrefixRange(); // Don't free this
    UnknownToKnown( oldUnknown, *r, rUnknownToKnown);

    if( ! rUnknownToKnown->empty() ){
      unknownToKnownByR[r] = rUnknownToKnown;
      rNewlyValid.push_back(r); 
    }
  }

  for (int as: A) {

    PrefixRange complementNotValidToValidPrefixes = notValidToValidPrefixes[as]->complement();

    for( ROA* r: rNewlyValid){      
      PrefixRange* rUnknownToKnown = new PrefixRange( *unknownToKnownByR[r] );

      UnknownToInvalidDowngrade downgrade = UnknownToInvalidDowngrade(*r, *rUnknownToKnown);

      rUnknownToKnown->denseIntersectWith( complementNotValidToValidPrefixes, true);

      PrefixRange* unknownToInvalid = rUnknownToKnown;

      downgrade.addException(as, unknownToInvalid); 

      if ( ! downgrade.empty() ){
        downgrades.push_back(downgrade);
      }
    } // R.New.valid loop
  } // as loop

  //clean up
  for( ROA* r: rNewlyValid) delete unknownToKnownByR[r];

  return downgrades;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2f8, %rsp            # imm = 0x2F8
movq %rcx, %rbx
movq %rdx, %r15
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rdi, 0x50(%rsp)
movq $0x0, 0x10(%rdi)
leaq 0x1f0(%rsp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
leaq 0x278(%rsp), %rdi
callq 0x51aa
leaq 0x1f8(%rsp), %rdi
movq %r15, %rsi
callq 0x51aa
leaq 0x278(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
leaq 0x1c0(%rsp), %rdx
callq 0x2e03
leaq 0x1f8(%rsp), %rdi
callq 0x532c
leaq 0x278(%rsp), %rdi
callq 0x532c
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x1d0(%rsp), %r12
testq %r12, %r12
je 0x32dc
leaq 0x30(%rsp), %r14
leaq 0x8(%r12), %rdx
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x32cb
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x32d3
movq %r14, %rdi
callq 0x77de
movq (%r12), %r12
testq %r12, %r12
jne 0x32ab
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
leaq 0x198(%rsp), %rcx
movl $0x0, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
cmpb $0x1, 0x78(%r15)
jne 0x3315
movb $0x0, 0x78(%r15)
movq 0x40(%r15), %r14
testq %r14, %r14
je 0x336f
movq (%r14), %r13
testq %r13, %r13
je 0x3362
movq %rbx, (%rsp)
leaq -0x8(%r13), %r12
movq -0x8(%r13), %rbp
testq %rbp, %rbp
je 0x334e
imulq $0x38, %rbp, %rbx
addq $-0x38, %r13
leaq (%rbx,%r13), %rdi
callq 0x6422
addq $-0x38, %rbx
jne 0x333f
imulq $0x38, %rbp, %rsi
addq $0x8, %rsi
movq %r12, %rdi
callq 0x2390
movq (%rsp), %rbx
movl $0x18, %esi
movq %r14, %rdi
callq 0x2240
movl $0x18, %edi
callq 0x2230
movq %rax, %r14
movq 0x38(%r15), %rsi
movq %rax, %rdi
callq 0x4d1a
movq %r14, 0x40(%r15)
movq (%rbx), %r12
movq 0x8(%rbx), %r13
cmpq %r13, %r12
je 0x34e2
leaq 0x140(%rsp), %rbx
leaq 0x120(%rsp), %r15
movq (%r12), %rax
movq %rax, 0x90(%rsp)
movl $0x18, %edi
callq 0x2230
movq %rax, %rbp
movq $0x0, 0x8(%rax)
movq %rax, %rdi
movl $0x20, %esi
callq 0x62f4
movq 0x90(%rsp), %rax
movl (%rax), %ecx
movl %ecx, 0x120(%rsp)
movl 0x4(%rax), %ecx
movl %ecx, 0x124(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x128(%rsp)
movq %rbx, 0x130(%rsp)
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
addq %rsi, %rdx
leaq 0x130(%rsp), %rdi
callq 0x7372
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x314a
movq 0x130(%rsp), %rdi
cmpq %rbx, %rdi
je 0x344c
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x2240
movslq 0x14(%rbp), %rax
testq %rax, %rax
setle %cl
jle 0x3488
movq (%rbp), %rcx
cmpq $0x0, 0x28(%rcx)
jne 0x348c
addq $0x60, %rcx
movl $0x1, %esi
movq %rsi, %rdx
cmpq %rsi, %rax
je 0x3482
leaq 0x1(%rdx), %rsi
cmpq $0x0, (%rcx)
leaq 0x38(%rcx), %rcx
je 0x346c
cmpq %rax, %rdx
setae %cl
testb %cl, %cl
jne 0x34d5
leaq 0x190(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x5462
movq %rbp, (%rax)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x34c3
movq 0x90(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x18(%rsp)
jmp 0x34d5
leaq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %rdx
callq 0x7b2e
addq $0x8, %r12
cmpq %r13, %r12
jne 0x33ac
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %rax
movq %rax, 0x110(%rsp)
cmpq %rax, %rbx
je 0x3877
leaq 0x80(%rsp), %r13
leaq 0xd8(%rsp), %r15
movl (%rbx), %eax
movl %eax, 0xc(%rsp)
leaq 0x1c0(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x7402
movq (%rax), %rsi
leaq 0x178(%rsp), %rdi
callq 0x4d1a
movq %rbx, 0x118(%rsp)
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %rax
movq %rax, (%rsp)
cmpq %rax, %rbp
je 0x3814
movq (%rbp), %rax
movq %rax, 0x58(%rsp)
movl $0x18, %edi
callq 0x2230
movq %rax, %r14
leaq 0x190(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x5462
movq (%rax), %rsi
movq %r14, %rdi
callq 0x4ea8
movq 0x58(%rsp), %rax
movl (%rax), %ecx
movl %ecx, 0x60(%rsp)
movl 0x4(%rax), %ecx
movl %ecx, 0x64(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x68(%rsp)
movq %r13, 0x70(%rsp)
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0x7372
leaq 0x160(%rsp), %rdi
movq %r14, %rsi
callq 0x4ea8
movups 0x60(%rsp), %xmm0
movups %xmm0, 0x90(%rsp)
leaq 0xb0(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
addq %rsi, %rdx
leaq 0xa0(%rsp), %rdi
callq 0x7372
leaq 0xc0(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x4ea8
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%r15)
movups %xmm0, 0x10(%r15)
movups %xmm0, (%r15)
movq $0x0, 0x30(%r15)
leaq 0x108(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq $0x1, 0xe0(%rsp)
leaq 0xa0(%rsp), %rax
movups %xmm0, 0x48(%rax)
movl $0x3f800000, 0xf8(%rsp) # imm = 0x3F800000
movups %xmm0, 0x60(%rax)
movq 0x160(%rsp), %rbx
testq %rbx, %rbx
je 0x36b9
movq -0x8(%rbx), %r12
testq %r12, %r12
je 0x3695
imulq $0x38, %r12, %r15
leaq -0x38(%rbx), %r13
leaq (%r15,%r13), %rdi
callq 0x6422
addq $-0x38, %r15
jne 0x3686
addq $-0x8, %rbx
imulq $0x38, %r12, %rsi
addq $0x8, %rsi
movq %rbx, %rdi
callq 0x2390
leaq 0x80(%rsp), %r13
leaq 0xd8(%rsp), %r15
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x36d3
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2240
movq %r14, %rdi
leaq 0x178(%rsp), %rsi
movl $0x1, %edx
callq 0x4c96
movl 0xc(%rsp), %r12d
movl $0x18, %edi
callq 0x2230
movq %rax, %rbx
movq %rax, %rdi
movq %r14, %rsi
callq 0x4ea8
movl %r12d, 0x150(%rsp)
movq %rbx, 0x158(%rsp)
movq %r15, %rdi
leaq 0x150(%rsp), %rsi
callq 0x7680
movslq 0xd4(%rsp), %rax
testq %rax, %rax
setle %cl
jle 0x376f
movq 0xc0(%rsp), %rcx
cmpq $0x0, 0x28(%rcx)
je 0x3748
xorl %ecx, %ecx
jmp 0x376f
addq $0x60, %rcx
leaq -0x1(%rax), %rsi
xorl %edx, %edx
cmpq %rdx, %rsi
je 0x3766
incq %rdx
cmpq $0x0, (%rcx)
leaq 0x38(%rcx), %rcx
je 0x3752
jmp 0x3769
movq %rax, %rdx
cmpq %rax, %rdx
setae %cl
testb %cl, %cl
je 0x377e
cmpq $0x0, 0xf0(%rsp)
je 0x3790
movq 0x50(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x54c8
movq %r15, %rdi
callq 0x70b2
movq 0xc0(%rsp), %rbx
testq %rbx, %rbx
je 0x37e1
movq -0x8(%rbx), %r14
testq %r14, %r14
je 0x37c5
imulq $0x38, %r14, %r15
leaq -0x38(%rbx), %r12
leaq (%r12,%r15), %rdi
callq 0x6422
addq $-0x38, %r15
jne 0x37b6
addq $-0x8, %rbx
imulq $0x38, %r14, %rsi
addq $0x8, %rsi
movq %rbx, %rdi
callq 0x2390
leaq 0xd8(%rsp), %r15
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x3806
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2240
addq $0x8, %rbp
cmpq (%rsp), %rbp
jne 0x3554
movq 0x178(%rsp), %r14
testq %r14, %r14
je 0x385d
movq -0x8(%r14), %rbx
testq %rbx, %rbx
je 0x3841
imulq $0x38, %rbx, %r12
leaq -0x38(%r14), %r15
leaq (%r15,%r12), %rdi
callq 0x6422
addq $-0x38, %r12
jne 0x3832
addq $-0x8, %r14
imulq $0x38, %rbx, %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0x2390
leaq 0xd8(%rsp), %r15
movq 0x118(%rsp), %rbx
addq $0x4, %rbx
cmpq 0x110(%rsp), %rbx
jne 0x350d
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %rbx
cmpq %rbx, %r13
je 0x3929
leaq 0x190(%rsp), %r14
leaq 0x90(%rsp), %rbp
movq %rbx, (%rsp)
movq (%r13), %rax
movq %rax, 0x90(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x5462
movq (%rax), %r15
testq %r15, %r15
je 0x391c
movq (%r15), %r12
testq %r12, %r12
je 0x390f
movq -0x8(%r12), %rbx
testq %rbx, %rbx
je 0x38e7
imulq $0x38, %rbx, %r14
leaq -0x38(%r12), %rbp
leaq (%r14,%rbp), %rdi
callq 0x6422
addq $-0x38, %r14
jne 0x38d8
addq $-0x8, %r12
imulq $0x38, %rbx, %rsi
addq $0x8, %rsi
movq %r12, %rdi
callq 0x2390
movq (%rsp), %rbx
leaq 0x190(%rsp), %r14
leaq 0x90(%rsp), %rbp
movl $0x18, %esi
movq %r15, %rdi
callq 0x2240
addq $0x8, %r13
cmpq %rbx, %r13
jne 0x389e
leaq 0x190(%rsp), %rdi
callq 0x7062
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x394d
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2240
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3964
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2240
leaq 0x1c0(%rsp), %rdi
callq 0x70b2
movq 0x50(%rsp), %rax
addq $0x2f8, %rsp            # imm = 0x2F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movl $0x18, %esi
movq %r14, %rdi
jmp 0x39fc
jmp 0x3a08
movq %rax, %r15
leaq 0x1f8(%rsp), %rdi
callq 0x532c
jmp 0x39ac
movq %rax, %r15
leaq 0x278(%rsp), %rdi
callq 0x532c
jmp 0x3aeb
movq %rax, %r15
jmp 0x3aeb
movq %rax, %r15
jmp 0x3ad4
jmp 0x3a08
movq %rax, %r15
movq 0x130(%rsp), %rdi
cmpq %rbx, %rdi
je 0x3ab0
movq 0x140(%rsp), %rsi
incq %rsi
jmp 0x39fc
movq %rax, %r15
movl $0x18, %esi
movq %rbp, %rdi
callq 0x2240
jmp 0x3ab0
jmp 0x3a08
movq %rax, %r15
jmp 0x3ab0
jmp 0x3a6a
movq %rax, %r15
jmp 0x3a3f
movq %rax, %r15
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x3a3f
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2240
leaq 0x160(%rsp), %rdi
callq 0x4e4c
jmp 0x3a51
movq %rax, %r15
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x3aa3
movq 0x80(%rsp), %rsi
incq %rsi
jmp 0x3a8c
jmp 0x3a93
movq %rax, %r15
jmp 0x3aa3
movq %rax, %r15
movl $0x18, %esi
movq %rbx, %rdi
callq 0x2240
jmp 0x3a96
movq %rax, %r15
movl $0x18, %esi
movq %r14, %rdi
callq 0x2240
jmp 0x3aa3
movq %rax, %r15
leaq 0x90(%rsp), %rdi
callq 0x54f2
leaq 0x178(%rsp), %rdi
callq 0x4e4c
leaq 0x190(%rsp), %rdi
callq 0x7062
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3ad4
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2240
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3aeb
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2240
leaq 0x1c0(%rsp), %rdi
callq 0x70b2
movq 0x50(%rsp), %rdi
callq 0x5570
movq %r15, %rdi
callq 0x2360