// File: aalto-speech[P]ftk/src/substrings.cc
// Function: main
int main(int argc, char* argv[]) {

    conf::Config config;
    config("usage: substrings [OPTION...] INPUT OUTPUT\n")
      ('h', "help", "", "", "display help")
      ('8', "utf-8", "", "", "Utf-8 character encoding in use")
      ('l', "max-length=INT", "arg must", "100", "Maximum length of the substrings");
    config.default_parse(argc, argv);
    if (config.arguments.size() != 2) config.print_help(stderr, 1);

    string infname = config.arguments[0];
    string outfname = config.arguments[1];
    unsigned int maxlen = config["max-length"].get_int();
    bool utf8_encoding = config["utf-8"].specified;

    map<string, float> substrs;
    int substr_count = get_substrings(infname, maxlen, substrs, utf8_encoding);

    vector<pair<string, float> > sorted_substrs;
    for (auto it = substrs.cbegin(); it != substrs.cend(); ++it)
        sorted_substrs.push_back(make_pair(it->first, it->second));
    sort(sorted_substrs.begin(), sorted_substrs.end(), desc_sort);

    cerr << substr_count << " substrings in total up to length of " << maxlen << endl;
    write_substrings(outfname, sorted_substrs);

    exit(EXIT_SUCCESS);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x500, %rsp            # imm = 0x500
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0xcf60
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x418(%rbp)
callq 0x4700
movq -0x418(%rbp), %rdx
leaq 0x64a8b(%rip), %rsi     # 0x6a061
leaq -0xe8(%rbp), %rdi
callq 0x4560
jmp 0x55e4
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0xcfd0
movq %rax, -0x420(%rbp)
jmp 0x5600
leaq -0x121(%rbp), %rdi
movq %rdi, -0x428(%rbp)
callq 0x4700
movq -0x428(%rbp), %rdx
leaq 0x64a74(%rip), %rsi     # 0x6a095
leaq -0x120(%rbp), %rdi
callq 0x4560
jmp 0x562f
leaq -0x149(%rbp), %rdi
movq %rdi, -0x430(%rbp)
callq 0x4700
movq -0x430(%rbp), %rdx
leaq 0x64dfb(%rip), %rsi     # 0x6a44b
leaq -0x148(%rbp), %rdi
callq 0x4560
jmp 0x565e
leaq -0x171(%rbp), %rdi
movq %rdi, -0x438(%rbp)
callq 0x4700
movq -0x438(%rbp), %rdx
leaq 0x64dcc(%rip), %rsi     # 0x6a44b
leaq -0x170(%rbp), %rdi
callq 0x4560
jmp 0x568d
leaq -0x199(%rbp), %rdi
movq %rdi, -0x440(%rbp)
callq 0x4700
movq -0x440(%rbp), %rdx
leaq 0x649df(%rip), %rsi     # 0x6a08d
leaq -0x198(%rbp), %rdi
callq 0x4560
jmp 0x56bc
movq -0x420(%rbp), %rdi
movl $0x68, %esi
leaq -0x120(%rbp), %rdx
leaq -0x148(%rbp), %rcx
leaq -0x170(%rbp), %r8
leaq -0x198(%rbp), %r9
callq 0xd000
movq %rax, -0x448(%rbp)
jmp 0x56f2
leaq -0x1c1(%rbp), %rdi
movq %rdi, -0x450(%rbp)
callq 0x4700
movq -0x450(%rbp), %rdx
leaq 0x64987(%rip), %rsi     # 0x6a09a
leaq -0x1c0(%rbp), %rdi
callq 0x4560
jmp 0x5721
leaq -0x1e9(%rbp), %rdi
movq %rdi, -0x458(%rbp)
callq 0x4700
movq -0x458(%rbp), %rdx
leaq 0x64d09(%rip), %rsi     # 0x6a44b
leaq -0x1e8(%rbp), %rdi
callq 0x4560
jmp 0x5750
leaq -0x211(%rbp), %rdi
movq %rdi, -0x460(%rbp)
callq 0x4700
movq -0x460(%rbp), %rdx
leaq 0x64cda(%rip), %rsi     # 0x6a44b
leaq -0x210(%rbp), %rdi
callq 0x4560
jmp 0x577f
leaq -0x239(%rbp), %rdi
movq %rdi, -0x468(%rbp)
callq 0x4700
movq -0x468(%rbp), %rdx
leaq 0x64900(%rip), %rsi     # 0x6a0a0
leaq -0x238(%rbp), %rdi
callq 0x4560
jmp 0x57ae
movq -0x448(%rbp), %rdi
movl $0x38, %esi
leaq -0x1c0(%rbp), %rdx
leaq -0x1e8(%rbp), %rcx
leaq -0x210(%rbp), %r8
leaq -0x238(%rbp), %r9
callq 0xd000
movq %rax, -0x470(%rbp)
jmp 0x57e4
leaq -0x261(%rbp), %rdi
movq %rdi, -0x478(%rbp)
callq 0x4700
movq -0x478(%rbp), %rdx
leaq 0x648bb(%rip), %rsi     # 0x6a0c0
leaq -0x260(%rbp), %rdi
callq 0x4560
jmp 0x5813
leaq -0x289(%rbp), %rdi
movq %rdi, -0x480(%rbp)
callq 0x4700
movq -0x480(%rbp), %rdx
leaq 0x6489b(%rip), %rsi     # 0x6a0cf
leaq -0x288(%rbp), %rdi
callq 0x4560
jmp 0x5842
leaq -0x2b1(%rbp), %rdi
movq %rdi, -0x488(%rbp)
callq 0x4700
movq -0x488(%rbp), %rdx
leaq 0x64875(%rip), %rsi     # 0x6a0d8
leaq -0x2b0(%rbp), %rdi
callq 0x4560
jmp 0x5871
leaq -0x2d9(%rbp), %rdi
movq %rdi, -0x490(%rbp)
callq 0x4700
movq -0x490(%rbp), %rdx
leaq 0x6484a(%rip), %rsi     # 0x6a0dc
leaq -0x2d8(%rbp), %rdi
callq 0x4560
jmp 0x58a0
movq -0x470(%rbp), %rdi
movl $0x6c, %esi
leaq -0x260(%rbp), %rdx
leaq -0x288(%rbp), %rcx
leaq -0x2b0(%rbp), %r8
leaq -0x2d8(%rbp), %r9
callq 0xd000
jmp 0x58cf
leaq -0x2d8(%rbp), %rdi
callq 0x4828
leaq -0x2d9(%rbp), %rdi
callq 0x4430
leaq -0x2b0(%rbp), %rdi
callq 0x4828
leaq -0x2b1(%rbp), %rdi
callq 0x4430
leaq -0x288(%rbp), %rdi
callq 0x4828
leaq -0x289(%rbp), %rdi
callq 0x4430
leaq -0x260(%rbp), %rdi
callq 0x4828
leaq -0x261(%rbp), %rdi
callq 0x4430
leaq -0x238(%rbp), %rdi
callq 0x4828
leaq -0x239(%rbp), %rdi
callq 0x4430
leaq -0x210(%rbp), %rdi
callq 0x4828
leaq -0x211(%rbp), %rdi
callq 0x4430
leaq -0x1e8(%rbp), %rdi
callq 0x4828
leaq -0x1e9(%rbp), %rdi
callq 0x4430
leaq -0x1c0(%rbp), %rdi
callq 0x4828
leaq -0x1c1(%rbp), %rdi
callq 0x4430
leaq -0x198(%rbp), %rdi
callq 0x4828
leaq -0x199(%rbp), %rdi
callq 0x4430
leaq -0x170(%rbp), %rdi
callq 0x4828
leaq -0x171(%rbp), %rdi
callq 0x4430
leaq -0x148(%rbp), %rdi
callq 0x4828
leaq -0x149(%rbp), %rdi
callq 0x4430
leaq -0x120(%rbp), %rdi
callq 0x4828
leaq -0x121(%rbp), %rdi
callq 0x4430
leaq -0xe8(%rbp), %rdi
callq 0x4828
leaq -0xe9(%rbp), %rdi
callq 0x4430
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq -0xc8(%rbp), %rdi
callq 0xde50
jmp 0x5a1c
leaq -0xc8(%rbp), %rdi
addq $0x98, %rdi
callq 0x65b0
cmpq $0x2, %rax
je 0x5d28
movq 0x94580(%rip), %rax     # 0x99fc0
movq (%rax), %rsi
leaq -0xc8(%rbp), %rdi
movl $0x1, %edx
callq 0xe610
jmp 0x5a56
jmp 0x5d28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5d00
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5cf4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5ce8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5cd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5cb8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5ca0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5c94
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5c88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5c70
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5c58
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5c40
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5c34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5c28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5c10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5bf8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5be0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0x4828
leaq -0x2d9(%rbp), %rdi
callq 0x4430
leaq -0x2b0(%rbp), %rdi
callq 0x4828
leaq -0x2b1(%rbp), %rdi
callq 0x4430
leaq -0x288(%rbp), %rdi
callq 0x4828
leaq -0x289(%rbp), %rdi
callq 0x4430
leaq -0x260(%rbp), %rdi
callq 0x4828
leaq -0x261(%rbp), %rdi
callq 0x4430
leaq -0x238(%rbp), %rdi
callq 0x4828
leaq -0x239(%rbp), %rdi
callq 0x4430
leaq -0x210(%rbp), %rdi
callq 0x4828
leaq -0x211(%rbp), %rdi
callq 0x4430
leaq -0x1e8(%rbp), %rdi
callq 0x4828
leaq -0x1e9(%rbp), %rdi
callq 0x4430
leaq -0x1c0(%rbp), %rdi
callq 0x4828
leaq -0x1c1(%rbp), %rdi
callq 0x4430
leaq -0x198(%rbp), %rdi
callq 0x4828
leaq -0x199(%rbp), %rdi
callq 0x4430
leaq -0x170(%rbp), %rdi
callq 0x4828
leaq -0x171(%rbp), %rdi
callq 0x4430
leaq -0x148(%rbp), %rdi
callq 0x4828
leaq -0x149(%rbp), %rdi
callq 0x4430
leaq -0x120(%rbp), %rdi
callq 0x4828
leaq -0x121(%rbp), %rdi
callq 0x4430
leaq -0xe8(%rbp), %rdi
callq 0x4828
leaq -0xe9(%rbp), %rdi
callq 0x4430
jmp 0x615f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x615f
leaq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x65d0
movq %rax, %rsi
leaq -0x300(%rbp), %rdi
callq 0x41b0
jmp 0x5d46
leaq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0x65d0
movq %rax, %rsi
leaq -0x320(%rbp), %rdi
callq 0x41b0
jmp 0x5d65
leaq -0x349(%rbp), %rdi
movq %rdi, -0x498(%rbp)
callq 0x4700
movq -0x498(%rbp), %rdx
leaq 0x64377(%rip), %rsi     # 0x6a0fd
leaq -0x348(%rbp), %rdi
callq 0x4560
jmp 0x5d94
leaq -0xc8(%rbp), %rdi
leaq -0x348(%rbp), %rsi
callq 0xdf90
movq %rax, -0x4a0(%rbp)
jmp 0x5db0
movq -0x4a0(%rbp), %rdi
callq 0xcce0
movl %eax, -0x4a4(%rbp)
jmp 0x5dc4
leaq -0x348(%rbp), %rdi
callq 0x4828
leaq -0x349(%rbp), %rdi
callq 0x4430
movl -0x4a4(%rbp), %eax
movl %eax, -0x324(%rbp)
leaq -0x371(%rbp), %rdi
movq %rdi, -0x4b0(%rbp)
callq 0x4700
movq -0x4b0(%rbp), %rdx
leaq 0x64291(%rip), %rsi     # 0x6a09a
leaq -0x370(%rbp), %rdi
callq 0x4560
jmp 0x5e17
leaq -0xc8(%rbp), %rdi
leaq -0x370(%rbp), %rsi
callq 0xdf90
movq %rax, -0x4b8(%rbp)
jmp 0x5e33
movq -0x4b8(%rbp), %rax
movb 0x4a(%rax), %al
movb %al, -0x4c9(%rbp)
leaq -0x370(%rbp), %rdi
callq 0x4828
leaq -0x371(%rbp), %rdi
callq 0x4430
movb -0x4c9(%rbp), %al
andb $0x1, %al
movb %al, -0x34a(%rbp)
leaq -0x3a8(%rbp), %rdi
movq %rdi, -0x4c8(%rbp)
callq 0x65f0
movq -0x4c8(%rbp), %rdx
movl -0x324(%rbp), %esi
movzbl -0x34a(%rbp), %ecx
andl $0x1, %ecx
leaq -0x300(%rbp), %rdi
callq 0x4f20
movl %eax, -0x4bc(%rbp)
jmp 0x5ea7
movl -0x4bc(%rbp), %eax
movl %eax, -0x3ac(%rbp)
leaq -0x3c8(%rbp), %rdi
callq 0x6610
leaq -0x3a8(%rbp), %rdi
callq 0x6630
movq %rax, -0x3d0(%rbp)
leaq -0x3a8(%rbp), %rdi
callq 0x6690
movq %rax, -0x3d8(%rbp)
leaq -0x3d0(%rbp), %rdi
leaq -0x3d8(%rbp), %rsi
callq 0x6660
testb $0x1, %al
jne 0x5f01
jmp 0x6063
leaq -0x3d0(%rbp), %rdi
movq %rdi, -0x4e0(%rbp)
callq 0x6730
movq -0x4e0(%rbp), %rdi
movq %rax, -0x4d8(%rbp)
callq 0x6730
movq -0x4d8(%rbp), %rsi
movq %rax, %rdx
addq $0x20, %rdx
leaq -0x400(%rbp), %rdi
callq 0x66f0
jmp 0x5f43
leaq -0x3c8(%rbp), %rdi
leaq -0x400(%rbp), %rsi
callq 0x66c0
jmp 0x5f58
leaq -0x400(%rbp), %rdi
callq 0x6750
leaq -0x3d0(%rbp), %rdi
callq 0x6770
jmp 0x5ed2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x6153
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x5fbe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x348(%rbp), %rdi
callq 0x4828
leaq -0x349(%rbp), %rdi
callq 0x4430
jmp 0x6147
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x6001
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x370(%rbp), %rdi
callq 0x4828
leaq -0x371(%rbp), %rdi
callq 0x4430
jmp 0x6147
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x613b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x612f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x400(%rbp), %rdi
callq 0x6750
jmp 0x612f
leaq -0x3c8(%rbp), %rdi
movq %rdi, -0x4e8(%rbp)
callq 0x67f0
movq -0x4e8(%rbp), %rdi
movq %rax, -0x408(%rbp)
callq 0x6820
movq %rax, -0x410(%rbp)
movq -0x408(%rbp), %rdi
movq -0x410(%rbp), %rsi
leaq -0x11a5(%rip), %rdx     # 0x4f00
callq 0x67a0
jmp 0x60ac
movl -0x3ac(%rbp), %esi
movq 0x93f2f(%rip), %rdi     # 0x99fe8
callq 0x46e0
movq %rax, -0x4f0(%rbp)
jmp 0x60c7
movq -0x4f0(%rbp), %rdi
leaq 0x64033(%rip), %rsi     # 0x6a108
callq 0x43d0
movq %rax, -0x4f8(%rbp)
jmp 0x60e3
movq -0x4f8(%rbp), %rdi
movl -0x324(%rbp), %esi
callq 0x4550
movq %rax, -0x500(%rbp)
jmp 0x60fe
movq -0x500(%rbp), %rdi
movq 0x93e8c(%rip), %rsi     # 0x99f98
callq 0x4410
jmp 0x6113
leaq -0x320(%rbp), %rdi
leaq -0x3c8(%rbp), %rsi
callq 0x53e0
jmp 0x6128
xorl %edi, %edi
callq 0x4480
leaq -0x3c8(%rbp), %rdi
callq 0x6850
leaq -0x3a8(%rbp), %rdi
callq 0x68b0
leaq -0x320(%rbp), %rdi
callq 0x4828
leaq -0x300(%rbp), %rdi
callq 0x4828
leaq -0xc8(%rbp), %rdi
callq 0x68d0
movq -0xf8(%rbp), %rdi
callq 0x46f0
nopw (%rax,%rax)