// File: 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
movq %rsp, %rbp
subq $0x3a0, %rsp            # imm = 0x3A0
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x7260
movq -0x8(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
callq 0x7280
jmp 0x4819
movq -0x10(%rbp), %rsi
leaq -0x148(%rbp), %rdi
callq 0x7280
jmp 0x482b
movq -0x8(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rdi
callq 0x6b20
movq %rax, -0x158(%rbp)
movq -0x150(%rbp), %rdi
callq 0x6b50
movq %rax, -0x160(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x6b80
testb $0x1, %al
jne 0x4878
jmp 0x4b4d
leaq -0x158(%rbp), %rdi
callq 0x6bc0
movq (%rax), %rax
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rdi
callq 0x5b50
movl %eax, -0x334(%rbp)
jmp 0x48a2
movl -0x334(%rbp), %eax
movl %eax, -0x16c(%rbp)
movq -0x168(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0x5b70
jmp 0x48c3
movq -0x168(%rbp), %rdi
callq 0x5ba0
movl %eax, -0x338(%rbp)
jmp 0x48d7
movl -0x338(%rbp), %edx
leaq -0x188(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x7350
jmp 0x48f2
movq -0x168(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0x5b70
jmp 0x4907
movq -0x168(%rbp), %rdi
callq 0x5ba0
movl %eax, -0x33c(%rbp)
jmp 0x491b
movl -0x33c(%rbp), %edx
leaq -0x188(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x6570
jmp 0x4936
movl -0x16c(%rbp), %edx
leaq -0x148(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x3bd0
jmp 0x4951
leaq -0x188(%rbp), %rdi
callq 0x62a0
movb %al, -0x33d(%rbp)
jmp 0x4965
movb -0x33d(%rbp), %al
testb $0x1, %al
jne 0x4b1f
jmp 0x4975
movq -0x18(%rbp), %rdi
leaq 0xf9a5(%rip), %rsi      # 0x14325
callq 0x3260
jmp 0x4987
movq -0x18(%rbp), %rdi
leaq 0xf71d(%rip), %rsi      # 0x140af
callq 0x3260
jmp 0x4999
movq -0x18(%rbp), %rdi
leaq 0xf71d(%rip), %rsi      # 0x140c1
callq 0x3260
movq %rax, -0x348(%rbp)
jmp 0x49b2
movq -0x168(%rbp), %rsi
leaq -0x1b8(%rbp), %rdi
callq 0x7390
jmp 0x49c7
movq -0x348(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x3230
movq %rax, -0x350(%rbp)
jmp 0x49e3
movq -0x350(%rbp), %rdi
leaq 0xf928(%rip), %rsi      # 0x14319
callq 0x3260
jmp 0x49f8
leaq -0x1b8(%rbp), %rdi
callq 0x3170
movq -0x18(%rbp), %rdi
leaq 0xf6b9(%rip), %rsi      # 0x140c8
callq 0x3260
movq %rax, -0x358(%rbp)
jmp 0x4a1d
leaq -0x1d8(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x75f0
jmp 0x4a32
movq -0x358(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x3230
jmp 0x4a47
leaq -0x1d8(%rbp), %rdi
callq 0x3170
movq -0x18(%rbp), %rdi
leaq 0xf5c8(%rip), %rsi      # 0x14026
callq 0x3260
movq %rax, -0x360(%rbp)
jmp 0x4a6c
movq -0x360(%rbp), %rdi
movq 0x1954e(%rip), %rsi     # 0x1dfc8
callq 0x32a0
jmp 0x4a81
jmp 0x4b1f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x4fd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x4fc4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x4fb8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x4b3c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x3170
jmp 0x4b3c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x3170
jmp 0x4b3c
leaq -0x188(%rbp), %rdi
callq 0x61e0
leaq -0x158(%rbp), %rdi
callq 0x6da0
jmp 0x485c
leaq -0x188(%rbp), %rdi
callq 0x61e0
jmp 0x4fb8
movq -0x8(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movq -0x1e0(%rbp), %rdi
callq 0x6b20
movq %rax, -0x1e8(%rbp)
movq -0x1e0(%rbp), %rdi
callq 0x6b50
movq %rax, -0x1f0(%rbp)
leaq -0x1e8(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0x6b80
testb $0x1, %al
jne 0x4b9a
jmp 0x4e01
leaq -0x1e8(%rbp), %rdi
callq 0x6bc0
movq (%rax), %rax
movq %rax, -0x1f8(%rbp)
movq -0x1f8(%rbp), %rsi
leaq -0x218(%rbp), %rdi
callq 0x5b70
jmp 0x4bc5
movq -0x1f8(%rbp), %rdi
callq 0x5ba0
movl %eax, -0x364(%rbp)
jmp 0x4bd9
movl -0x364(%rbp), %edx
leaq -0x210(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x7350
jmp 0x4bf4
movq -0x1f8(%rbp), %rsi
leaq -0x220(%rbp), %rdi
callq 0x5b70
jmp 0x4c09
movq -0x1f8(%rbp), %rdi
callq 0x5ba0
movl %eax, -0x368(%rbp)
jmp 0x4c1d
movl -0x368(%rbp), %edx
leaq -0x210(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x6570
jmp 0x4c38
leaq -0x148(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x3b90
jmp 0x4c4d
leaq -0x210(%rbp), %rdi
callq 0x62a0
movb %al, -0x369(%rbp)
jmp 0x4c61
movb -0x369(%rbp), %al
testb $0x1, %al
jne 0x4dd3
jmp 0x4c71
movq -0x18(%rbp), %rdi
leaq 0xf6a9(%rip), %rsi      # 0x14325
callq 0x3260
jmp 0x4c83
movq -0x18(%rbp), %rdi
leaq 0xf444(%rip), %rsi      # 0x140d2
callq 0x3260
jmp 0x4c95
movq -0x18(%rbp), %rdi
leaq 0xf421(%rip), %rsi      # 0x140c1
callq 0x3260
movq %rax, -0x378(%rbp)
jmp 0x4cae
movq -0x1f8(%rbp), %rsi
leaq -0x240(%rbp), %rdi
callq 0x7390
jmp 0x4cc3
movq -0x378(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x3230
movq %rax, -0x380(%rbp)
jmp 0x4cdf
movq -0x380(%rbp), %rdi
leaq 0xf62c(%rip), %rsi      # 0x14319
callq 0x3260
jmp 0x4cf4
leaq -0x240(%rbp), %rdi
callq 0x3170
movq -0x18(%rbp), %rdi
leaq 0xf3bd(%rip), %rsi      # 0x140c8
callq 0x3260
movq %rax, -0x388(%rbp)
jmp 0x4d19
leaq -0x260(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x75f0
jmp 0x4d2e
movq -0x388(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x3230
jmp 0x4d43
leaq -0x260(%rbp), %rdi
callq 0x3170
movq -0x18(%rbp), %rdi
leaq 0xf2cc(%rip), %rsi      # 0x14026
callq 0x3260
movq %rax, -0x390(%rbp)
jmp 0x4d68
movq -0x390(%rbp), %rdi
movq 0x19252(%rip), %rsi     # 0x1dfc8
callq 0x32a0
jmp 0x4d7d
jmp 0x4dd3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x4df0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x3170
jmp 0x4df0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x3170
jmp 0x4df0
leaq -0x210(%rbp), %rdi
callq 0x61e0
leaq -0x1e8(%rbp), %rdi
callq 0x6da0
jmp 0x4b7e
leaq -0x210(%rbp), %rdi
callq 0x61e0
jmp 0x4fb8
testb $0x1, -0x19(%rbp)
je 0x4f8e
movq -0x10(%rbp), %rcx
leaq -0x278(%rbp), %rdi
leaq -0x148(%rbp), %rsi
leaq -0xb8(%rbp), %rdx
callq 0x3fe0
jmp 0x4e2b
leaq -0x278(%rbp), %rax
movq %rax, -0x280(%rbp)
movq -0x280(%rbp), %rdi
callq 0x77c0
movq %rax, -0x288(%rbp)
movq -0x280(%rbp), %rdi
callq 0x77f0
movq %rax, -0x290(%rbp)
leaq -0x288(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x7820
testb $0x1, %al
jne 0x4e7b
jmp 0x4f72
leaq -0x288(%rbp), %rdi
callq 0x7860
movq %rax, %rsi
leaq -0x310(%rbp), %rdi
callq 0x7880
jmp 0x4e98
leaq -0x310(%rbp), %rdi
callq 0x6fe0
movb %al, -0x391(%rbp)
jmp 0x4eac
movb -0x391(%rbp), %al
testb $0x1, %al
jne 0x4f47
jmp 0x4ebc
movq -0x18(%rbp), %rax
movq %rax, -0x3a0(%rbp)
leaq -0x330(%rbp), %rdi
leaq -0x310(%rbp), %rsi
callq 0x7920
jmp 0x4edc
movq -0x3a0(%rbp), %rdi
leaq -0x330(%rbp), %rsi
callq 0x3230
jmp 0x4ef1
leaq -0x330(%rbp), %rdi
callq 0x3170
jmp 0x4f47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x4f80
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
jmp 0x4f64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
leaq -0x330(%rbp), %rdi
callq 0x3170
jmp 0x4f64
leaq -0x310(%rbp), %rdi
callq 0x70a0
leaq -0x288(%rbp), %rdi
callq 0x7d00
jmp 0x4e5f
leaq -0x310(%rbp), %rdi
callq 0x70a0
jmp 0x4f80
leaq -0x278(%rbp), %rdi
callq 0x7200
jmp 0x4f8e
leaq -0x278(%rbp), %rdi
callq 0x7200
jmp 0x4fb8
leaq -0x148(%rbp), %rdi
callq 0x6960
leaq -0xb8(%rbp), %rdi
callq 0x6960
leaq -0x38(%rbp), %rdi
callq 0x7d20
addq $0x3a0, %rsp            # imm = 0x3A0
popq %rbp
retq
leaq -0x148(%rbp), %rdi
callq 0x6960
leaq -0xb8(%rbp), %rdi
callq 0x6960
leaq -0x38(%rbp), %rdi
callq 0x7d20
movq -0xc0(%rbp), %rdi
callq 0x3400
nopw %cs:(%rax,%rax)