// File: MITRECND[P]snugglefish/src/snugglefish.cpp
// Function: main
int main(int argc, char *argv[]){
    int c, option_index = 0;
    uint32_t ngramSize = 3;
    uint32_t max_files = 0;
    uint64_t max_buffer = 0;
    uint32_t threads = 0;

    signal(SIGSEGV, handler); 

    string commandString, indexFileName = "", searchString;
    vector <string> fileList;
    static struct option long_options[] ={
        // Ngramsize defaults to 3 if not present
        {INDEX_OPTION_LONG, no_argument, 0, INDEX_OPTION_SHORT},
        {SEARCH_OPTION_LONG, no_argument, 0, SEARCH_OPTION_SHORT},
        {FILE_OPTION_LONG, required_argument, 0, FILE_OPTION_SHORT},
        {OUTPUT_OPTION_LONG, required_argument, 0, OUTPUT_OPTION_SHORT},
        {NGRAM_SIZE_OPTION_LONG, required_argument, 0, NGRAM_SIZE_OPTION_SHORT},
        {HELP_OPTION_LONG, no_argument, 0, HELP_OPTION_SHORT},
        {THREADS_OPTION_LONG, required_argument, 0, THREADS_OPTION_SHORT},
        {0,0,0,0}
    };
    bool indexFlag = false, searchFlag = false;

    // Default threads to the number of cpus
    threads = cpu_count();

    // loop over all of the options
    while ((c = getopt_long(argc, argv, SHORT_OPTIONS_STRING, long_options, &option_index)) != -1){
        // check to see if a single character or long option came through
        switch (c){
            // short option 't'
            case THREADS_OPTION_SHORT:
                {
                    istringstream tss(optarg);
                    uint32_t thr = 0;

                    if(!(tss >> thr)){
                        cout << "Invalid number of threads, please enter an integer" << endl;
                        return 0;
                    }else{
                        threads = thr;
                    }

                    break;
                }
            case SEARCH_OPTION_SHORT:
                searchFlag = true;
                break;
            case INDEX_OPTION_SHORT:
                indexFlag = true;
                break;
                // Outpur and file options are the same
            case OUTPUT_OPTION_SHORT:
            case FILE_OPTION_SHORT:
                indexFileName = optarg;
                break;
            case HELP_OPTION_SHORT:
                printHelp();
                return 0;
                // short option 'a'
            case NGRAM_SIZE_OPTION_SHORT:
                {
                    //string ngramSizeString(optarg);
                    istringstream ss(optarg);
                    //stringstream ss;
                    //ss << ngramSizeString;
                    if(!(ss >> ngramSize)){
                        cout << "Invalid ngram size, please enter an integer" << endl;
                        return 0;
                    }
                    if(ngramSize < 3 || ngramSize > 4){
                        cout << "Ngram size must be 3 or 4. Ngram size is " << ngramSize << endl;
                        return 0;
                    }
                    break;
                }

            case NODE_BUFFER_OPTION_SHORT:
                {
                    istringstream ss(optarg);
                    uint64_t tmax_buffer = 0;
                    if(!(ss >> tmax_buffer)){
                        cout << "Invalid maxmimum node buffer, please enter an integer" << endl;
                        return 0;
                    }

                    if(tmax_buffer < 4){
                        cout << "Node buffer size must be at least 4GB in size" << endl;
                        return 0;
                    }
            
                    max_buffer = tmax_buffer * 1073741824; //in Gigabytes 
                    break;
                }
                    
        }
    }
    /* the rest of the command line arguments 
     * each option needs at least an aditional parameter*/
    if((!indexFlag && !searchFlag)){
        cout << "Must specify -i for index or -s for search" << endl;
        return 0;
    }

    if((indexFlag && searchFlag)){
        cout << "Must specify only one of -i or -s" << endl;
        return 0;

    }
    if(indexFileName.empty()){
        cout << "Index file necessary" << endl;
        return 0;
    }


    if(indexFlag){
        // get the list of files to add

        for(; optind < argc; optind++){
            fileList.push_back(argv[optind]);
        }
        // if fileList is empty, it means we need to get the
        // filenames from stdin
        if(fileList.empty()){
            string fileName;
            while(cin){
                getline(cin,fileName);
                if(fileName.empty())
                    break;
                fileList.push_back(fileName);
            }
        }
        //Eventually options should be sent as a structure
        make_index(indexFileName, fileList, ngramSize, max_files, max_buffer, threads);
    } else if(searchFlag) {
        // Get the string to search for
		if (optind < argc) {
			searchString = argv[optind];
		} else {
			cin >> searchString;
		}
	    if (searchString.size() < ngramSize){
	        cout << "Search string size is smaller than Ngram size, the search string must be greater than or equal to the ngram size" << endl;
	    } else {
			vector<string>* found = search(indexFileName, searchString, ngramSize, threads);
			for(uint32_t i = 0; i < found->size(); i++){
       			cout << (*found)[i] << endl;
   			}
            delete found;
		}
    } else{
        printHelp();
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x7a0, %rsp            # imm = 0x7A0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x3, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
leaq -0xa4(%rip), %rsi       # 0xe9c0
movl $0xb, %edi
callq 0xe3a0
leaq -0x50(%rbp), %rdi
callq 0xe470
leaq -0x71(%rbp), %rdi
movq %rdi, -0x6a8(%rbp)
callq 0xe5e0
movq -0x6a8(%rbp), %rdx
leaq 0xb631(%rip), %rsi      # 0x1a0c6
leaq -0x70(%rbp), %rdi
callq 0x102a0
jmp 0xeaa0
leaq -0x71(%rbp), %rdi
callq 0xe360
leaq -0xa8(%rbp), %rdi
callq 0xe470
leaq -0xc0(%rbp), %rdi
callq 0x10350
movb $0x0, -0xc1(%rbp)
movb $0x0, -0xc2(%rbp)
callq 0xe940
movl %eax, -0x6ac(%rbp)
jmp 0xeadc
movl -0x6ac(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0xb5f2(%rip), %rdx      # 0x1a0e5
leaq 0x12856(%rip), %rcx     # 0x21350
leaq -0x18(%rbp), %r8
callq 0xe560
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0xf138
movl -0x14(%rbp), %eax
addl $-0x62, %eax
movl %eax, %ecx
movq %rcx, -0x6b8(%rbp)
subl $0x12, %eax
ja 0xf133
movq -0x6b8(%rbp), %rax
leaq 0xb4cf(%rip), %rcx      # 0x1a004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x71(%rbp), %rdi
callq 0xe360
jmp 0xf707
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xf6e6
movq 0x12422(%rip), %rax     # 0x20f98
movq (%rax), %rax
movq %rax, -0x6c8(%rbp)
leaq -0x269(%rbp), %rdi
movq %rdi, -0x6c0(%rbp)
callq 0xe5e0
movq -0x6c8(%rbp), %rsi
movq -0x6c0(%rbp), %rdx
leaq -0x268(%rbp), %rdi
callq 0x102a0
jmp 0xebaf
leaq -0x248(%rbp), %rdi
leaq -0x268(%rbp), %rsi
movl $0x8, %edx
callq 0xe590
jmp 0xebc9
leaq -0x268(%rbp), %rdi
callq 0xe1d0
leaq -0x269(%rbp), %rdi
callq 0xe360
movl $0x0, -0x270(%rbp)
leaq -0x248(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0xe070
movq %rax, -0x6d0(%rbp)
jmp 0xec07
movq -0x6d0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xe150
movb %al, -0x6d1(%rbp)
jmp 0xec25
movb -0x6d1(%rbp), %al
testb $0x1, %al
jne 0xec34
jmp 0xecd5
movq 0x12375(%rip), %rdi     # 0x20fb0
leaq 0xb4b1(%rip), %rsi      # 0x1a0f3
callq 0xe2f0
movq %rax, -0x6e0(%rbp)
jmp 0xec50
movq -0x6e0(%rbp), %rdi
movq 0x12332(%rip), %rsi     # 0x20f90
callq 0xe340
jmp 0xec65
movl $0x0, -0x4(%rbp)
movl $0x1, -0x274(%rbp)
jmp 0xece8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xeca4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x268(%rbp), %rdi
callq 0xe1d0
leaq -0x269(%rbp), %rdi
callq 0xe360
jmp 0xf6e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x248(%rbp), %rdi
callq 0xe160
jmp 0xf6e6
movl -0x270(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl $0x4, -0x274(%rbp)
leaq -0x248(%rbp), %rdi
callq 0xe160
movl -0x274(%rbp), %eax
subl $0x4, %eax
je 0xf133
jmp 0xf6b0
movb $0x1, -0xc2(%rbp)
jmp 0xf133
movb $0x1, -0xc1(%rbp)
jmp 0xf133
movq 0x12271(%rip), %rax     # 0x20f98
movq (%rax), %rsi
leaq -0x70(%rbp), %rdi
callq 0xe460
jmp 0xed35
jmp 0xf133
callq 0xf720
jmp 0xed41
movl $0x0, -0x4(%rbp)
movl $0x1, -0x274(%rbp)
jmp 0xf6b0
movq 0x1223a(%rip), %rax     # 0x20f98
movq (%rax), %rax
movq %rax, -0x6f0(%rbp)
leaq -0x419(%rbp), %rdi
movq %rdi, -0x6e8(%rbp)
callq 0xe5e0
movq -0x6f0(%rbp), %rsi
movq -0x6e8(%rbp), %rdx
leaq -0x418(%rbp), %rdi
callq 0x102a0
jmp 0xed97
leaq -0x3f8(%rbp), %rdi
leaq -0x418(%rbp), %rsi
movl $0x8, %edx
callq 0xe590
jmp 0xedb1
leaq -0x418(%rbp), %rdi
callq 0xe1d0
leaq -0x419(%rbp), %rdi
callq 0xe360
leaq -0x3f8(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0xe070
movq %rax, -0x6f8(%rbp)
jmp 0xede2
movq -0x6f8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xe150
movb %al, -0x6f9(%rbp)
jmp 0xee00
movb -0x6f9(%rbp), %al
testb $0x1, %al
jne 0xee0f
jmp 0xeeb3
movq 0x1219a(%rip), %rdi     # 0x20fb0
leaq 0xb309(%rip), %rsi      # 0x1a126
callq 0xe2f0
movq %rax, -0x708(%rbp)
jmp 0xee2b
movq -0x708(%rbp), %rdi
movq 0x12157(%rip), %rsi     # 0x20f90
callq 0xe340
jmp 0xee40
movl $0x0, -0x4(%rbp)
movl $0x1, -0x274(%rbp)
jmp 0xef25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xee82
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x418(%rbp), %rdi
callq 0xe1d0
leaq -0x419(%rbp), %rdi
callq 0xe360
jmp 0xf6e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x3f8(%rbp), %rdi
callq 0xe160
jmp 0xf6e6
cmpl $0x3, -0x1c(%rbp)
jb 0xeebf
cmpl $0x4, -0x1c(%rbp)
jbe 0xef1b
movq 0x120ea(%rip), %rdi     # 0x20fb0
leaq 0xb285(%rip), %rsi      # 0x1a152
callq 0xe2f0
movq %rax, -0x710(%rbp)
jmp 0xeedb
movq -0x710(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0xe450
movq %rax, -0x718(%rbp)
jmp 0xeef3
movq -0x718(%rbp), %rdi
movq 0x1208f(%rip), %rsi     # 0x20f90
callq 0xe340
jmp 0xef08
movl $0x0, -0x4(%rbp)
movl $0x1, -0x274(%rbp)
jmp 0xef25
movl $0x4, -0x274(%rbp)
leaq -0x3f8(%rbp), %rdi
callq 0xe160
movl -0x274(%rbp), %eax
subl $0x4, %eax
je 0xf133
jmp 0xf6b0
movq 0x1204c(%rip), %rax     # 0x20f98
movq (%rax), %rax
movq %rax, -0x728(%rbp)
leaq -0x5c1(%rbp), %rdi
movq %rdi, -0x720(%rbp)
callq 0xe5e0
movq -0x728(%rbp), %rsi
movq -0x720(%rbp), %rdx
leaq -0x5c0(%rbp), %rdi
callq 0x102a0
jmp 0xef85
leaq -0x5a0(%rbp), %rdi
leaq -0x5c0(%rbp), %rsi
movl $0x8, %edx
callq 0xe590
jmp 0xef9f
leaq -0x5c0(%rbp), %rdi
callq 0xe1d0
leaq -0x5c1(%rbp), %rdi
callq 0xe360
movq $0x0, -0x5d0(%rbp)
leaq -0x5a0(%rbp), %rdi
leaq -0x5d0(%rbp), %rsi
callq 0xe480
movq %rax, -0x730(%rbp)
jmp 0xefde
movq -0x730(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xe150
movb %al, -0x731(%rbp)
jmp 0xeffc
movb -0x731(%rbp), %al
testb $0x1, %al
jne 0xf00b
jmp 0xf0af
movq 0x11f9e(%rip), %rdi     # 0x20fb0
leaq 0xb163(%rip), %rsi      # 0x1a17c
callq 0xe2f0
movq %rax, -0x740(%rbp)
jmp 0xf027
movq -0x740(%rbp), %rdi
movq 0x11f5b(%rip), %rsi     # 0x20f90
callq 0xe340
jmp 0xf03c
movl $0x0, -0x4(%rbp)
movl $0x1, -0x274(%rbp)
jmp 0xf116
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xf07e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x5c0(%rbp), %rdi
callq 0xe1d0
leaq -0x5c1(%rbp), %rdi
callq 0xe360
jmp 0xf6e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x5a0(%rbp), %rdi
callq 0xe160
jmp 0xf6e6
cmpq $0x4, -0x5d0(%rbp)
jae 0xf0fd
movq 0x11ef0(%rip), %rdi     # 0x20fb0
leaq 0xb0eb(%rip), %rsi      # 0x1a1b2
callq 0xe2f0
movq %rax, -0x748(%rbp)
jmp 0xf0d5
movq -0x748(%rbp), %rdi
movq 0x11ead(%rip), %rsi     # 0x20f90
callq 0xe340
jmp 0xf0ea
movl $0x0, -0x4(%rbp)
movl $0x1, -0x274(%rbp)
jmp 0xf116
movq -0x5d0(%rbp), %rax
shlq $0x1e, %rax
movq %rax, -0x28(%rbp)
movl $0x4, -0x274(%rbp)
leaq -0x5a0(%rbp), %rdi
callq 0xe160
movl -0x274(%rbp), %eax
subl $0x4, %eax
jne 0xf6b0
jmp 0xf133
jmp 0xeae5
testb $0x1, -0xc1(%rbp)
jne 0xf191
testb $0x1, -0xc2(%rbp)
jne 0xf191
movq 0x11e5f(%rip), %rdi     # 0x20fb0
leaq 0xb088(%rip), %rsi      # 0x1a1e0
callq 0xe2f0
movq %rax, -0x750(%rbp)
jmp 0xf166
movq -0x750(%rbp), %rdi
movq 0x11e1c(%rip), %rsi     # 0x20f90
callq 0xe340
jmp 0xf17b
movl $0x0, -0x4(%rbp)
movl $0x1, -0x274(%rbp)
jmp 0xf6b0
testb $0x1, -0xc1(%rbp)
je 0xf1ea
testb $0x1, -0xc2(%rbp)
je 0xf1ea
movq 0x11e06(%rip), %rdi     # 0x20fb0
leaq 0xb05a(%rip), %rsi      # 0x1a20b
callq 0xe2f0
movq %rax, -0x758(%rbp)
jmp 0xf1bf
movq -0x758(%rbp), %rdi
movq 0x11dc3(%rip), %rsi     # 0x20f90
callq 0xe340
jmp 0xf1d4
movl $0x0, -0x4(%rbp)
movl $0x1, -0x274(%rbp)
jmp 0xf6b0
leaq -0x70(%rbp), %rdi
callq 0xe580
testb $0x1, %al
jne 0xf1f9
jmp 0xf240
movq 0x11db0(%rip), %rdi     # 0x20fb0
leaq 0xb026(%rip), %rsi      # 0x1a22d
callq 0xe2f0
movq %rax, -0x760(%rbp)
jmp 0xf215
movq -0x760(%rbp), %rdi
movq 0x11d6d(%rip), %rsi     # 0x20f90
callq 0xe340
jmp 0xf22a
movl $0x0, -0x4(%rbp)
movl $0x1, -0x274(%rbp)
jmp 0xf6b0
testb $0x1, -0xc1(%rbp)
je 0xf48b
jmp 0xf24f
movq 0x11d6a(%rip), %rax     # 0x20fc0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jge 0xf32d
movq -0x10(%rbp), %rax
movq 0x11d54(%rip), %rcx     # 0x20fc0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x770(%rbp)
leaq -0x5f1(%rbp), %rdi
movq %rdi, -0x768(%rbp)
callq 0xe5e0
movq -0x770(%rbp), %rsi
movq -0x768(%rbp), %rdx
leaq -0x5f0(%rbp), %rdi
callq 0x102a0
jmp 0xf2a9
leaq -0xc0(%rbp), %rdi
leaq -0x5f0(%rbp), %rsi
callq 0x10370
jmp 0xf2be
leaq -0x5f0(%rbp), %rdi
callq 0xe1d0
leaq -0x5f1(%rbp), %rdi
callq 0xe360
movq 0x11ce3(%rip), %rax     # 0x20fc0
movl (%rax), %ecx
addl $0x1, %ecx
movq 0x11cd7(%rip), %rax     # 0x20fc0
movl %ecx, (%rax)
jmp 0xf24f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xf31c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x5f0(%rbp), %rdi
callq 0xe1d0
leaq -0x5f1(%rbp), %rdi
callq 0xe360
jmp 0xf6e6
leaq -0xc0(%rbp), %rdi
callq 0x103a0
testb $0x1, %al
jne 0xf342
jmp 0xf3e7
leaq -0x618(%rbp), %rdi
callq 0xe470
movq 0x11c7b(%rip), %rdi     # 0x20fd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xe400
movb %al, -0x771(%rbp)
jmp 0xf36c
movb -0x771(%rbp), %al
testb $0x1, %al
jne 0xf378
jmp 0xf3db
movq 0x11c51(%rip), %rdi     # 0x20fd0
leaq -0x618(%rbp), %rsi
callq 0xe0a0
jmp 0xf38d
leaq -0x618(%rbp), %rdi
callq 0xe580
testb $0x1, %al
jne 0xf39f
jmp 0xf3c1
jmp 0xf3db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x618(%rbp), %rdi
callq 0xe1d0
jmp 0xf6e6
leaq -0xc0(%rbp), %rdi
leaq -0x618(%rbp), %rsi
callq 0x103e0
jmp 0xf3d6
jmp 0xf34e
leaq -0x618(%rbp), %rdi
callq 0xe1d0
leaq -0x638(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xe130
jmp 0xf3f9
leaq -0x650(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x10450
jmp 0xf40e
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movq -0x28(%rbp), %r8
movl -0x2c(%rbp), %r9d
leaq -0x638(%rbp), %rdi
leaq -0x650(%rbp), %rsi
callq 0xf930
jmp 0xf431
leaq -0x650(%rbp), %rdi
callq 0x10540
leaq -0x638(%rbp), %rdi
callq 0xe1d0
jmp 0xf69f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xf47a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x650(%rbp), %rdi
callq 0x10540
leaq -0x638(%rbp), %rdi
callq 0xe1d0
jmp 0xf6e6
testb $0x1, -0xc2(%rbp)
je 0xf694
movq 0x11b21(%rip), %rax     # 0x20fc0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jge 0xf4c8
movq -0x10(%rbp), %rax
movq 0x11b0f(%rip), %rcx     # 0x20fc0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0xa8(%rbp), %rdi
callq 0xe460
jmp 0xf4c6
jmp 0xf4df
movq 0x11b01(%rip), %rdi     # 0x20fd0
leaq -0xa8(%rbp), %rsi
callq 0xe410
jmp 0xf4dd
jmp 0xf4df
leaq -0xa8(%rbp), %rdi
callq 0xe210
movl -0x1c(%rbp), %ecx
cmpq %rcx, %rax
jae 0xf529
movq 0x11ab6(%rip), %rdi     # 0x20fb0
leaq 0xad41(%rip), %rsi      # 0x1a242
callq 0xe2f0
movq %rax, -0x780(%rbp)
jmp 0xf50f
movq -0x780(%rbp), %rdi
movq 0x11a73(%rip), %rsi     # 0x20f90
callq 0xe340
jmp 0xf524
jmp 0xf692
leaq -0x678(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xe130
jmp 0xf53b
leaq -0x698(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xe130
jmp 0xf550
movl -0x1c(%rbp), %edx
movl -0x2c(%rbp), %ecx
leaq -0x678(%rbp), %rdi
leaq -0x698(%rbp), %rsi
callq 0xfd30
movq %rax, -0x788(%rbp)
jmp 0xf572
leaq -0x698(%rbp), %rdi
callq 0xe1d0
leaq -0x678(%rbp), %rdi
callq 0xe1d0
movq -0x788(%rbp), %rax
movq %rax, -0x658(%rbp)
movl $0x0, -0x69c(%rbp)
movl -0x69c(%rbp), %eax
movq %rax, -0x790(%rbp)
movq -0x658(%rbp), %rdi
callq 0x105a0
movq %rax, %rcx
movq -0x790(%rbp), %rax
cmpq %rcx, %rax
jae 0xf65f
movq -0x658(%rbp), %rdi
movl -0x69c(%rbp), %eax
movl %eax, %esi
callq 0x105c0
movq %rax, %rsi
movq 0x119c4(%rip), %rdi     # 0x20fb0
callq 0xe2c0
movq %rax, -0x798(%rbp)
jmp 0xf5fa
movq -0x798(%rbp), %rdi
movq 0x11988(%rip), %rsi     # 0x20f90
callq 0xe340
jmp 0xf60f
jmp 0xf611
movl -0x69c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x69c(%rbp)
jmp 0xf5a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xf64e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x698(%rbp), %rdi
callq 0xe1d0
leaq -0x678(%rbp), %rdi
callq 0xe1d0
jmp 0xf6e6
movq -0x658(%rbp), %rax
movq %rax, -0x7a0(%rbp)
cmpq $0x0, %rax
je 0xf690
movq -0x7a0(%rbp), %rdi
callq 0x10540
movq -0x7a0(%rbp), %rdi
movl $0x18, %esi
callq 0xe310
jmp 0xf692
jmp 0xf69d
callq 0xf720
jmp 0xf69b
jmp 0xf69d
jmp 0xf69f
movl $0x0, -0x4(%rbp)
movl $0x1, -0x274(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x10540
leaq -0xa8(%rbp), %rdi
callq 0xe1d0
leaq -0x70(%rbp), %rdi
callq 0xe1d0
leaq -0x50(%rbp), %rdi
callq 0xe1d0
movl -0x4(%rbp), %eax
addq $0x7a0, %rsp            # imm = 0x7A0
popq %rbp
retq
leaq -0xc0(%rbp), %rdi
callq 0x10540
leaq -0xa8(%rbp), %rdi
callq 0xe1d0
leaq -0x70(%rbp), %rdi
callq 0xe1d0
leaq -0x50(%rbp), %rdi
callq 0xe1d0
movq -0x80(%rbp), %rdi
callq 0xe5d0
nopl (%rax)