// File: alexandres[P]terashuf/terashuf.cc
// Function: main
int main()
{
    char const *sepStr = std::getenv("SEP");
    const char sep = (sepStr != NULL && strlen(sepStr)) ? sepStr[0] : '\n';

    char *seedStr = std::getenv("SEED");
    const int seed = (seedStr != NULL && strlen(seedStr)) ? strtol(seedStr, NULL, 10) : time(NULL);
    std::mt19937_64 rng(seed);

    char *skipStr = std::getenv("SKIP");
    const int skipLines = (skipStr != NULL && strlen(skipStr)) ? strtol(skipStr, NULL, 10) : 0;

    char const *tmpDir = std::getenv("TMPDIR");
    if (tmpDir == NULL)
        tmpDir = "/tmp";
    char *tmpNameTemplate = (char *)malloc((strlen(tmpDir) + sizeof(TMP_NAME_TEMPLATE)) * sizeof(char));
    strcpy(tmpNameTemplate, tmpDir);
    strcat(tmpNameTemplate, TMP_NAME_TEMPLATE);

    char *memoryStr = std::getenv("MEMORY");
    const float memory = (memoryStr != NULL && strlen(memoryStr)) ? strtof(memoryStr, NULL) : 4;

    std::vector<ll> shufIndexes;

    const ll bufBytes = sizeof(char) * (ll)(memory * 1024. * 1024. * 1024.);
    char *buf = (char *)malloc(bufBytes);
    fprintf(stderr, "trying to allocate %zu bytes\n", bufBytes);
    if (buf == NULL)
    {
        fprintf(stderr, "failed to allocate buf memory\n");
        return 1;
    }

    fprintf(stderr, "\nstarting read\n");

    for (int i = 0; i < skipLines;)
    {
        char c = fgetc(stdin);
        if (c == EOF)
            return 0;
        if (fputc(c, stdout) == EOF)
        {
            fprintf(stderr, "failed to write SKIP lines. is disk full?");
            return 1;
        }
        if (c == sep)
            i++;
    }
    fprintf(stderr, "skipped %d lines\n", skipLines);

    ll totalBytesRead = 0, totalLinesRead = 0;
    std::vector<TmpFile> files;
    bool reachedEof = false;
    while (!reachedEof)
    {
        reachedEof = fillBufAndMarkLines(stdin, buf, bufBytes, shufIndexes, sep, memory);
        TmpFile tmpFile;
        // default output is stdout. if input fit in buffer, no need to use
        // temp files, just write to stdout.
        tmpFile.f = stdout;
        if (!reachedEof || files.size() > 0)
        {
            // haven't reached eof so have to call fillBuf again.
            // or we did did reach eof but there is already a temp file,
            // so we are already in temp file mode, not direct to stdout.
            tmpFile.path = (char *)malloc((strlen(tmpNameTemplate) + 1) * sizeof(char));
            strcpy(tmpFile.path, tmpNameTemplate);
            int fd = mkstemp(tmpFile.path);
            if (fd == -1)
            {
                fprintf(stderr, "failed to create fd tmp file %s\n",
                        tmpNameTemplate);
                return 1;
            }
            tmpFile.f = fdopen(fd, "wb+");
            if (tmpFile.f == NULL)
            {
                fprintf(stderr, "failed to create tmp file %s\n",
                        tmpFile.path);
                return 1;
            }
        }
        totalBytesRead += shufFlushBuf(buf, shufIndexes, rng, sep, tmpFile.f);
        totalLinesRead += shufIndexes.size();
        tmpFile.lines = shufIndexes.size();
        fprintf(stderr, "\rlines read: %zu, gb read: %zu", totalLinesRead,
                totalBytesRead / (1024 * 1024 * 1024));
        files.push_back(tmpFile);
    }

    // inform totalLines and totalBytesRead
    fprintf(stderr, "\nRead %zu lines, %zu bytes, have %d tmp files\n",
            totalLinesRead, totalBytesRead, (int)files.size());

    if (files.size() == 1)
    {
        fprintf(
            stderr,
            "\nShuffled directly to stdout without using tmpfiles, done!\n");
        return 0;
    }

    std::vector<ll> linesRemainingPerFile;

    for (auto &file : files)
    {
        rewind(file.f);
        // for bufferedFgetc
        file.buf = (char *)malloc(IO_CHUNK);
        file.bufPos = 0;
        file.bufN = 0;
        file.eof = false;
        linesRemainingPerFile.push_back(file.lines);
    }

    auto fenwickTree = FenwickTree(linesRemainingPerFile);

    ll totalBytesWritten = 0, linesRemaining = totalLinesRead, totalBytesWrittenForProgress = 0;

    fprintf(stderr, "\nstarting write to output\n");

    while (linesRemaining)
    {
        ll randLine = std::uniform_int_distribution<ll>{0, linesRemaining - 1}(rng);
        auto fileIdx = fenwickTree.findIndexAndDraw(randLine + 1);
        auto linesRemainingInFile = fenwickTree.getCountAtIndex(fileIdx);
        linesRemaining--;
        TmpFile &file = files[fileIdx];
        ll bytesRead = readLine(buf, sep, file);
        if (!linesRemainingInFile)
        {
            fclose(file.f);
            unlink(file.path);
        }
        ll bytesWritten = fwrite(buf, sizeof(char), bytesRead, stdout);
        if (bytesRead != bytesWritten)
        {
            fprintf(stderr, "\nFATAL ERROR: failed to write line to disk. is there space left?\n");
            return 1;
        }
        totalBytesWritten += bytesWritten;
        totalBytesWrittenForProgress += bytesWritten;
        // progress report
        if (!linesRemaining || totalBytesWrittenForProgress >= bufBytes)
        {
            fprintf(stderr, "\rlines written: %zu, gb written: %zu",
                    totalLinesRead - linesRemaining, totalBytesWritten / (1024 * 1024 * 1024));
            totalBytesWrittenForProgress = 0;
        }
    }
    fprintf(stderr, "\ndone\n");
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc10, %rsp            # imm = 0xC10
movl $0x0, -0x4(%rbp)
leaq 0x4828(%rip), %rdi      # 0x7181
callq 0x2160
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x2986
movq -0x10(%rbp), %rdi
callq 0x2090
cmpq $0x0, %rax
je 0x2986
movq -0x10(%rbp), %rax
movb (%rax), %al
movb %al, -0xb89(%rbp)
jmp 0x2990
movb $0xa, %al
movb %al, -0xb89(%rbp)
jmp 0x2990
movb -0xb89(%rbp), %al
movb %al, -0x11(%rbp)
leaq 0x47e5(%rip), %rdi      # 0x7185
callq 0x2160
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x29da
movq -0x20(%rbp), %rdi
callq 0x2090
cmpq $0x0, %rax
je 0x29da
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x21a0
movq %rax, -0xb98(%rbp)
jmp 0x29ea
xorl %eax, %eax
movl %eax, %edi
callq 0x20f0
movq %rax, -0xb98(%rbp)
movq -0xb98(%rbp), %rax
movl %eax, -0x24(%rbp)
movslq -0x24(%rbp), %rsi
leaq -0x9f0(%rbp), %rdi
callq 0x38d0
leaq 0x477f(%rip), %rdi      # 0x718a
callq 0x2160
movq %rax, -0x9f8(%rbp)
cmpq $0x0, -0x9f8(%rbp)
je 0x2a51
movq -0x9f8(%rbp), %rdi
callq 0x2090
cmpq $0x0, %rax
je 0x2a51
movq -0x9f8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x21a0
movq %rax, -0xba0(%rbp)
jmp 0x2a5c
xorl %eax, %eax
movq %rax, -0xba0(%rbp)
jmp 0x2a5c
movq -0xba0(%rbp), %rax
movl %eax, -0x9fc(%rbp)
leaq 0x471f(%rip), %rdi      # 0x718f
callq 0x2160
movq %rax, -0xa08(%rbp)
cmpq $0x0, -0xa08(%rbp)
jne 0x2a94
leaq 0x4709(%rip), %rax      # 0x7196
movq %rax, -0xa08(%rbp)
movq -0xa08(%rbp), %rdi
callq 0x2090
movq %rax, %rdi
addq $0x13, %rdi
shlq $0x0, %rdi
callq 0x2180
movq %rax, -0xa10(%rbp)
movq -0xa10(%rbp), %rdi
movq -0xa08(%rbp), %rsi
callq 0x2100
movq -0xa10(%rbp), %rdi
leaq 0x48f8(%rip), %rsi      # 0x73d0
callq 0x2220
leaq 0x46b7(%rip), %rdi      # 0x719b
callq 0x2160
movq %rax, -0xa18(%rbp)
cmpq $0x0, -0xa18(%rbp)
je 0x2b26
movq -0xa18(%rbp), %rdi
callq 0x2090
cmpq $0x0, %rax
je 0x2b26
movq -0xa18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2190
movss %xmm0, -0xba4(%rbp)
jmp 0x2b38
movss 0x4522(%rip), %xmm0     # 0x7050
movss %xmm0, -0xba4(%rbp)
jmp 0x2b38
movss -0xba4(%rbp), %xmm0
movss %xmm0, -0xa1c(%rbp)
leaq -0xa38(%rbp), %rdi
callq 0x3900
movss -0xa1c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x44b0(%rip), %xmm1     # 0x7018
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x4495(%rip), %xmm1     # 0x7020
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
shlq $0x0, %rax
movq %rax, -0xa40(%rbp)
movq -0xa40(%rbp), %rdi
callq 0x2180
movq %rax, -0xa48(%rbp)
movq 0x8419(%rip), %rax      # 0xafd8
movq (%rax), %rdi
movq -0xa40(%rbp), %rdx
leaq 0x45d2(%rip), %rsi      # 0x71a2
movb $0x0, %al
callq 0x21b0
cmpq $0x0, -0xa48(%rbp)
jne 0x2c0f
movq 0x83f0(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x45ce(%rip), %rsi      # 0x71c0
movb $0x0, %al
callq 0x21b0
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa4c(%rbp)
jmp 0x3459
movq 0x83c2(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x45bf(%rip), %rsi      # 0x71df
movb $0x0, %al
callq 0x21b0
movl $0x0, -0xa50(%rbp)
movl -0xa50(%rbp), %eax
cmpl -0x9fc(%rbp), %eax
jge 0x2d19
movq 0x8386(%rip), %rax      # 0xafd0
movq (%rax), %rdi
callq 0x21e0
movl %eax, -0xba8(%rbp)
jmp 0x2c5a
movl -0xba8(%rbp), %eax
movb %al, -0xa51(%rbp)
movsbl -0xa51(%rbp), %eax
cmpl $-0x1, %eax
jne 0x2c9f
movl $0x0, -0x4(%rbp)
movl $0x1, -0xa4c(%rbp)
jmp 0x3459
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa60(%rbp)
movl %eax, -0xa64(%rbp)
jmp 0x3471
movsbl -0xa51(%rbp), %edi
movq 0x830b(%rip), %rax      # 0xafb8
movq (%rax), %rsi
callq 0x2170
movl %eax, -0xbac(%rbp)
jmp 0x2cbd
movl -0xbac(%rbp), %eax
cmpl $-0x1, %eax
jne 0x2cf6
movq 0x8309(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x4516(%rip), %rsi      # 0x71ef
movb $0x0, %al
callq 0x21b0
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa4c(%rbp)
jmp 0x3459
movsbl -0xa51(%rbp), %eax
movsbl -0x11(%rbp), %ecx
cmpl %ecx, %eax
jne 0x2d14
movl -0xa50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa50(%rbp)
jmp 0x2c31
movq 0x82b8(%rip), %rax      # 0xafd8
movq (%rax), %rdi
movl -0x9fc(%rbp), %edx
leaq 0x44e9(%rip), %rsi      # 0x7219
movb $0x0, %al
callq 0x21b0
movq $0x0, -0xa70(%rbp)
movq $0x0, -0xa78(%rbp)
leaq -0xa90(%rbp), %rdi
callq 0x3920
movb $0x0, -0xa91(%rbp)
movb -0xa91(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2d71
jmp 0x2fac
movq 0x8258(%rip), %rax      # 0xafd0
movq (%rax), %rdi
movq -0xa48(%rbp), %rsi
movq -0xa40(%rbp), %rdx
movsbl -0x11(%rbp), %r8d
movss -0xa1c(%rbp), %xmm0
leaq -0xa38(%rbp), %rcx
callq 0x2600
movb %al, -0xbad(%rbp)
jmp 0x2daa
movb -0xbad(%rbp), %al
andb $0x1, %al
movb %al, -0xa91(%rbp)
movq 0x81f9(%rip), %rax      # 0xafb8
movq (%rax), %rax
movq %rax, -0xad0(%rbp)
testb $0x1, -0xa91(%rbp)
je 0x2de8
leaq -0xa90(%rbp), %rdi
callq 0x3940
cmpq $0x0, %rax
jbe 0x2ee8
movq -0xa10(%rbp), %rdi
callq 0x2090
movq %rax, %rdi
incq %rdi
callq 0x2180
movq %rax, -0xac8(%rbp)
movq -0xac8(%rbp), %rdi
movq -0xa10(%rbp), %rsi
callq 0x2100
movq -0xac8(%rbp), %rdi
callq 0x2060
movl %eax, -0xbb4(%rbp)
jmp 0x2e2d
movl -0xbb4(%rbp), %eax
movl %eax, -0xad4(%rbp)
cmpl $-0x1, -0xad4(%rbp)
jne 0x2e8e
movq 0x818f(%rip), %rax      # 0xafd8
movq (%rax), %rdi
movq -0xa10(%rbp), %rdx
leaq 0x43d1(%rip), %rsi      # 0x722b
movb $0x0, %al
callq 0x21b0
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa4c(%rbp)
jmp 0x343d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa60(%rbp)
movl %eax, -0xa64(%rbp)
jmp 0x344b
movl -0xad4(%rbp), %edi
leaq 0x43b1(%rip), %rsi      # 0x724c
callq 0x2140
movq %rax, -0xad0(%rbp)
cmpq $0x0, -0xad0(%rbp)
jne 0x2ee6
movq 0x8120(%rip), %rax      # 0xafd8
movq (%rax), %rdi
movq -0xac8(%rbp), %rdx
leaq 0x4387(%rip), %rsi      # 0x7250
movb $0x0, %al
callq 0x21b0
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa4c(%rbp)
jmp 0x343d
jmp 0x2ee8
movq -0xa48(%rbp), %rdi
movsbl -0x11(%rbp), %ecx
movq -0xad0(%rbp), %r8
leaq -0xa38(%rbp), %rsi
leaq -0x9f0(%rbp), %rdx
callq 0x2390
movq %rax, -0xbc0(%rbp)
jmp 0x2f16
movq -0xbc0(%rbp), %rcx
movq -0xa70(%rbp), %rax
addq %rcx, %rax
movq %rax, -0xa70(%rbp)
leaq -0xa38(%rbp), %rdi
movq %rdi, -0xbc8(%rbp)
callq 0x3870
movq -0xbc8(%rbp), %rdi
movq %rax, %rcx
movq -0xa78(%rbp), %rax
addq %rcx, %rax
movq %rax, -0xa78(%rbp)
callq 0x3870
movq %rax, -0xac0(%rbp)
movq 0x8069(%rip), %rax      # 0xafd8
movq (%rax), %rdi
movq -0xa78(%rbp), %rdx
movq -0xa70(%rbp), %rcx
shrq $0x1e, %rcx
leaq 0x42e3(%rip), %rsi      # 0x726e
xorl %eax, %eax
callq 0x21b0
leaq -0xa90(%rbp), %rdi
leaq -0xad0(%rbp), %rsi
callq 0x3970
jmp 0x2fa7
jmp 0x2d60
movq 0x8025(%rip), %rax      # 0xafd8
movq (%rax), %rax
movq %rax, -0xbe0(%rbp)
movq -0xa78(%rbp), %rax
movq %rax, -0xbd8(%rbp)
movq -0xa70(%rbp), %rax
movq %rax, -0xbd0(%rbp)
leaq -0xa90(%rbp), %rdi
callq 0x3940
movq -0xbe0(%rbp), %rdi
movq -0xbd8(%rbp), %rdx
movq -0xbd0(%rbp), %rcx
movl %eax, %r8d
leaq 0x4289(%rip), %rsi      # 0x728d
movb $0x0, %al
callq 0x21b0
leaq -0xa90(%rbp), %rdi
callq 0x3940
cmpq $0x1, %rax
jne 0x304b
movq 0x7fb4(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x428e(%rip), %rsi      # 0x72bc
movb $0x0, %al
callq 0x21b0
movl $0x0, -0x4(%rbp)
movl $0x1, -0xa4c(%rbp)
jmp 0x343d
leaq -0xaf0(%rbp), %rdi
callq 0x3900
leaq -0xa90(%rbp), %rax
movq %rax, -0xaf8(%rbp)
movq -0xaf8(%rbp), %rdi
callq 0x39e0
movq %rax, -0xb00(%rbp)
movq -0xaf8(%rbp), %rdi
callq 0x3a10
movq %rax, -0xb08(%rbp)
leaq -0xb00(%rbp), %rdi
leaq -0xb08(%rbp), %rsi
callq 0x3a40
testb $0x1, %al
jne 0x30a7
jmp 0x314f
leaq -0xb00(%rbp), %rdi
callq 0x3a80
movq %rax, -0xb10(%rbp)
movq -0xb10(%rbp), %rax
movq (%rax), %rdi
callq 0x2030
jmp 0x30cb
movl $0x10000, %edi          # imm = 0x10000
callq 0x2180
movq %rax, %rcx
movq -0xb10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0xb10(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0xb10(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0xb10(%rbp), %rax
movb $0x0, 0x30(%rax)
movq -0xb10(%rbp), %rsi
addq $0x10, %rsi
leaq -0xaf0(%rbp), %rdi
callq 0x3800
jmp 0x3125
jmp 0x3127
leaq -0xb00(%rbp), %rdi
callq 0x3aa0
jmp 0x308b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa60(%rbp)
movl %eax, -0xa64(%rbp)
jmp 0x342f
leaq -0xb30(%rbp), %rdi
leaq -0xaf0(%rbp), %rsi
callq 0x3ac0
jmp 0x3164
movq $0x0, -0xb38(%rbp)
movq -0xa78(%rbp), %rax
movq %rax, -0xb40(%rbp)
movq $0x0, -0xb48(%rbp)
movq 0x7e49(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x415f(%rip), %rsi      # 0x72f8
movb $0x0, %al
callq 0x21b0
cmpq $0x0, -0xb40(%rbp)
je 0x33ec
movq -0xb40(%rbp), %rdx
decq %rdx
xorl %eax, %eax
movl %eax, %esi
leaq -0xb60(%rbp), %rdi
callq 0x3be0
jmp 0x31ca
leaq -0xb60(%rbp), %rdi
leaq -0x9f0(%rbp), %rsi
callq 0x3c10
movq %rax, -0xbe8(%rbp)
jmp 0x31e6
movq -0xbe8(%rbp), %rax
movq %rax, -0xb50(%rbp)
movq -0xb50(%rbp), %rsi
incq %rsi
leaq -0xb30(%rbp), %rdi
callq 0x3c40
movl %eax, -0xbec(%rbp)
jmp 0x3212
movl -0xbec(%rbp), %eax
movl %eax, -0xb64(%rbp)
movl -0xb64(%rbp), %esi
leaq -0xb30(%rbp), %rdi
callq 0x3cf0
movq %rax, -0xbf8(%rbp)
jmp 0x3239
movq -0xbf8(%rbp), %rax
movq %rax, -0xb70(%rbp)
movq -0xb40(%rbp), %rax
decq %rax
movq %rax, -0xb40(%rbp)
movslq -0xb64(%rbp), %rsi
leaq -0xa90(%rbp), %rdi
callq 0x3d20
movq %rax, -0xb78(%rbp)
movq -0xa48(%rbp), %rdi
movsbl -0x11(%rbp), %esi
movq -0xb78(%rbp), %rdx
callq 0x2580
movq %rax, -0xc00(%rbp)
jmp 0x3292
movq -0xc00(%rbp), %rax
movq %rax, -0xb80(%rbp)
cmpq $0x0, -0xb70(%rbp)
jne 0x32f0
movq -0xb78(%rbp), %rax
movq (%rax), %rdi
callq 0x2110
jmp 0x32bb
movq -0xb78(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x20a0
jmp 0x32f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa60(%rbp)
movl %eax, -0xa64(%rbp)
leaq -0xb30(%rbp), %rdi
callq 0x3d40
jmp 0x342f
movq -0xa48(%rbp), %rdi
movq -0xb80(%rbp), %rdx
movq 0x7cb3(%rip), %rax      # 0xafb8
movq (%rax), %rcx
movl $0x1, %esi
callq 0x2240
movq %rax, -0xc08(%rbp)
jmp 0x331b
movq -0xc08(%rbp), %rax
movq %rax, -0xb88(%rbp)
movq -0xb80(%rbp), %rax
cmpq -0xb88(%rbp), %rax
je 0x3367
movq 0x7c98(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x3fc9(%rip), %rsi      # 0x7313
movb $0x0, %al
callq 0x21b0
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa4c(%rbp)
jmp 0x3415
movq -0xb88(%rbp), %rax
addq -0xb38(%rbp), %rax
movq %rax, -0xb38(%rbp)
movq -0xb88(%rbp), %rax
addq -0xb48(%rbp), %rax
movq %rax, -0xb48(%rbp)
cmpq $0x0, -0xb40(%rbp)
je 0x33ab
movq -0xb48(%rbp), %rax
cmpq -0xa40(%rbp), %rax
jb 0x33e7
movq 0x7c26(%rip), %rax      # 0xafd8
movq (%rax), %rdi
movq -0xa78(%rbp), %rdx
subq -0xb40(%rbp), %rdx
movq -0xb38(%rbp), %rcx
shrq $0x1e, %rcx
leaq 0x3f80(%rip), %rsi      # 0x7355
movb $0x0, %al
callq 0x21b0
movq $0x0, -0xb48(%rbp)
jmp 0x31a0
movq 0x7be5(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x3f7d(%rip), %rsi      # 0x737a
movb $0x0, %al
callq 0x21b0
movl $0x0, -0x4(%rbp)
movl $0x1, -0xa4c(%rbp)
leaq -0xb30(%rbp), %rdi
callq 0x3d40
leaq -0xaf0(%rbp), %rdi
callq 0x3d60
jmp 0x343d
leaq -0xaf0(%rbp), %rdi
callq 0x3d60
jmp 0x344b
leaq -0xa90(%rbp), %rdi
callq 0x3dc0
jmp 0x3459
leaq -0xa90(%rbp), %rdi
callq 0x3dc0
jmp 0x3471
leaq -0xa38(%rbp), %rdi
callq 0x3d60
movl -0x4(%rbp), %eax
addq $0xc10, %rsp            # imm = 0xC10
popq %rbp
retq
leaq -0xa38(%rbp), %rdi
callq 0x3d60
movq -0xa60(%rbp), %rdi
callq 0x2210
nopl (%rax)