// File: /workspace/github_c_makefile_star2_O1/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), %rdi
movq %rdi, 0x2e93(%rip)      # 0x4070
movl $0x2f, %esi
callq 0x1060
testq %rax, %rax
je 0x11f6
incq %rax
movq %rax, 0x2e7a(%rip)      # 0x4070
cmpl $0x1, %ebp
jg 0x121a
movq 0x2e6e(%rip), %rsi      # 0x4070
leaq 0xdfb(%rip), %rdi       # 0x2004
xorl %eax, %eax
callq 0x1050
movl $0x1, %ebx
jmp 0x129b
movq 0x8(%r14), %rbx
leaq 0xe6d(%rip), %rsi       # 0x2092
movq %rbx, %rdi
callq 0x1070
testl %eax, %eax
je 0x1284
leaq 0xe5d(%rip), %rsi       # 0x2095
movq %rbx, %rdi
callq 0x1070
testl %eax, %eax
je 0x1284
movl %ebp, %r13d
movq -0x8(%r14,%r13,8), %rsi
leaq 0xe4a(%rip), %rdi       # 0x209d
xorl %eax, %eax
callq 0x1050
cmpl $0x3, %ebp
jne 0x12af
movq 0x8(%r14), %r15
leaq 0xe4c(%rip), %rsi       # 0x20b6
movq %r15, %rdi
callq 0x1070
testl %eax, %eax
je 0x12af
leaq 0xe3d(%rip), %rdi       # 0x20ba
xorl %ebx, %ebx
movq %r15, %rsi
jmp 0x1294
movq 0x2de5(%rip), %rsi      # 0x4070
leaq 0xd72(%rip), %rdi       # 0x2004
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1050
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 0xe19(%rip), %rsi       # 0x20d4
callq 0x1090
testq %rax, %rax
je 0x143e
movq %rax, %rbx
xorps %xmm0, %xmm0
leaq 0x90(%rsp), %r15
movaps %xmm0, (%r15)
xorl %eax, %eax
movl %eax, 0x60(%r15)
movaps %xmm0, 0x50(%r15)
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x30(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movl $0x74726170, %ecx       # imm = 0x74726170
movl %ecx, (%r15)
movw $0x5f31, 0x4(%r15)      # imm = 0x5F31
leaq 0x20(%rsp), %r12
movaps %xmm0, (%r12)
movl %eax, 0x60(%r12)
movaps %xmm0, 0x50(%r12)
movaps %xmm0, 0x40(%r12)
movaps %xmm0, 0x30(%r12)
movaps %xmm0, 0x20(%r12)
movaps %xmm0, 0x10(%r12)
movl %ecx, (%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 0xd98(%rip), %r13       # 0x20fc
movq %r15, %rdi
movq %r13, %rsi
callq 0x1090
movq %rax, %r14
movq %r12, %rdi
movq %r13, %rsi
callq 0x1090
movq %r14, 0x10(%rsp)
testq %r14, %r14
setne %dl
movq %rax, 0x8(%rsp)
testq %rax, %rax
setne %cl
testb %cl, %dl
jne 0x13b2
leaq 0xd60(%rip), %rdi       # 0x20fe
leaq 0x90(%rsp), %rsi
leaq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x1050
cmpl $0x3, %ebp
jne 0x144f
leaq 0xd89(%rip), %r15       # 0x214b
leaq 0x300(%rsp), %r13
leaq 0x200(%rsp), %rbp
leaq 0xd7d(%rip), %r12       # 0x2156
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x1030
testl %eax, %eax
jle 0x1517
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x1080
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x1030
movl %eax, %r14d
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x1080
testl %r14d, %r14d
jg 0x13d9
jmp 0x1517
movq -0x8(%r14,%r13,8), %rsi
leaq 0xc8c(%rip), %rdi       # 0x20d6
jmp 0x1209
leaq 0xcd6(%rip), %r14       # 0x212c
leaq 0x1b(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x300(%rsp), %rdx
leaq 0x200(%rsp), %rcx
movq %r15, %r8
leaq 0x100(%rsp), %r9
xorl %eax, %eax
callq 0x1030
testl %eax, %eax
jle 0x1517
movq 0x10(%rsp), %rdi
leaq 0xca8(%rip), %rsi       # 0x213f
leaq 0x300(%rsp), %rbp
movq %rbp, %rdx
leaq 0x200(%rsp), %r12
movq %r12, %rcx
leaq 0x100(%rsp), %r13
movq %r13, %r8
xorl %eax, %eax
callq 0x1080
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r12, %rcx
movq %r15, %r8
movq %r13, %r9
xorl %eax, %eax
callq 0x1030
movq %rbx, %r13
movq %r15, %rbx
movq %r14, %r15
movl %eax, %r14d
movq 0x8(%rsp), %rdi
leaq 0xc4f(%rip), %rsi       # 0x213f
movq %rbp, %rdx
movq %r12, %rcx
leaq 0x100(%rsp), %r8
xorl %eax, %eax
callq 0x1080
testl %r14d, %r14d
movq %r15, %r14
movq %rbx, %r15
movq %r13, %rbx
jg 0x145b
movq 0x10(%rsp), %rdi
callq 0x1040
movq 0x8(%rsp), %rdi
callq 0x1040
movq %rbx, %rdi
callq 0x1040
jmp 0x1210