// File: /workspace/github_cpp_makefile_star2_O2/BUSEC[P]RPKI_Downgrade_Detector/./exp.cpp
// Function: OutputDowngrades(std::vector<ROA*, std::allocator<ROA*>>*, std::vector<ROA*, std::allocator<ROA*>>*, std::ostream*, bool)
void OutputDowngrades( vector<ROA*>* oldROAs, vector<ROA*>* newROAs, ostream* output, bool U2I ) {
  vector<PrefixRange*> validToUnknownPrefixes; 


  ROAGroup oldPrefixes = ROAGroup(oldROAs); // old.AS.valid
  ROAGroup newPrefixes = ROAGroup(newROAs); // new.AS.valid

  //valid to invalid move this into method 
  for ( ROA* rOld: *oldROAs){
    int as = rOld->getAS();

    PrefixRange effect = PrefixRange( rOld->getPrefix(), rOld->getMaxlen() ); 
    effect.addROA( rOld->getPrefix(), rOld->getMaxlen() ); 

    ValidToInvalid( &newPrefixes, &effect, as);

    if( ! effect.empty() ) {
      (*output)<<"{";
      (*output)<<"\"CHANGE\":\"-V2I\", ";
      (*output)<<"\"ROA\":"<<rOld->toJSON()<<", ";      
      (*output)<< "\"EFFECT\":"<<effect.toJSON(); 
      (*output)<<"}"<<endl;
    }
  }

  //valid to unknown
  for ( ROA* rOld: *oldROAs){
    PrefixRange effect = PrefixRange( rOld->getPrefix(), rOld->getMaxlen() );
    effect.addROA( rOld->getPrefix(), rOld->getMaxlen() );

    ValidToUnknown( &newPrefixes, &effect);

    if( ! effect.empty() )  {
      (*output)<<"{";
      (*output)<<"\"CHANGE\":\"-V2U\", ";
      (*output)<<"\"ROA\":"<<rOld->toJSON()<<", ";      
      (*output)<< "\"EFFECT\":"<<effect.toJSON(); 
      (*output)<<"}"<<endl;
    }

  }
  
  if( U2I ){
    //unknown to invalid
    vector<UnknownToInvalidDowngrade> unknownToInvalid = UnknownToInvalid( &newPrefixes, &oldPrefixes, newROAs);
      
    for (UnknownToInvalidDowngrade effect:  unknownToInvalid){
      if( ! effect.empty() ) (*output)<<effect.toJSON();
    }
  }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
andq $0x0, 0x90(%rsp)
leaq 0x198(%rsp), %rdi
movq %r15, %rsi
callq 0x4264
movl %ebp, 0x14(%rsp)
leaq 0x118(%rsp), %rdi
movq %r14, 0x18(%rsp)
movq %r14, %rsi
callq 0x4264
movq (%r15), %r14
movq %r15, 0x20(%rsp)
movq 0x8(%r15), %rax
movq %rax, 0x8(%rsp)
leaq 0x60(%rsp), %r12
leaq 0x98(%rsp), %r15
cmpq 0x8(%rsp), %r14
je 0x311b
movq (%r14), %r13
movl 0xc(%r13), %ebp
movq (%r13), %rax
movq %rax, 0x40(%rsp)
movl 0x8(%r13), %edx
movq %r12, %rdi
leaq 0x40(%rsp), %rsi
callq 0x42f0
movq (%r13), %rax
movq %rax, 0x38(%rsp)
movl 0x8(%r13), %edx
movq %r12, %rdi
leaq 0x38(%rsp), %rsi
callq 0x3d6c
leaq 0x118(%rsp), %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x28f0
movq %r12, %rdi
callq 0x3c52
testb %al, %al
jne 0x310a
movq %rbx, %rdi
leaq 0x42b1(%rip), %rsi      # 0x7321
callq 0x2230
movq %rbx, %rdi
leaq 0x402c(%rip), %rsi      # 0x70ab
callq 0x2230
movq %rbx, %rdi
leaq 0x402f(%rip), %rsi      # 0x70bd
callq 0x2230
movq %rax, %rbp
movq %r15, %rdi
movq %r13, %rsi
callq 0x42fe
movq %rbp, %rdi
movq %r15, %rsi
callq 0x2210
movq %rax, %rdi
leaq 0x425f(%rip), %rsi      # 0x7315
callq 0x2230
movq %r15, %rdi
callq 0x20e0
movq %rbx, %rdi
leaq 0x3ff7(%rip), %rsi      # 0x70c4
callq 0x2230
movq %rax, %r13
movq %r15, %rdi
movq %r12, %rsi
callq 0x4460
movq %r13, %rdi
movq %r15, %rsi
callq 0x2210
movq %r15, %rdi
callq 0x20e0
movq %rbx, %rdi
leaq 0x3f25(%rip), %rsi      # 0x7022
callq 0x2230
movq %rax, %rdi
callq 0x2100
movq %r12, %rdi
callq 0x3bf6
addq $0x8, %r14
jmp 0x2ffe
movq 0x20(%rsp), %rax
movq (%rax), %r13
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
leaq 0x60(%rsp), %r15
leaq 0x98(%rsp), %rbp
cmpq 0x8(%rsp), %r13
je 0x3253
movq (%r13), %r12
movq (%r12), %rax
movq %rax, 0x30(%rsp)
movl 0x8(%r12), %edx
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
callq 0x42f0
movq (%r12), %rax
movq %rax, 0x28(%rsp)
movl 0x8(%r12), %edx
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x3d6c
leaq 0x118(%rsp), %rdi
movq %r15, %rsi
callq 0x28d9
movq %r15, %rdi
callq 0x3c52
testb %al, %al
jne 0x3242
movq %rbx, %rdi
leaq 0x4179(%rip), %rsi      # 0x7321
callq 0x2230
movq %rbx, %rdi
leaq 0x3f17(%rip), %rsi      # 0x70ce
callq 0x2230
movq %rbx, %rdi
leaq 0x3ef7(%rip), %rsi      # 0x70bd
callq 0x2230
movq %rax, %r14
movq %rbp, %rdi
movq %r12, %rsi
callq 0x42fe
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2210
movq %rax, %rdi
leaq 0x4127(%rip), %rsi      # 0x7315
callq 0x2230
movq %rbp, %rdi
callq 0x20e0
movq %rbx, %rdi
leaq 0x3ebf(%rip), %rsi      # 0x70c4
callq 0x2230
movq %rax, %r14
movq %rbp, %rdi
movq %r15, %rsi
callq 0x4460
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2210
movq %rbp, %rdi
callq 0x20e0
movq %rbx, %rdi
leaq 0x3ded(%rip), %rsi      # 0x7022
callq 0x2230
movq %rax, %rdi
callq 0x2100
movq %r15, %rdi
callq 0x3bf6
addq $0x8, %r13
jmp 0x3139
cmpb $0x0, 0x14(%rsp)
je 0x32e6
leaq 0x48(%rsp), %rdi
leaq 0x118(%rsp), %rsi
leaq 0x198(%rsp), %rdx
movq 0x18(%rsp), %rcx
callq 0x2b27
movq 0x48(%rsp), %r14
movq 0x50(%rsp), %r13
leaq 0x98(%rsp), %r15
leaq 0x60(%rsp), %r12
cmpq %r13, %r14
je 0x32dc
movq %r15, %rdi
movq %r14, %rsi
callq 0x4568
movq %r15, %rdi
callq 0x41d8
testb %al, %al
jne 0x32ce
movq %r12, %rdi
movq %r15, %rsi
callq 0x45c2
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2210
movq %r12, %rdi
callq 0x20e0
movq %r15, %rdi
callq 0x421e
subq $-0x80, %r14
jmp 0x3294
leaq 0x48(%rsp), %rdi
callq 0x4242
leaq 0x118(%rsp), %rdi
callq 0x3fc6
leaq 0x198(%rsp), %rdi
callq 0x3fc6
leaq 0x80(%rsp), %rdi
callq 0x6c1c
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3370
movq %rax, %rbx
jmp 0x33a3
movq %rax, %rbx
jmp 0x33b0
jmp 0x3344
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x20e0
jmp 0x3347
movq %rax, %rbx
jmp 0x3354
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x421e
leaq 0x48(%rsp), %rdi
callq 0x4242
jmp 0x3396
jmp 0x3389
jmp 0x3389
jmp 0x3375
jmp 0x3389
jmp 0x3389
jmp 0x3375
jmp 0x3370
jmp 0x3375
movq %rax, %rbx
jmp 0x3396
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x20e0
jmp 0x338c
jmp 0x3389
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x3bf6
leaq 0x118(%rsp), %rdi
callq 0x3fc6
leaq 0x198(%rsp), %rdi
callq 0x3fc6
leaq 0x80(%rsp), %rdi
callq 0x6c1c
movq %rbx, %rdi
callq 0x2350