#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  if (argc != 4)
    print_usage();
  FILE *fastq = fopen(argv[1], "r");
  FILE *f_fastq = fopen(argv[2], "w");
  FILE *r_fastq = fopen(argv[3], "w");
  if (fastq != NULL && f_fastq != NULL && r_fastq != NULL) {
    int count = 0;
    char line[1024];
    while (fgets(line, sizeof line, fastq) != NULL) {
      if (count < 4) {
        fputs(line, f_fastq);
        count++;
      } else {
        fputs(line, r_fastq);
        count++;
      }
      if (count == 8)
        count = 0;
    }
    fclose(fastq);
    fclose(f_fastq);
    fclose(r_fastq);
  } else {
    printf("Error reading some of the input files\n");
    exit(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     119a <main+0x2a>
mov    $0x0,%al
call   1090 <print_usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe57(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe41(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe29(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12a0 <main+0x130>
cmpq   $0x0,-0x20(%rbp)
je     12a0 <main+0x130>
cmpq   $0x0,-0x28(%rbp)
je     12a0 <main+0x130>
movl   $0x0,-0x2c(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1280 <main+0x110>
cmpl   $0x4,-0x2c(%rbp)
jge    1251 <main+0xe1>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    126a <main+0xfa>
lea    -0x430(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x8,-0x2c(%rbp)
jne    127b <main+0x10b>
movl   $0x0,-0x2c(%rbp)
jmp    120a <main+0x9a>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
jmp    12b3 <main+0x143>
lea    0xd5d(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
je     1190 <main+0x20>
xor    %eax,%eax
call   1090 <print_usage@plt>
mov    0x8(%rbx),%rdi
lea    0xe65(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
mov    0x10(%rbx),%rdi
lea    0xe54(%rip),%r15
mov    %r15,%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    0x18(%rbx),%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
test   %r12,%r12
je     1270 <main+0x100>
test   %r14,%r14
je     1270 <main+0x100>
mov    %rax,%r15
test   %rax,%rax
je     1270 <main+0x100>
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1244 <main+0xd4>
xor    %r13d,%r13d
mov    %rsp,%rbx
xor    %ebp,%ebp
jmp    1237 <main+0xc7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <fputs@plt>
add    $0x1,%ebp
cmp    $0x8,%ebp
cmove  %r13d,%ebp
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1244 <main+0xd4>
mov    %r14,%rsi
cmp    $0x4,%ebp
jl     1210 <main+0xa0>
mov    %r15,%rsi
jmp    1210 <main+0xa0>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd8d(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [39 x i8] c"Error reading some of the input files\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (...) @print_usage()
br label %15
15: ; preds = %13, %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %7
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 3
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %8
%28 = load i32*, i32** %6
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %69
30: ; preds = %15
%31 = load i32*, i32** %7
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %69
33: ; preds = %30
%34 = load i32*, i32** %8
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %69
36: ; preds = %33
store i32 0, i32* %9
br label %37
37: ; preds = %61, %36
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%39 = load i32*, i32** %6
%40 = call i32* @fgets(i8* %38, i32 1024, i32* %39)
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %62
42: ; preds = %37
%43 = load i32, i32* %9
%44 = icmp slt i32 %43, 4
br i1 %44, label %45, label %51
45: ; preds = %42
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%47 = load i32*, i32** %7
%48 = call i32 @fputs(i8* %46, i32* %47)
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %57
51: ; preds = %42
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%53 = load i32*, i32** %8
%54 = call i32 @fputs(i8* %52, i32* %53)
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %57
57: ; preds = %51, %45
%58 = load i32, i32* %9
%59 = icmp eq i32 %58, 8
br i1 %59, label %60, label %61
60: ; preds = %57
store i32 0, i32* %9
br label %61
61: ; preds = %60, %57
br label %37
62: ; preds = %37
%63 = load i32*, i32** %6
%64 = call i32 @fclose(i32* %63)
%65 = load i32*, i32** %7
%66 = call i32 @fclose(i32* %65)
%67 = load i32*, i32** %8
%68 = call i32 @fclose(i32* %67)
br label %72
69: ; preds = %33, %30, %15
%70 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%71 = call i32 @exit(i32 0)
unreachable
72: ; preds = %62
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@str = [38 x i8] c"Error reading some of the input files\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = icmp eq i32 %0, 4
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 (...) @print_usage()
br label %7
7: ; preds = %5, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i32* %10, null
%18 = icmp ne i32* %13, null
%19 = and i1 %17, %18
%20 = icmp ne i32* %16, null
%21 = and i1 %19, %20
br i1 %21, label %22, label %40
22: ; preds = %7
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%24 = call i32* @fgets(i8* %23, i32 1024, i32* %10)
%25 = icmp eq i32* %24, null
br i1 %25, label %36, label %26
26: ; preds = %22, %26
%27 = phi i32 [ %33, %26 ], [ 0, %22 ]
%28 = icmp slt i32 %27, 4
%29 = select i1 %28, i32* %13, i32* %16
%30 = call i32 @fputs(i8* %23, i32* %29)
%31 = add nsw i32 %27, 1
%32 = icmp eq i32 %31, 8
%33 = select i1 %32, i32 0, i32 %31
%34 = call i32* @fgets(i8* %23, i32 1024, i32* %10)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %26
36: ; preds = %26, %22
%37 = call i32 @fclose(i32* %10)
%38 = call i32 @fclose(i32* %13)
%39 = call i32 @fclose(i32* %16)
ret i32 0
40: ; preds = %7
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%42 = tail call i32 @exit(i32 0)
unreachable
}