// File: /workspace/github_c_makefile_star2_O2/sc932[P]ALE/src/readFileSplitter.c
// Function: main
int main(int argc, char **argv){
    static char *prog;
    char *p;
    prog = argv[0];
    if((p = strrchr(prog, '/')) != NULL)
        prog = ++p;
    if (argc < 2) { usage(prog); return 1; }
    if (strcmp(argv[1], "-h") ==  0) { usage(prog); return 0; }
    if (strcmp(argv[1], "--helph")  == 0) { usage(prog); return 0; }
    printf("Input file to split: %s\n", argv[argc - 1]);
    
    int hasQualityInfo = 1;
    
    if (argc == 3) {
        if(strcmp(argv[1], "-ro")==0){
            hasQualityInfo = 0;
        }else{
            printf("Could not find option %s\n", argv[1]);
            return 0;
        }
    }
    
    // attempt to open the input file
    FILE *ins = fopen(argv[argc - 1], "r");
    if(ins == NULL){
        printf("Error! Could not open input file: %s\n", argv[argc - 1]);
        return 1;
    }
    
    
    
    // open up output file
    FILE *fo1, *fo2;
    char fileName1[100] = "part1_", fileName2[100] = "part2_";
    strcat(fileName1, argv[argc - 1]);
    strcat(fileName2, argv[argc - 1]);
    fo1 = fopen(fileName1, "w");
    fo2 = fopen(fileName2, "w");
    if(fo1 == NULL || fo2 == NULL){
        printf("Error! Could not open output files: %s or %s\n", fileName1, fileName2);
    }
    
    // read in and output the files
    int keepGoing = 1;
    char seqName[256];
    char seq[256];
    char qual[256];
    char temp[5];
    if(hasQualityInfo == 1){
        while(keepGoing > 0){
            // first read
            keepGoing = fscanf( ins, "%255s%255s%5s%255s", seqName, seq, temp, qual);
            if(keepGoing > 0){
                fprintf(fo1, "%s\n%s\n+\n%s\n", seqName, seq, qual);
                keepGoing = fscanf( ins, "%255s%255s%5s%255s", seqName, seq, temp, qual);
                fprintf(fo2, "%s\n%s\n+\n%s\n", seqName, seq, qual);
            }
        }
        fclose(fo1);
        fclose(fo2);
        fclose(ins);
    }else{
        while(keepGoing > 0){
            // first read
            keepGoing = fscanf( ins, "%255s%255s", seqName, seq);
            if(keepGoing > 0){
                fprintf(fo1, "%s\n%s\n", seqName, seq);
                keepGoing = fscanf( ins, "%255s%255s", seqName, seq);
                fprintf(fo2, "%s\n%s\n", seqName, seq);
            }
        }
        fclose(fo1);
        fclose(fo2);
        fclose(ins);
    }
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
movq %rsi, %r14
movl %edi, %ebp
movq (%rsi), %rbx
movq %rbx, 0x2e93(%rip)      # 0x4070
pushq $0x2f
popq %rsi
movq %rbx, %rdi
callq 0x1060
testq %rax, %rax
je 0x11fa
incq %rax
movq %rax, 0x2e79(%rip)      # 0x4070
movq %rax, %rbx
cmpl $0x1, %ebp
jg 0x120c
movq %rbx, %rdi
callq 0x11ac
pushq $0x1
popq %rbx
jmp 0x1282
movq 0x8(%r14), %rdi
cmpb $0x2d, (%rdi)
jne 0x1221
cmpb $0x68, 0x1(%rdi)
jne 0x1221
cmpb $0x0, 0x2(%rdi)
je 0x1278
leaq 0xe6a(%rip), %rsi       # 0x2092
callq 0x1070
testl %eax, %eax
je 0x1278
movl %ebp, %r13d
movq -0x8(%r14,%r13,8), %rsi
leaq 0xe5a(%rip), %rdi       # 0x209a
xorl %eax, %eax
callq 0x1050
cmpl $0x3, %ebp
jne 0x1296
movq 0x8(%r14), %r15
leaq 0xe5c(%rip), %rsi       # 0x20b3
movq %r15, %rdi
callq 0x1070
testl %eax, %eax
je 0x1296
leaq 0xe4d(%rip), %rdi       # 0x20b7
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0x1050
jmp 0x1282
movq %rbx, %rdi
callq 0x11ac
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x8(%r14,%r13,8), %rdi
leaq 0xe2f(%rip), %rsi       # 0x20d1
callq 0x1090
testq %rax, %rax
je 0x142d
movq %rax, %rbx
xorps %xmm0, %xmm0
leaq 0x90(%rsp), %r15
movaps %xmm0, (%r15)
movaps %xmm0, 0x50(%r15)
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x30(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
andl $0x0, 0x60(%r15)
movl $0x74726170, %eax       # imm = 0x74726170
movl %eax, (%r15)
movw $0x5f31, 0x4(%r15)      # imm = 0x5F31
leaq 0x20(%rsp), %r12
movaps %xmm0, (%r12)
movaps %xmm0, 0x50(%r12)
movaps %xmm0, 0x40(%r12)
movaps %xmm0, 0x30(%r12)
movaps %xmm0, 0x20(%r12)
andl $0x0, 0x60(%r12)
movaps %xmm0, 0x10(%r12)
movl %eax, (%r12)
movw $0x5f32, 0x4(%r12)      # imm = 0x5F32
movq -0x8(%r14,%r13,8), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x10a0
movq %r12, %rdi
movq %r14, %rsi
callq 0x10a0
leaq 0xdae(%rip), %r14       # 0x20f9
movq %r15, %rdi
movq %r14, %rsi
callq 0x1090
movq %rax, %r15
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
movq %r15, 0x8(%rsp)
testq %r15, %r15
setne %dl
movq %rax, (%rsp)
testq %rax, %rax
setne %cl
testb %cl, %dl
jne 0x1398
leaq 0xd77(%rip), %rdi       # 0x20fb
leaq 0x90(%rsp), %rsi
leaq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x1050
cmpl $0x3, %ebp
movq %rbx, 0x10(%rsp)
jne 0x1445
pushq $0x1
popq %rbp
leaq 0xd98(%rip), %r14       # 0x2148
leaq 0x200(%rsp), %r15
leaq 0x100(%rsp), %r12
leaq 0xd8c(%rip), %r13       # 0x2153
movq 0x10(%rsp), %rbx
testl %ebp, %ebp
jle 0x14f9
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x1030
movl %eax, %ebp
testl %eax, %eax
jle 0x13cc
movq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x1080
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x1030
movl %eax, %ebp
movq (%rsp), %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x1080
jmp 0x13cc
movq -0x8(%r14,%r13,8), %rsi
leaq 0xc9a(%rip), %rdi       # 0x20d3
xorl %eax, %eax
callq 0x1050
jmp 0x1207
pushq $0x1
popq %r12
leaq 0x200(%rsp), %rbp
leaq 0x100(%rsp), %r15
leaq 0x1b(%rsp), %rbx
leaq 0x300(%rsp), %r14
movq 0x10(%rsp), %r13
movq %r14, %rax
leaq 0xcb4(%rip), %r14       # 0x2129
testl %r12d, %r12d
jle 0x14f9
movq %r13, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movq %rbx, %r8
movq %rax, %r14
movq %rax, %r9
xorl %eax, %eax
callq 0x1030
movl %eax, %r12d
testl %eax, %eax
jle 0x146b
movq 0x8(%rsp), %rdi
leaq 0xc93(%rip), %rsi       # 0x213c
movq %rbp, %rdx
movq %r15, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x1080
movq %r13, %rdi
leaq 0xc66(%rip), %rsi       # 0x2129
movq %rbp, %rdx
movq %r15, %rcx
movq %rbx, %r8
movq %r14, %r9
xorl %eax, %eax
callq 0x1030
movl %eax, %r12d
movq (%rsp), %rdi
leaq 0xc58(%rip), %rsi       # 0x213c
movq %rbp, %rdx
movq %r15, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x1080
jmp 0x146b
movq 0x8(%rsp), %rdi
callq 0x1040
movq (%rsp), %rdi
callq 0x1040
movq 0x10(%rsp), %rdi
callq 0x1040
jmp 0x1207