// File: BUSEC[P]RPKI_Downgrade_Detector/cli.cpp
// Function: main
int main(int argc, char* argv[]){

	bool U2I = false;

	if (argc == 5 ){ 
		if( string(argv[1]) == "-U2I" ){
			U2I = true;
		} else{
			cout<<"detector <old file> <new file> <outputfile>"<<endl; return 0; 
		}	
	} else if (argc != 4){ cout<<"detector <old file> <new file> <outputfile>"<<endl; return 0; }

	string oldFilepath = string(argv[1]);
	string newFilepath = string(argv[2]);
	string outputFilepath = string(argv[3]);

	vector<ROA*> oldROAs;
	vector<ROA*> newROAs;

	int success = readScanROAFile(&oldROAs, &oldFilepath);
	if (!success) { return 1; cout<<"Failed to load old roas :"<<oldFilepath<<endl;}

	success = readScanROAFile(&newROAs, &newFilepath);
	if (!success) { return 1; cout<<"Failed to load new roas :"<<newFilepath<<endl;}
	
	ofstream outputFile(outputFilepath.c_str());

	OutputDowngrades(&oldROAs, &newROAs, &outputFile, U2I);

	cout<<"finished sucessfully"<<endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x370, %rsp            # imm = 0x370
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
cmpl $0x5, -0x8(%rbp)
jne 0x56bc
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x310(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x308(%rbp)
callq 0x3410
movq -0x310(%rbp), %rsi
movq -0x308(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x7db0
jmp 0x561f
leaq 0xeb0d(%rip), %rsi      # 0x14133
leaq -0x38(%rbp), %rdi
callq 0x7f80
movb %al, -0x311(%rbp)
jmp 0x5637
leaq -0x38(%rbp), %rdi
callq 0x3170
leaq -0x39(%rbp), %rdi
callq 0x32c0
movb -0x311(%rbp), %al
testb $0x1, %al
jne 0x5655
jmp 0x568c
movb $0x1, -0x11(%rbp)
jmp 0x56ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x567e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3170
leaq -0x39(%rbp), %rdi
callq 0x32c0
jmp 0x59f6
movq 0x18945(%rip), %rdi     # 0x1dfd8
leaq 0xea9e(%rip), %rsi      # 0x14138
callq 0x3260
movq %rax, %rdi
movq 0x1891f(%rip), %rsi     # 0x1dfc8
callq 0x32a0
movl $0x0, -0x4(%rbp)
jmp 0x5999
jmp 0x56f2
cmpl $0x4, -0x8(%rbp)
je 0x56f0
movq 0x1890f(%rip), %rdi     # 0x1dfd8
leaq 0xea68(%rip), %rsi      # 0x14138
callq 0x3260
movq %rax, %rdi
movq 0x188e9(%rip), %rsi     # 0x1dfc8
callq 0x32a0
movl $0x0, -0x4(%rbp)
jmp 0x5999
jmp 0x56f2
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x328(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0x320(%rbp)
callq 0x3410
movq -0x328(%rbp), %rsi
movq -0x320(%rbp), %rdx
leaq -0x70(%rbp), %rdi
callq 0x7db0
jmp 0x572a
leaq -0x71(%rbp), %rdi
callq 0x32c0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x338(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x330(%rbp)
callq 0x3410
movq -0x338(%rbp), %rsi
movq -0x330(%rbp), %rdx
leaq -0x98(%rbp), %rdi
callq 0x7db0
jmp 0x5771
leaq -0x99(%rbp), %rdi
callq 0x32c0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x348(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x340(%rbp)
callq 0x3410
movq -0x348(%rbp), %rsi
movq -0x340(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x7db0
jmp 0x57bb
leaq -0xc1(%rbp), %rdi
callq 0x32c0
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x358(%rbp)
callq 0x6ae0
leaq -0xf8(%rbp), %rdi
callq 0x6ae0
movq -0x358(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4ff0
movl %eax, -0x34c(%rbp)
jmp 0x57fe
movl -0x34c(%rbp), %eax
movl %eax, -0xfc(%rbp)
cmpl $0x0, -0xfc(%rbp)
jne 0x588e
movl $0x1, -0x4(%rbp)
movl $0x1, -0x100(%rbp)
jmp 0x5960
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x71(%rbp), %rdi
callq 0x32c0
jmp 0x59f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x99(%rbp), %rdi
callq 0x32c0
jmp 0x59ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xc1(%rbp), %rdi
callq 0x32c0
jmp 0x59e1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x59bd
leaq -0xf8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x4ff0
movl %eax, -0x35c(%rbp)
jmp 0x58a9
movl -0x35c(%rbp), %eax
movl %eax, -0xfc(%rbp)
cmpl $0x0, -0xfc(%rbp)
jne 0x58d4
movl $0x1, -0x4(%rbp)
movl $0x1, -0x100(%rbp)
jmp 0x5960
leaq -0xc0(%rbp), %rdi
callq 0x30e0
movq %rax, %rsi
leaq -0x300(%rbp), %rdi
movl $0x10, %edx
callq 0x32d0
jmp 0x58f6
movzbl -0x11(%rbp), %ecx
andl $0x1, %ecx
leaq -0xe0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
leaq -0x300(%rbp), %rdx
callq 0x47e0
jmp 0x5919
movq 0x186b8(%rip), %rdi     # 0x1dfd8
leaq 0xe83d(%rip), %rsi      # 0x14164
callq 0x3260
movq %rax, -0x368(%rbp)
jmp 0x5935
movq -0x368(%rbp), %rdi
movq 0x18685(%rip), %rsi     # 0x1dfc8
callq 0x32a0
jmp 0x594a
leaq -0x300(%rbp), %rdi
callq 0x3390
movl $0x0, -0x100(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x7120
leaq -0xe0(%rbp), %rdi
callq 0x7120
leaq -0xc0(%rbp), %rdi
callq 0x3170
leaq -0x98(%rbp), %rdi
callq 0x3170
leaq -0x70(%rbp), %rdi
callq 0x3170
movl -0x4(%rbp), %eax
addq $0x370, %rsp            # imm = 0x370
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x300(%rbp), %rdi
callq 0x3390
leaq -0xf8(%rbp), %rdi
callq 0x7120
leaq -0xe0(%rbp), %rdi
callq 0x7120
leaq -0xc0(%rbp), %rdi
callq 0x3170
leaq -0x98(%rbp), %rdi
callq 0x3170
leaq -0x70(%rbp), %rdi
callq 0x3170
movq -0x48(%rbp), %rdi
callq 0x3400
nop