// File: NinjaDevelper[P]ReedSolomon/cxx/main.cpp
// Function: main
int main(int argc,char *argv[]){
    ReedSolomon rs;
 
    int fin=open(argv[2],O_RDONLY);
    long size=lseek(fin,0,SEEK_END);
    lseek(fin,0,SEEK_SET);
    close(fin);

    if(argv[1][0]=='e'){
        rs.encodeFile(argv[2],"encoded.dat",200,208);
    }
    if(argv[1][0]=='m'){
        if(size>500000+1024*300){
            //embed sequential error
	    fin=open("encoded.dat",O_RDWR);
	    lseek(fin,FROM,SEEK_END);
	    char buf[1024]={};
	    for(int i=0;i<COUNT;i++){
	        write(fin,buf,1024);
	    }
	    close(fin);
        }
    }
    if(argv[1][0]=='d'){
	vector<long> loc;
	for(int i=0;i<COUNT*1024;i++){
	    loc.push_back(i+500000);
    	}
        rs.decodeFile("encoded.dat","recovered.dat",200,208,size,loc);
    }
    return 0;
}

// Assembly:
subq $0x838, %rsp            # imm = 0x838
movl $0x0, 0x834(%rsp)
movl %edi, 0x830(%rsp)
movq %rsi, 0x828(%rsp)
leaq 0x528(%rsp), %rdi
callq 0x2400
movq 0x828(%rsp), %rax
movq 0x10(%rax), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x2140
movl %eax, 0x524(%rsp)
movl 0x524(%rsp), %edi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x22c0
movq %rax, 0x518(%rsp)
movl 0x524(%rsp), %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x22c0
movl 0x524(%rsp), %edi
callq 0x22e0
movq 0x828(%rsp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x65, %eax
jne 0x662f
movq 0x828(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x20(%rsp)
leaq 0x4f7(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x2290
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0x4f8(%rsp), %rdi
callq 0x68e0
jmp 0x6529
leaq 0x4bf(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x2290
movq 0x18(%rsp), %rdx
leaq 0x1b29(%rip), %rsi      # 0x8070
leaq 0x4c0(%rsp), %rdi
callq 0x68e0
jmp 0x6556
leaq 0x528(%rsp), %rdi
leaq 0x4f8(%rsp), %rsi
leaq 0x4c0(%rsp), %rdx
movl $0xc8, %ecx
movl $0xd0, %r8d
callq 0x37a0
jmp 0x6580
leaq 0x4c0(%rsp), %rdi
callq 0x20f0
leaq 0x4bf(%rsp), %rdi
callq 0x21d0
leaq 0x4f8(%rsp), %rdi
callq 0x20f0
leaq 0x4f7(%rsp), %rdi
callq 0x21d0
jmp 0x662f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4e8(%rsp)
movl %eax, 0x4e4(%rsp)
jmp 0x661d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4e8(%rsp)
movl %eax, 0x4e4(%rsp)
jmp 0x6603
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4e8(%rsp)
movl %eax, 0x4e4(%rsp)
leaq 0x4c0(%rsp), %rdi
callq 0x20f0
leaq 0x4bf(%rsp), %rdi
callq 0x21d0
leaq 0x4f8(%rsp), %rdi
callq 0x20f0
leaq 0x4f7(%rsp), %rdi
callq 0x21d0
jmp 0x68c7
movq 0x828(%rsp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x6d, %eax
jne 0x66ef
cmpq $0xc5120, 0x518(%rsp) # imm = 0xC5120
jle 0x66ed
leaq 0x1a10(%rip), %rdi      # 0x8070
movl $0x2, %esi
movb $0x0, %al
callq 0x2140
movl %eax, 0x524(%rsp)
movl 0x524(%rsp), %edi
movl $0x7a120, %esi          # imm = 0x7A120
movl $0x2, %edx
callq 0x22c0
leaq 0xb0(%rsp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x20d0
movl $0x0, 0xac(%rsp)
cmpl $0x12c, 0xac(%rsp) # imm = 0x12C
jge 0x66e1
movl 0x524(%rsp), %edi
leaq 0xb0(%rsp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x2070
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x66a8
movl 0x524(%rsp), %edi
callq 0x22e0
jmp 0x66ef
movq 0x828(%rsp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x64, %eax
jne 0x68bd
leaq 0x90(%rsp), %rdi
callq 0x69a0
movl $0x0, 0x8c(%rsp)
cmpl $0x4b000, 0x8c(%rsp) # imm = 0x4B000
jge 0x6787
movl 0x8c(%rsp), %eax
addl $0x7a120, %eax          # imm = 0x7A120
cltq
movq %rax, 0x80(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x69b0
jmp 0x6759
jmp 0x675b
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0x671f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4e8(%rsp)
movl %eax, 0x4e4(%rsp)
jmp 0x68ae
leaq 0x5f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x2290
movq 0x10(%rsp), %rdx
leaq 0x18ce(%rip), %rsi      # 0x8070
leaq 0x60(%rsp), %rdi
callq 0x68e0
jmp 0x67ae
leaq 0x37(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x2290
movq 0x8(%rsp), %rdx
leaq 0x18b3(%rip), %rsi      # 0x807c
leaq 0x38(%rsp), %rdi
callq 0x68e0
jmp 0x67d5
movq 0x518(%rsp), %r9
movq %rsp, %rax
leaq 0x90(%rsp), %rcx
movq %rcx, (%rax)
leaq 0x528(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movl $0xc8, %ecx
movl $0xd0, %r8d
callq 0x3030
jmp 0x680f
leaq 0x38(%rsp), %rdi
callq 0x20f0
leaq 0x37(%rsp), %rdi
callq 0x21d0
leaq 0x60(%rsp), %rdi
callq 0x20f0
leaq 0x5f(%rsp), %rdi
callq 0x21d0
leaq 0x90(%rsp), %rdi
callq 0x69e0
jmp 0x68bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4e8(%rsp)
movl %eax, 0x4e4(%rsp)
jmp 0x68a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4e8(%rsp)
movl %eax, 0x4e4(%rsp)
jmp 0x6890
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4e8(%rsp)
movl %eax, 0x4e4(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x20f0
leaq 0x37(%rsp), %rdi
callq 0x21d0
leaq 0x60(%rsp), %rdi
callq 0x20f0
leaq 0x5f(%rsp), %rdi
callq 0x21d0
leaq 0x90(%rsp), %rdi
callq 0x69e0
jmp 0x68c7
xorl %eax, %eax
addq $0x838, %rsp            # imm = 0x838
retq
movq 0x4e8(%rsp), %rdi
callq 0x2280
nopw %cs:(%rax,%rax)
nop