// File: ninjabear[P]dr-doom/src/main.cpp
// Function: main
int main(int argc, char **argv) {

    if (argc != 2) {
        usage();
        return PROC_OTHER_ERROR;
    }

    string method(argv[1]);

    switch (get_mode(method)) {
        case memory: 
            if (are_you_sure("This process will consume as much memory as it possibly can. This may make your system unstable!")) {
                cout << endl << "Understood. Memory cannon mode activating!" << endl << endl;
                consume_memory();
            }
            break;
        case fork_proc:
            if (are_you_sure("This process will spawn as many processes as it can. These processes will spawn processes and so on. This is going to be difficult to clean up!")) {
                cout << "Understood. Fork-bomb mode activating." << endl << endl;
                fork_bomb();
            }
            break;
        case cpu:
            if (are_you_sure("This process will create a thread that runs an infinite loop for each core. Killing this process should restore normal behaviour.")) {
                cout << endl << "Understood. Halt and catch fire mode activating." << endl << endl;
                consume_cpu();
            }
            break;
        case thread_b:
            if (are_you_sure("This process will create as many threads as it can. These threads will be zombies (consume no CPU). Killing this process should restore normal behaviour.")) {
                cout << endl << "Understood, activating." << endl << endl; 
                thread_bomb();
            }
            break;
        case file_handles:
            if (are_you_sure("This process will open a temp file for writing using as many file handles as possible.")) {
                cout << endl << "Understood. Opening file over and over again." << endl << endl;
                many_open_file_handles();
            }
            break;
        case version:
            show_version();
            break;
        case help:
        case unknown: 
        default: 
            usage();
            break;
    }

    return 0;    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
je 0x2bc0
callq 0x2740
movl $0x1, -0x4(%rbp)
jmp 0x31de
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x120(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x23a0
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x3200
jmp 0x2bf8
leaq -0x31(%rbp), %rdi
callq 0x2250
leaq -0x30(%rbp), %rdi
callq 0x29d0
movl %eax, -0x124(%rbp)
jmp 0x2c12
movl -0x124(%rbp), %eax
movl %eax, %ecx
movq %rcx, -0x130(%rbp)
subl $0x7, %eax
ja 0x31b8
movq -0x130(%rbp), %rax
leaq 0x53cc(%rip), %rcx      # 0x8004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x2250
jmp 0x31ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x31d3
leaq -0x69(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x23a0
movq -0x138(%rbp), %rdx
leaq 0x54c8(%rip), %rsi      # 0x8152
leaq -0x68(%rbp), %rdi
callq 0x3200
jmp 0x2c95
leaq -0x68(%rbp), %rdi
callq 0x2b00
movb %al, -0x139(%rbp)
jmp 0x2ca6
leaq -0x68(%rbp), %rdi
callq 0x2408
leaq -0x69(%rbp), %rdi
callq 0x2250
movb -0x139(%rbp), %al
testb $0x1, %al
jne 0x2cc7
jmp 0x2d6a
movq 0xa302(%rip), %rdi      # 0xcfd0
movq 0xa2db(%rip), %rsi      # 0xcfb0
callq 0x2230
movq %rax, -0x148(%rbp)
jmp 0x2ce3
movq -0x148(%rbp), %rdi
leaq 0x54c2(%rip), %rsi      # 0x81b3
callq 0x21f0
movq %rax, -0x150(%rbp)
jmp 0x2cff
movq -0x150(%rbp), %rdi
movq 0xa2a3(%rip), %rsi      # 0xcfb0
callq 0x2230
movq %rax, -0x158(%rbp)
jmp 0x2d1b
movq -0x158(%rbp), %rdi
movq 0xa287(%rip), %rsi      # 0xcfb0
callq 0x2230
jmp 0x2d30
callq 0x5040
jmp 0x2d37
jmp 0x2d6a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2d5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x2408
leaq -0x69(%rbp), %rdi
callq 0x2250
jmp 0x31d3
jmp 0x31c1
leaq -0x91(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x23a0
movq -0x160(%rbp), %rdx
leaq 0x544e(%rip), %rsi      # 0x81de
leaq -0x90(%rbp), %rdi
callq 0x3200
jmp 0x2d9e
leaq -0x90(%rbp), %rdi
callq 0x2b00
movb %al, -0x161(%rbp)
jmp 0x2db2
leaq -0x90(%rbp), %rdi
callq 0x2408
leaq -0x91(%rbp), %rdi
callq 0x2250
movb -0x161(%rbp), %al
testb $0x1, %al
jne 0x2dd9
jmp 0x2e66
movq 0xa1f0(%rip), %rdi      # 0xcfd0
leaq 0x5487(%rip), %rsi      # 0x826e
callq 0x21f0
movq %rax, -0x170(%rbp)
jmp 0x2df5
movq -0x170(%rbp), %rdi
movq 0xa1ad(%rip), %rsi      # 0xcfb0
callq 0x2230
movq %rax, -0x178(%rbp)
jmp 0x2e11
movq -0x178(%rbp), %rdi
movq 0xa191(%rip), %rsi      # 0xcfb0
callq 0x2230
jmp 0x2e26
callq 0x5e30
jmp 0x2e2d
jmp 0x2e66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2e55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x2408
leaq -0x91(%rbp), %rdi
callq 0x2250
jmp 0x31d3
jmp 0x31c1
leaq -0xb9(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x23a0
movq -0x180(%rbp), %rdx
leaq 0x5409(%rip), %rsi      # 0x8295
leaq -0xb8(%rbp), %rdi
callq 0x3200
jmp 0x2e9a
leaq -0xb8(%rbp), %rdi
callq 0x2b00
movb %al, -0x181(%rbp)
jmp 0x2eae
leaq -0xb8(%rbp), %rdi
callq 0x2408
leaq -0xb9(%rbp), %rdi
callq 0x2250
movb -0x181(%rbp), %al
testb $0x1, %al
jne 0x2ed5
jmp 0x2f7e
movq 0xa0f4(%rip), %rdi      # 0xcfd0
movq 0xa0cd(%rip), %rsi      # 0xcfb0
callq 0x2230
movq %rax, -0x190(%rbp)
jmp 0x2ef1
movq -0x190(%rbp), %rdi
leaq 0x5418(%rip), %rsi      # 0x8317
callq 0x21f0
movq %rax, -0x198(%rbp)
jmp 0x2f0d
movq -0x198(%rbp), %rdi
movq 0xa095(%rip), %rsi      # 0xcfb0
callq 0x2230
movq %rax, -0x1a0(%rbp)
jmp 0x2f29
movq -0x1a0(%rbp), %rdi
movq 0xa079(%rip), %rsi      # 0xcfb0
callq 0x2230
jmp 0x2f3e
callq 0x3580
jmp 0x2f45
jmp 0x2f7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2f6d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x2408
leaq -0xb9(%rbp), %rdi
callq 0x2250
jmp 0x31d3
jmp 0x31c1
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x23a0
movq -0x1a8(%rbp), %rdx
leaq 0x53a4(%rip), %rsi      # 0x8348
leaq -0xe0(%rbp), %rdi
callq 0x3200
jmp 0x2fb2
leaq -0xe0(%rbp), %rdi
callq 0x2b00
movb %al, -0x1a9(%rbp)
jmp 0x2fc6
leaq -0xe0(%rbp), %rdi
callq 0x2408
leaq -0xe1(%rbp), %rdi
callq 0x2250
movb -0x1a9(%rbp), %al
testb $0x1, %al
jne 0x2fed
jmp 0x3096
movq 0x9fdc(%rip), %rdi      # 0xcfd0
movq 0x9fb5(%rip), %rsi      # 0xcfb0
callq 0x2230
movq %rax, -0x1b8(%rbp)
jmp 0x3009
movq -0x1b8(%rbp), %rdi
leaq 0x53cb(%rip), %rsi      # 0x83e2
callq 0x21f0
movq %rax, -0x1c0(%rbp)
jmp 0x3025
movq -0x1c0(%rbp), %rdi
movq 0x9f7d(%rip), %rsi      # 0xcfb0
callq 0x2230
movq %rax, -0x1c8(%rbp)
jmp 0x3041
movq -0x1c8(%rbp), %rdi
movq 0x9f61(%rip), %rsi      # 0xcfb0
callq 0x2230
jmp 0x3056
callq 0x5e70
jmp 0x305d
jmp 0x3096
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x3085
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x2408
leaq -0xe1(%rbp), %rdi
callq 0x2250
jmp 0x31d3
jmp 0x31c1
leaq -0x109(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x23a0
movq -0x1d0(%rbp), %rdx
leaq 0x533e(%rip), %rsi      # 0x83fa
leaq -0x108(%rbp), %rdi
callq 0x3200
jmp 0x30ca
leaq -0x108(%rbp), %rdi
callq 0x2b00
movb %al, -0x1d1(%rbp)
jmp 0x30de
leaq -0x108(%rbp), %rdi
callq 0x2408
leaq -0x109(%rbp), %rdi
callq 0x2250
movb -0x1d1(%rbp), %al
testb $0x1, %al
jne 0x3105
jmp 0x31ab
movq 0x9ec4(%rip), %rdi      # 0xcfd0
movq 0x9e9d(%rip), %rsi      # 0xcfb0
callq 0x2230
movq %rax, -0x1e0(%rbp)
jmp 0x3121
movq -0x1e0(%rbp), %rdi
leaq 0x5322(%rip), %rsi      # 0x8451
callq 0x21f0
movq %rax, -0x1e8(%rbp)
jmp 0x313d
movq -0x1e8(%rbp), %rdi
movq 0x9e65(%rip), %rsi      # 0xcfb0
callq 0x2230
movq %rax, -0x1f0(%rbp)
jmp 0x3159
movq -0x1f0(%rbp), %rdi
movq 0x9e49(%rip), %rsi      # 0xcfb0
callq 0x2230
jmp 0x316e
callq 0x3f60
jmp 0x3175
jmp 0x31ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x319d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x2408
leaq -0x109(%rbp), %rdi
callq 0x2250
jmp 0x31d3
jmp 0x31c1
callq 0x2700
jmp 0x31b4
jmp 0x31c1
jmp 0x31b8
callq 0x2740
jmp 0x31bf
jmp 0x31c1
movl $0x0, -0x4(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2408
jmp 0x31de
leaq -0x30(%rbp), %rdi
callq 0x2408
jmp 0x31ea
movl -0x4(%rbp), %eax
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x2390
nopw %cs:(%rax,%rax)
nopl (%rax)