// File: tonymugen[P]sampleSNPs/varfiles.cpp
// Function: sampFiles::GbinFileI::sample(sampFiles::GbinFileO&, unsigned long const&)
void GbinFileI::sample(GbinFileO &out, const uint64_t &n){

    if (n == 0) {
        cerr << "WARNING: zero SNPs requested. Nothing to be done." << endl;
        return;
    }
    // start by figuring out the number of rows


    // calculate number of rows in the input binary file; file is closed before the function exits.
    uint64_t N = _numLines();

    // Test for potential problems
    if (N < n) {
        cerr << "ERROR: requested a sample of " << n << " rows that is greater than the number of rows (" << N << ") in the input file." << endl;
        return;
    } else if (N == n) {
        cerr << "WARNING: sample size (" << n << ") the same as the number of rows (" << N << ") in the input file. Simply copying the file." << endl;
        char *buf;
        const size_t bufSize = BUF_SIZE;
        try {
            buf = new char[bufSize];
        } catch (bad_alloc&) {
            cerr << "ERROR: failed to allocate buffer" << endl;
            exit(4);
        }

        try {
            _varFile.open(_fileName.c_str(), ios::in | ios::binary);
			if (!_varFile.is_open()) {
				cerr << "ERROR: failed to open file " << _fileName << " for input" << endl;
				exit(2);
			}

        } catch (system_error &error) {
            cerr << "ERROR: cannot open binary file " << _fileName << " for input: " << error.code().message() << flush;
            perror(" ");
            exit(1);
        }
        try {
            out._varFile.open(out._fileName.c_str(), ios::out | ios::binary | ios::trunc);
			if (!out._varFile.is_open()) {
				cerr << "ERROR: failed to open file " << out._fileName << " for output" << endl;
				exit(2);
			}

        } catch (system_error &error) {
            cerr << "ERROR: cannot open binary file " << out._fileName << " for output: " << error.code().message() << flush;
            perror(" ");
            exit(1);
        }

        while (_varFile) {
            _varFile.read(buf, bufSize);
            out._varFile.write(buf, _varFile.gcount()); // must be gcount() in case we got to the end of the file
        }
        _varFile.close();
        out._varFile.close();
        delete [] buf;
        return;
    }

    // Passed all the tests, proceed to sampling
    char *ROWbuf;
    size_t rowSize = _nCols*_elemSize;
    try {
        ROWbuf = new char[rowSize]; // .read() does not append a null-character
    } catch (bad_alloc &) {
        cerr << "ERROR: failed to allocate the row buffer" << endl;
        exit(4);
    }

    try {
        _varFile.open(_fileName.c_str(), ios::in | ios::binary);
		if (!_varFile.is_open()) {
			cerr << "ERROR: failed to open file " << _fileName << " for input" << endl;
			exit(2);
		}

    } catch (system_error &error) {
        cerr << "ERROR: cannot open binary file " << _fileName << " for input: " << error.code().message() << flush;
        perror(" ");
        exit(1);
    }

    if (out._varFile.is_open()) {
        out.close();
    }
    try {
        out._varFile.open(out._fileName.c_str(), ios::out | ios::binary | ios::trunc);
		if (!out._varFile.is_open()) {
			cerr << "ERROR: failed to open file " << out._fileName << " for output" << endl;
			exit(2);
		}

    } catch (system_error &error) {
        cerr << "ERROR: cannot open binary file " << out._fileName << " for output: " << error.code().message() << flush;
        perror(" ");
        exit(1);
    }

    uint64_t nloc = n; // local copy of n
    uint64_t S;
    uint64_t cumS = 0; // cumulative position in the file
    RanDraw *rowSamp;  // so that I can catch RanDraw constructor exceptions
    try {
        rowSamp = new RanDraw();
    } catch (string error) {
        cerr << "ERROR: " << error << endl;
        exit(5);
    }
    while (nloc) {
        try {
            S = rowSamp->vitter(nloc, N); // sample the number of rows to skip; keep track of the running total
        } catch (string error) {
            cerr << "ERROR: " << error << endl;
            exit(5);
        }
        cumS += S;
        N    -= S + 1;
        _varFile.seekg(cumS*rowSize); // seekg() index is base-0
        _varFile.read(ROWbuf, rowSize);
        cumS++;                        // step up cumS because seekg() will not change it (unlike the getline() that automatially advances)
        out._varFile.write(ROWbuf, rowSize);
        nloc--;

    }
    _varFile.close();
    out._varFile.close();
    delete [] ROWbuf;
    delete rowSamp;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x380, %rsp            # imm = 0x380
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0xa413
movq 0x21bfd(%rip), %rdi     # 0x2bff0
leaq 0x191b2(%rip), %rsi     # 0x235ac
callq 0x4310
movq %rax, %rdi
movq 0x21ba7(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0xb3bb
movq -0x188(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0xa491
movq 0x21bb8(%rip), %rdi     # 0x2bff0
leaq 0x1919f(%rip), %rsi     # 0x235de
callq 0x4310
movq %rax, %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
callq 0x40d0
movq %rax, %rdi
leaq 0x1919f(%rip), %rsi     # 0x235fc
callq 0x4310
movq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0x40d0
movq %rax, %rdi
leaq 0x191b4(%rip), %rsi     # 0x2362c
callq 0x4310
movq %rax, %rdi
movq 0x21b29(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0xb3bb
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jne 0xaaa8
movq 0x21b47(%rip), %rdi     # 0x2bff0
leaq 0x19191(%rip), %rsi     # 0x23641
callq 0x4310
movq %rax, %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
callq 0x40d0
movq %rax, %rdi
leaq 0x1918a(%rip), %rsi     # 0x23658
callq 0x4310
movq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0x40d0
movq %rax, %rdi
leaq 0x19192(%rip), %rsi     # 0x2367b
callq 0x4310
movq %rax, %rdi
movq 0x21ab8(%rip), %rsi     # 0x2bfb0
callq 0x4350
movq $0xa00000, -0x30(%rbp)  # imm = 0xA00000
movl $0xa00000, %edi         # imm = 0xA00000
callq 0x4030
movq %rax, -0x190(%rbp)
jmp 0xa518
movq -0x190(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0xa5a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xb3c4
movq -0x38(%rbp), %rdi
callq 0x4130
movq %rax, -0x48(%rbp)
movq 0x21a9b(%rip), %rdi     # 0x2bff0
leaq 0x1914d(%rip), %rsi     # 0x236a9
callq 0x4310
movq %rax, -0x198(%rbp)
jmp 0xa56a
movq -0x198(%rbp), %rdi
movq 0x21a38(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0xa57f
movl $0x4, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0x4580
jmp 0xa59c
jmp 0xb3c4
movq -0x188(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x1b0(%rbp)
addq $0x218, %rdi            # imm = 0x218
callq 0x4140
movq %rax, -0x1a8(%rbp)
movl $0x8, %edi
movl $0x4, %esi
callq 0x1ee70
movl %eax, -0x19c(%rbp)
jmp 0xa5e0
movl -0x19c(%rbp), %edx
movq -0x1a8(%rbp), %rsi
movq -0x1b0(%rbp), %rdi
callq 0x42f0
jmp 0xa5fb
movq -0x188(%rbp), %rdi
addq $0x8, %rdi
callq 0x45e0
movb %al, -0x1b1(%rbp)
jmp 0xa613
movb -0x1b1(%rbp), %al
testb $0x1, %al
jne 0xa787
jmp 0xa623
movq 0x219c6(%rip), %rdi     # 0x2bff0
leaq 0x18f07(%rip), %rsi     # 0x23538
callq 0x4310
movq %rax, -0x1c0(%rbp)
jmp 0xa63f
movq -0x1c0(%rbp), %rdi
movq -0x188(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x1c8(%rbp)
jmp 0xa662
movq -0x1c8(%rbp), %rdi
leaq 0x18ee4(%rip), %rsi     # 0x23554
callq 0x4310
movq %rax, -0x1d0(%rbp)
jmp 0xa67e
movq -0x1d0(%rbp), %rdi
movq 0x21924(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0xa693
movl $0x2, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0xb3c4
movq -0x38(%rbp), %rdi
callq 0x4130
movq %rax, -0x50(%rbp)
movq 0x21923(%rip), %rdi     # 0x2bff0
leaq 0x18e8b(%rip), %rsi     # 0x2355f
callq 0x4310
movq %rax, -0x1d8(%rbp)
jmp 0xa6e2
movq -0x1d8(%rbp), %rdi
movq -0x188(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x1e0(%rbp)
jmp 0xa705
movq -0x1e0(%rbp), %rdi
leaq 0x192d2(%rip), %rsi     # 0x239e5
callq 0x4310
movq %rax, -0x1e8(%rbp)
jmp 0xa721
movq -0x50(%rbp), %rdi
callq 0x1ee90
movq %rax, %rsi
leaq -0x70(%rbp), %rdi
callq 0x1eeb0
jmp 0xa738
movq -0x1e8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x42e0
movq %rax, -0x1f0(%rbp)
jmp 0xa751
movq -0x1f0(%rbp), %rdi
movq 0x21869(%rip), %rsi     # 0x2bfc8
callq 0x4350
jmp 0xa766
leaq -0x70(%rbp), %rdi
callq 0x46d8
leaq 0x19084(%rip), %rdi     # 0x237fa
callq 0x42a0
jmp 0xa77d
movl $0x1, %edi
callq 0x4400
jmp 0xa7b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xa7ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0xa7b3
jmp 0xb3c4
movq -0x10(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x208(%rbp)
addq $0x218, %rdi            # imm = 0x218
callq 0x4140
movq %rax, -0x200(%rbp)
movl $0x10, %edi
movl $0x4, %esi
callq 0x1ee70
movl %eax, -0x1f4(%rbp)
jmp 0xa7f4
movl -0x1f4(%rbp), %edi
movl $0x20, %esi
callq 0x1ee70
movl %eax, -0x20c(%rbp)
jmp 0xa80c
movl -0x20c(%rbp), %edx
movq -0x200(%rbp), %rsi
movq -0x208(%rbp), %rdi
callq 0x42f0
jmp 0xa827
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
callq 0x45e0
movb %al, -0x20d(%rbp)
jmp 0xa83c
movb -0x20d(%rbp), %al
testb $0x1, %al
jne 0xa9b3
jmp 0xa84c
movq 0x2179d(%rip), %rdi     # 0x2bff0
leaq 0x18cde(%rip), %rsi     # 0x23538
callq 0x4310
movq %rax, -0x218(%rbp)
jmp 0xa868
movq -0x218(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x220(%rbp)
jmp 0xa888
movq -0x220(%rbp), %rdi
leaq 0x18e34(%rip), %rsi     # 0x236ca
callq 0x4310
movq %rax, -0x228(%rbp)
jmp 0xa8a4
movq -0x228(%rbp), %rdi
movq 0x216fe(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0xa8b9
movl $0x2, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0xb3c4
movq -0x38(%rbp), %rdi
callq 0x4130
movq %rax, -0x78(%rbp)
movq 0x216fd(%rip), %rdi     # 0x2bff0
leaq 0x18c65(%rip), %rsi     # 0x2355f
callq 0x4310
movq %rax, -0x230(%rbp)
jmp 0xa908
movq -0x230(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x238(%rbp)
jmp 0xa928
movq -0x238(%rbp), %rdi
leaq 0x18da0(%rip), %rsi     # 0x236d6
callq 0x4310
movq %rax, -0x240(%rbp)
jmp 0xa944
movq -0x78(%rbp), %rdi
callq 0x1ee90
movq %rax, %rsi
leaq -0x98(%rbp), %rdi
callq 0x1eeb0
jmp 0xa95e
movq -0x240(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x42e0
movq %rax, -0x248(%rbp)
jmp 0xa97a
movq -0x248(%rbp), %rdi
movq 0x21640(%rip), %rsi     # 0x2bfc8
callq 0x4350
jmp 0xa98f
leaq -0x98(%rbp), %rdi
callq 0x46d8
leaq 0x18e58(%rip), %rdi     # 0x237fa
callq 0x42a0
jmp 0xa9a9
movl $0x1, %edi
callq 0x4400
jmp 0xa9e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xa9db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0xa9e2
jmp 0xb3c4
jmp 0xa9e9
movq -0x188(%rbp), %rax
movq %rax, %rdi
addq $0x8, %rdi
movq 0x8(%rax), %rax
addq -0x18(%rax), %rdi
callq 0x4440
testb $0x1, %al
jne 0xaa0a
jmp 0xaa69
movq -0x188(%rbp), %rdi
addq $0x8, %rdi
movq -0x28(%rbp), %rsi
movl $0xa00000, %edx         # imm = 0xA00000
callq 0x4450
movq -0x188(%rbp), %rdi
movq -0x10(%rbp), %rax
addq $0x8, %rax
addq $0x10, %rax
movq %rax, -0x258(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x250(%rbp)
addq $0x8, %rdi
callq 0x46c0
movq -0x258(%rbp), %rdi
movq -0x250(%rbp), %rsi
movq %rax, %rdx
callq 0x44a0
jmp 0xa9e9
movq -0x188(%rbp), %rdi
addq $0x8, %rdi
callq 0x4060
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
callq 0x4060
movq -0x28(%rbp), %rax
movq %rax, -0x260(%rbp)
cmpq $0x0, %rax
je 0xaaa3
movq -0x260(%rbp), %rdi
callq 0x4480
jmp 0xb3bb
jmp 0xaaaa
movq -0x188(%rbp), %rcx
movq 0x238(%rcx), %rax
movq 0x240(%rcx), %rcx
imulq %rcx, %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x4030
movq %rax, -0x268(%rbp)
jmp 0xaadf
movq -0x268(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0xab6e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xb3c4
movq -0x38(%rbp), %rdi
callq 0x4130
movq %rax, -0xb0(%rbp)
movq 0x214ce(%rip), %rdi     # 0x2bff0
leaq 0x18bbb(%rip), %rsi     # 0x236e4
callq 0x4310
movq %rax, -0x270(%rbp)
jmp 0xab37
movq -0x270(%rbp), %rdi
movq 0x2146b(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0xab4c
movl $0x4, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0x4580
jmp 0xab69
jmp 0xb3c4
movq -0x188(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x288(%rbp)
addq $0x218, %rdi            # imm = 0x218
callq 0x4140
movq %rax, -0x280(%rbp)
movl $0x8, %edi
movl $0x4, %esi
callq 0x1ee70
movl %eax, -0x274(%rbp)
jmp 0xabad
movl -0x274(%rbp), %edx
movq -0x280(%rbp), %rsi
movq -0x288(%rbp), %rdi
callq 0x42f0
jmp 0xabc8
movq -0x188(%rbp), %rdi
addq $0x8, %rdi
callq 0x45e0
movb %al, -0x289(%rbp)
jmp 0xabe0
movb -0x289(%rbp), %al
testb $0x1, %al
jne 0xad63
jmp 0xabf0
movq 0x213f9(%rip), %rdi     # 0x2bff0
leaq 0x1893a(%rip), %rsi     # 0x23538
callq 0x4310
movq %rax, -0x298(%rbp)
jmp 0xac0c
movq -0x298(%rbp), %rdi
movq -0x188(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x2a0(%rbp)
jmp 0xac2f
movq -0x2a0(%rbp), %rdi
leaq 0x18917(%rip), %rsi     # 0x23554
callq 0x4310
movq %rax, -0x2a8(%rbp)
jmp 0xac4b
movq -0x2a8(%rbp), %rdi
movq 0x21357(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0xac60
movl $0x2, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0xb3c4
movq -0x38(%rbp), %rdi
callq 0x4130
movq %rax, -0xb8(%rbp)
movq 0x21353(%rip), %rdi     # 0x2bff0
leaq 0x188bb(%rip), %rsi     # 0x2355f
callq 0x4310
movq %rax, -0x2b0(%rbp)
jmp 0xacb2
movq -0x2b0(%rbp), %rdi
movq -0x188(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x2b8(%rbp)
jmp 0xacd5
movq -0x2b8(%rbp), %rdi
leaq 0x18d02(%rip), %rsi     # 0x239e5
callq 0x4310
movq %rax, -0x2c0(%rbp)
jmp 0xacf1
movq -0xb8(%rbp), %rdi
callq 0x1ee90
movq %rax, %rsi
leaq -0xd8(%rbp), %rdi
callq 0x1eeb0
jmp 0xad0e
movq -0x2c0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x42e0
movq %rax, -0x2c8(%rbp)
jmp 0xad2a
movq -0x2c8(%rbp), %rdi
movq 0x21290(%rip), %rsi     # 0x2bfc8
callq 0x4350
jmp 0xad3f
leaq -0xd8(%rbp), %rdi
callq 0x46d8
leaq 0x18aa8(%rip), %rdi     # 0x237fa
callq 0x42a0
jmp 0xad59
movl $0x1, %edi
callq 0x4400
jmp 0xad97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xad8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0xad92
jmp 0xb3c4
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
callq 0x45e0
testb $0x1, %al
jne 0xadaa
jmp 0xadb4
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq -0x10(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x2e0(%rbp)
addq $0x218, %rdi            # imm = 0x218
callq 0x4140
movq %rax, -0x2d8(%rbp)
movl $0x10, %edi
movl $0x4, %esi
callq 0x1ee70
movl %eax, -0x2cc(%rbp)
jmp 0xadf0
movl -0x2cc(%rbp), %edi
movl $0x20, %esi
callq 0x1ee70
movl %eax, -0x2e4(%rbp)
jmp 0xae08
movl -0x2e4(%rbp), %edx
movq -0x2d8(%rbp), %rsi
movq -0x2e0(%rbp), %rdi
callq 0x42f0
jmp 0xae23
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
callq 0x45e0
movb %al, -0x2e5(%rbp)
jmp 0xae38
movb -0x2e5(%rbp), %al
testb $0x1, %al
jne 0xafb5
jmp 0xae48
movq 0x211a1(%rip), %rdi     # 0x2bff0
leaq 0x186e2(%rip), %rsi     # 0x23538
callq 0x4310
movq %rax, -0x2f0(%rbp)
jmp 0xae64
movq -0x2f0(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x2f8(%rbp)
jmp 0xae84
movq -0x2f8(%rbp), %rdi
leaq 0x18838(%rip), %rsi     # 0x236ca
callq 0x4310
movq %rax, -0x300(%rbp)
jmp 0xaea0
movq -0x300(%rbp), %rdi
movq 0x21102(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0xaeb5
movl $0x2, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0xb3c4
movq -0x38(%rbp), %rdi
callq 0x4130
movq %rax, -0xe0(%rbp)
movq 0x210fe(%rip), %rdi     # 0x2bff0
leaq 0x18666(%rip), %rsi     # 0x2355f
callq 0x4310
movq %rax, -0x308(%rbp)
jmp 0xaf07
movq -0x308(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x218, %rsi            # imm = 0x218
callq 0x42e0
movq %rax, -0x310(%rbp)
jmp 0xaf27
movq -0x310(%rbp), %rdi
leaq 0x187a1(%rip), %rsi     # 0x236d6
callq 0x4310
movq %rax, -0x318(%rbp)
jmp 0xaf43
movq -0xe0(%rbp), %rdi
callq 0x1ee90
movq %rax, %rsi
leaq -0x100(%rbp), %rdi
callq 0x1eeb0
jmp 0xaf60
movq -0x318(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x42e0
movq %rax, -0x320(%rbp)
jmp 0xaf7c
movq -0x320(%rbp), %rdi
movq 0x2103e(%rip), %rsi     # 0x2bfc8
callq 0x4350
jmp 0xaf91
leaq -0x100(%rbp), %rdi
callq 0x46d8
leaq 0x18856(%rip), %rdi     # 0x237fa
callq 0x42a0
jmp 0xafab
movl $0x1, %edi
callq 0x4400
jmp 0xafe9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xafdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0xafe4
jmp 0xb3c4
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x108(%rbp)
movq $0x0, -0x118(%rbp)
movl $0x8, %edi
callq 0x4330
movq %rax, -0x328(%rbp)
jmp 0xb015
movq -0x328(%rbp), %rdi
callq 0x22380
jmp 0xb023
movq -0x328(%rbp), %rax
movq %rax, -0x120(%rbp)
jmp 0xb119
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xb061
movq -0x328(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x8, %esi
callq 0x4340
movl -0x3c(%rbp), %eax
movl $0x3, %ecx
cmpl %ecx, %eax
jne 0xb3c4
movq -0x38(%rbp), %rdi
movq %rdi, -0x330(%rbp)
callq 0x4430
movq %rax, %rsi
leaq -0x140(%rbp), %rdi
callq 0x4150
jmp 0xb092
movq -0x330(%rbp), %rdi
callq 0x4130
movq 0x20f4b(%rip), %rdi     # 0x2bff0
leaq 0x18661(%rip), %rsi     # 0x2370d
callq 0x4310
movq %rax, -0x338(%rbp)
jmp 0xb0ba
movq -0x338(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x42e0
movq %rax, -0x340(%rbp)
jmp 0xb0d6
movq -0x340(%rbp), %rdi
movq 0x20ecc(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0xb0eb
movl $0x5, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0xb114
jmp 0xb3c4
jmp 0xb11b
cmpq $0x0, -0x108(%rbp)
je 0xb34d
movq -0x120(%rbp), %rdi
movq -0x108(%rbp), %xmm0
movaps 0x18361(%rip), %xmm2    # 0x234a0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x18365(%rip), %xmm1    # 0x234b0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm3
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm3, %xmm0
movsd %xmm0, -0x148(%rbp)
movq -0x20(%rbp), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x150(%rbp)
leaq -0x148(%rbp), %rsi
leaq -0x150(%rbp), %rdx
callq 0x227a0
movq %rax, -0x348(%rbp)
jmp 0xb19e
movq -0x348(%rbp), %rax
movq %rax, -0x110(%rbp)
jmp 0xb275
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl $0x3, %ecx
cmpl %ecx, %eax
jne 0xb3c4
movq -0x38(%rbp), %rdi
movq %rdi, -0x350(%rbp)
callq 0x4430
movq %rax, %rsi
leaq -0x170(%rbp), %rdi
callq 0x4150
jmp 0xb1ee
movq -0x350(%rbp), %rdi
callq 0x4130
movq 0x20def(%rip), %rdi     # 0x2bff0
leaq 0x18505(%rip), %rsi     # 0x2370d
callq 0x4310
movq %rax, -0x358(%rbp)
jmp 0xb216
movq -0x358(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x42e0
movq %rax, -0x360(%rbp)
jmp 0xb232
movq -0x360(%rbp), %rdi
movq 0x20d70(%rip), %rsi     # 0x2bfb0
callq 0x4350
jmp 0xb247
movl $0x5, %edi
callq 0x4400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x46d8
callq 0x4580
jmp 0xb270
jmp 0xb3c4
movq -0x188(%rbp), %rax
movq -0x110(%rbp), %rcx
addq -0x118(%rbp), %rcx
movq %rcx, -0x118(%rbp)
movq -0x110(%rbp), %rdx
addq $0x1, %rdx
movq -0x20(%rbp), %rcx
subq %rdx, %rcx
movq %rcx, -0x20(%rbp)
addq $0x8, %rax
movq %rax, -0x368(%rbp)
movq -0x118(%rbp), %rsi
imulq -0xa8(%rbp), %rsi
leaq -0x180(%rbp), %rdi
callq 0x1ef20
movq -0x368(%rbp), %rdi
movq -0x180(%rbp), %rsi
movq -0x178(%rbp), %rdx
callq 0x4460
movq -0x188(%rbp), %rdi
addq $0x8, %rdi
movq -0xa0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
callq 0x4450
movq -0x118(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x118(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
addq $0x10, %rdi
movq -0xa0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
callq 0x44a0
movq -0x108(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x108(%rbp)
jmp 0xb11b
movq -0x188(%rbp), %rdi
addq $0x8, %rdi
callq 0x4060
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
callq 0x4060
movq -0xa0(%rbp), %rax
movq %rax, -0x370(%rbp)
cmpq $0x0, %rax
je 0xb38a
movq -0x370(%rbp), %rdi
callq 0x4480
movq -0x120(%rbp), %rax
movq %rax, -0x378(%rbp)
cmpq $0x0, %rax
je 0xb3bb
movq -0x378(%rbp), %rdi
callq 0x1ef60
movq -0x378(%rbp), %rdi
movl $0x8, %esi
callq 0x4340
addq $0x380, %rsp            # imm = 0x380
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x4610
movq %rax, %rdi
callq 0x82c0
nopw %cs:(%rax,%rax)