// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
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 0x4f32
leaq 0x1f8(%rsp), %rdi
movq %r14, %rsi
callq 0x4f32
leaq 0x278(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
leaq 0x1c0(%rsp), %rdx
callq 0x2d26
leaq 0x1f8(%rsp), %rdi
callq 0x50b4
leaq 0x278(%rsp), %rdi
callq 0x50b4
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x1d0(%rsp), %r12
testq %r12, %r12
je 0x311d
leaq 0x30(%rsp), %r15
leaq 0x8(%r12), %rdx
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x310c
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x3114
movq %r15, %rdi
callq 0x74ea
movq (%r12), %r12
testq %r12, %r12
jne 0x30ec
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(%r14)
jne 0x3156
movb $0x0, 0x78(%r14)
movq 0x40(%r14), %r15
testq %r15, %r15
je 0x31b0
movq (%r15), %r13
testq %r13, %r13
je 0x31a3
movq %rbx, (%rsp)
leaq -0x8(%r13), %r12
movq -0x8(%r13), %rbp
testq %rbp, %rbp
je 0x318f
imulq $0x38, %rbp, %rbx
addq $-0x38, %r13
leaq (%rbx,%r13), %rdi
callq 0x618a
addq $-0x38, %rbx
jne 0x3180
imulq $0x38, %rbp, %rsi
addq $0x8, %rsi
movq %r12, %rdi
callq 0x2390
movq (%rsp), %rbx
movl $0x18, %esi
movq %r15, %rdi
callq 0x2240
movl $0x18, %edi
callq 0x2230
movq %rax, %r15
movq 0x38(%r14), %rsi
movq %rax, %rdi
callq 0x4ace
movq %r15, 0x40(%r14)
movq (%rbx), %r12
movq 0x8(%rbx), %r13
cmpq %r13, %r12
je 0x3313
leaq 0x140(%rsp), %rbx
leaq 0x120(%rsp), %r14
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 0x6062
movq 0x90(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x120(%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 0x7078
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x2f9a
movq 0x130(%rsp), %rdi
cmpq %rbx, %rdi
je 0x3285
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x2240
movslq 0x14(%rbp), %rax
testq %rax, %rax
jle 0x3306
movq (%rbp), %rcx
cmpq $0x0, 0x28(%rcx)
jne 0x32bd
addq $0x60, %rcx
movl $0x1, %esi
movq %rsi, %rdx
cmpq %rsi, %rax
je 0x32b8
leaq 0x1(%rdx), %rsi
cmpq $0x0, (%rcx)
leaq 0x38(%rcx), %rcx
je 0x32a2
cmpq %rax, %rdx
jae 0x3306
leaq 0x190(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x51ec
movq %rbp, (%rax)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x32f4
movq 0x90(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x18(%rsp)
jmp 0x3306
leaq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %rdx
callq 0x783a
addq $0x8, %r12
cmpq %r13, %r12
jne 0x31ed
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %rax
movq %rax, 0x110(%rsp)
cmpq %rax, %rbx
je 0x367f
leaq 0x80(%rsp), %r13
movl (%rbx), %eax
movl %eax, 0xc(%rsp)
leaq 0x1c0(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x710e
movq (%rax), %rsi
leaq 0x178(%rsp), %rdi
callq 0x4ace
movq %rbx, 0x118(%rsp)
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %rax
movq %rax, (%rsp)
cmpq %rax, %rbp
je 0x361c
movq (%rbp), %rax
movq %rax, 0x58(%rsp)
movl $0x18, %edi
callq 0x2230
movq %rax, %r14
leaq 0x190(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x51ec
movq (%rax), %rsi
movq %r14, %rdi
callq 0x4c54
movq 0x58(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x60(%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 0x7078
leaq 0x160(%rsp), %rdi
movq %r14, %rsi
callq 0x4c54
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 0x7078
leaq 0xc0(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x4c54
movq $0x0, 0xf8(%rsp)
leaq 0x108(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq $0x1, 0xe0(%rsp)
leaq 0xa0(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rax)
movl $0x3f800000, 0xf8(%rsp) # imm = 0x3F800000
movups %xmm0, 0x60(%rax)
movq 0x160(%rsp), %rbx
testq %rbx, %rbx
je 0x34cb
movq -0x8(%rbx), %r12
testq %r12, %r12
je 0x34af
imulq $0x38, %r12, %r13
leaq -0x38(%rbx), %r15
leaq (%r15,%r13), %rdi
callq 0x618a
addq $-0x38, %r13
jne 0x34a0
addq $-0x8, %rbx
imulq $0x38, %r12, %rsi
addq $0x8, %rsi
movq %rbx, %rdi
callq 0x2390
leaq 0x80(%rsp), %r13
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x34e5
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2240
movq %r14, %rdi
leaq 0x178(%rsp), %rsi
movl $0x1, %edx
callq 0x4a4a
movl 0xc(%rsp), %r12d
movl $0x18, %edi
callq 0x2230
movq %rax, %rbx
movq %rax, %rdi
movq %r14, %rsi
callq 0x4c54
movl %r12d, 0x150(%rsp)
movq %rbx, 0x158(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x739e
movslq 0xd4(%rsp), %rax
testq %rax, %rax
jle 0x357e
movq 0xc0(%rsp), %rcx
cmpq $0x0, 0x28(%rcx)
jne 0x3589
addq $0x60, %rcx
leaq -0x1(%rax), %rsi
xorl %edx, %edx
cmpq %rdx, %rsi
je 0x3576
incq %rdx
cmpq $0x0, (%rcx)
leaq 0x38(%rcx), %rcx
je 0x3562
jmp 0x3579
movq %rax, %rdx
cmpq %rax, %rdx
jb 0x3589
cmpq $0x0, 0xf0(%rsp)
je 0x359b
movq 0x50(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x5252
leaq 0xd8(%rsp), %rdi
callq 0x6e14
movq 0xc0(%rsp), %rbx
testq %rbx, %rbx
je 0x35e9
movq -0x8(%rbx), %r14
testq %r14, %r14
je 0x35d5
imulq $0x38, %r14, %r12
leaq -0x38(%rbx), %r15
leaq (%r15,%r12), %rdi
callq 0x618a
addq $-0x38, %r12
jne 0x35c6
addq $-0x8, %rbx
imulq $0x38, %r14, %rsi
addq $0x8, %rsi
movq %rbx, %rdi
callq 0x2390
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x360e
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2240
addq $0x8, %rbp
cmpq (%rsp), %rbp
jne 0x337d
movq 0x178(%rsp), %r14
testq %r14, %r14
je 0x3665
movq -0x8(%r14), %rbx
testq %rbx, %rbx
je 0x3649
imulq $0x38, %rbx, %r12
leaq -0x38(%r14), %r13
leaq (%r12,%r13), %rdi
callq 0x618a
addq $-0x38, %r12
jne 0x363a
addq $-0x8, %r14
imulq $0x38, %rbx, %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0x2390
leaq 0x80(%rsp), %r13
movq 0x118(%rsp), %rbx
addq $0x4, %rbx
cmpq 0x110(%rsp), %rbx
jne 0x3336
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %rbx
cmpq %rbx, %r13
je 0x3731
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 0x51ec
movq (%rax), %r15
testq %r15, %r15
je 0x3717
movq (%r15), %r12
testq %r12, %r12
je 0x3717
movq -0x8(%r12), %rbx
testq %rbx, %rbx
je 0x36ef
imulq $0x38, %rbx, %r14
leaq -0x38(%r12), %rbp
leaq (%r14,%rbp), %rdi
callq 0x618a
addq $-0x38, %r14
jne 0x36e0
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 0x36a6
leaq 0x190(%rsp), %rdi
callq 0x6dc4
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3755
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2240
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x376c
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2240
leaq 0x1c0(%rsp), %rdi
callq 0x6e14
movq 0x50(%rsp), %rax
addq $0x2f8, %rsp            # imm = 0x2F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r12
movl $0x18, %esi
movq %r15, %rdi
jmp 0x3804
jmp 0x3810
movq %rax, %r12
leaq 0x1f8(%rsp), %rdi
callq 0x50b4
jmp 0x37b4
movq %rax, %r12
leaq 0x278(%rsp), %rdi
callq 0x50b4
jmp 0x38f3
movq %rax, %r12
jmp 0x38f3
movq %rax, %r12
jmp 0x38dc
jmp 0x3810
movq %rax, %r12
movq 0x130(%rsp), %rdi
cmpq %rbx, %rdi
je 0x38b8
movq 0x140(%rsp), %rsi
incq %rsi
jmp 0x3804
movq %rax, %r12
movl $0x18, %esi
movq %rbp, %rdi
callq 0x2240
jmp 0x38b8
jmp 0x3810
movq %rax, %r12
jmp 0x38b8
movq %rax, %r12
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x3865
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2240
jmp 0x3865
jmp 0x3846
jmp 0x389b
movq %rax, %r12
jmp 0x38ab
movq %rax, %r12
jmp 0x3872
movq %rax, %r12
movl $0x18, %esi
movq %rbx, %rdi
callq 0x2240
jmp 0x389e
movq %rax, %r12
leaq 0x160(%rsp), %rdi
callq 0x4bf8
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x38ab
movq 0x80(%rsp), %rsi
incq %rsi
jmp 0x3894
movq %rax, %r12
movl $0x18, %esi
movq %r14, %rdi
callq 0x2240
jmp 0x38ab
movq %rax, %r12
leaq 0x90(%rsp), %rdi
callq 0x527c
leaq 0x178(%rsp), %rdi
callq 0x4bf8
leaq 0x190(%rsp), %rdi
callq 0x6dc4
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x38dc
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2240
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x38f3
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2240
leaq 0x1c0(%rsp), %rdi
callq 0x6e14
movq 0x50(%rsp), %rdi
callq 0x52fa
movq %r12, %rdi
callq 0x2360