// File: nicluo[P]sorting-numbers/generate.cpp
// Function: main
int main(int argc, char *argv[]) {
    /* Must provide -n and -o argument */
    if (argc != 5 || strncmp(argv[1], "-n", 3) != 0 || strncmp(argv[3], "-o", 3) != 0) {
        printUsage(argv[0]);
        return 1;
    }
    
    /* Parse n */
    int n = 10;
    
    try {
        int nArg = std::stoi(argv[2]);
        n = nArg;
    } catch (std::invalid_argument &e) {
        printInvalidArgument();
        printUsage(argv[0]);
        return 1;
    }
    
    /* Open output file */
    char* outputFilename = argv[4];
    std::ofstream out;
    out.open(outputFilename, std::ofstream::out);
    
    /* Seed random number generator with current time */
    std::srand(std::time(0));
    
    /* Print n random numbers */
    for (int i = 0; i < n; i++) {
        out << std::rand() << "\n";
    }
    
    /* Flush and close output file */
    out.close();
        
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x5, -0x8(%rbp)
jne 0x249b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xbd5(%rip), %rsi       # 0x3043
movl $0x3, %edx
callq 0x20b0
cmpl $0x0, %eax
jne 0x249b
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0xbba(%rip), %rsi       # 0x3046
movl $0x3, %edx
callq 0x20b0
cmpl $0x0, %eax
je 0x24b3
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x23c0
movl $0x1, -0x4(%rbp)
jmp 0x2693
movl $0xa, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x278(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x2250
movq -0x278(%rbp), %rsi
movq -0x270(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x26f0
jmp 0x24f2
xorl %eax, %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
movl $0xa, %edx
callq 0x26b0
movl %eax, -0x27c(%rbp)
jmp 0x250c
leaq -0x38(%rbp), %rdi
callq 0x20d0
leaq -0x39(%rbp), %rdi
callq 0x2180
movl -0x27c(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x25b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x2555
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x20d0
leaq -0x39(%rbp), %rdi
callq 0x2180
movl -0x4c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x269f
movq -0x48(%rbp), %rdi
callq 0x2080
movq %rax, -0x58(%rbp)
callq 0x2410
jmp 0x2582
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x23c0
jmp 0x2590
movl $0x1, -0x4(%rbp)
callq 0x2210
jmp 0x2693
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x2210
jmp 0x25b4
jmp 0x269f
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x60(%rbp)
leaq -0x260(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x2220
movq -0x288(%rbp), %rdi
movq -0x60(%rbp), %rsi
movl $0x10, %edx
callq 0x2040
jmp 0x25ef
xorl %eax, %eax
movl %eax, %edi
callq 0x2130
movl %eax, %edi
callq 0x2140
movl $0x0, -0x264(%rbp)
movl -0x264(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x2672
callq 0x2060
movl %eax, %esi
leaq -0x260(%rbp), %rdi
callq 0x2230
movq %rax, -0x290(%rbp)
jmp 0x2630
movq -0x290(%rbp), %rdi
leaq 0xa0b(%rip), %rsi       # 0x3049
callq 0x2150
jmp 0x2645
jmp 0x2647
movl -0x264(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x264(%rbp)
jmp 0x2609
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x21f0
jmp 0x269f
leaq -0x260(%rbp), %rdi
callq 0x21c0
jmp 0x2680
movl $0x0, -0x4(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x21f0
movl -0x4(%rbp), %eax
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x2240
movq %rax, %rdi
callq 0x27a0