#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*/ SEEK_END;
int check_data(char *, long);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
long fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, char, long);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int extractFastq(char *fname, char *pdata, long int Size_pdata) {
  FILE *fil;
  long int dataSize;
  long int i;
  if ((fil = fopen(fname, "r")) == NULL)
    printf("error: file not found\n");
  fseek(fil, 0, SEEK_END);
  dataSize = ftell(fil);
  rewind(fil);
  if (dataSize == 0) {
    fclose(fil);
    printf("error: no data in file\n");
  }
  memset(pdata, '\0', Size_pdata);
  for (i = 0; i < dataSize; i += 1024 * 1000000) {
    long int size = 1024 * 1000000;
    if (dataSize - i < size)
      size = dataSize - i;
    if (fread(pdata + i, sizeof(char), size, fil) != size) {
      fclose(fil);
      printf("error: file is too small\n");
    }
  }
  fclose(fil);
  pdata[dataSize] = 0;
  return check_data(pdata, dataSize);
}


x86 assembly (clang, -O0):
<extractFastq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11ce <extractFastq+0x3e>
lea    0xe39(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <rewind@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1218 <extractFastq+0x88>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe06(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1080 <memset@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    12b4 <extractFastq+0x124>
movq   $0x3d090000,-0x38(%rbp)
3d
mov    -0x28(%rbp),%rax
sub    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jge    1263 <extractFastq+0xd3>
mov    -0x28(%rbp),%rax
sub    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
add    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
cmp    -0x38(%rbp),%rax
je     129c <extractFastq+0x10c>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd9a(%rip),%rdi
call   1050 <printf@plt>
jmp    12a1 <extractFastq+0x111>
mov    -0x30(%rbp),%rax
add    $0x3d090000,%rax
mov    %rax,-0x30(%rbp)
jmp    122f <extractFastq+0x9f>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <check_data@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extractFastq>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
lea    0xe58(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11c1 <extractFastq+0x31>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r13,%rdi
call   1090 <ftell@plt>
mov    %rax,%r12
mov    %r13,%rdi
call   1060 <rewind@plt>
test   %r12,%r12
je     1262 <extractFastq+0xd2>
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1080 <memset@plt>
test   %r12,%r12
jle    1283 <extractFastq+0xf3>
xor    %ebp,%ebp
mov    %r12,%r15
jmp    1223 <extractFastq+0x93>
nopl   0x0(%rax)
add    $0x3d090000,%rbp
add    $0xffffffffc2f70000,%r15
cmp    %rbp,%r12
jle    1283 <extractFastq+0xf3>
cmp    $0x3d090000,%r15
mov    $0x3d090000,%ebx
cmovl  %r15,%rbx
lea    (%r14,%rbp,1),%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r13,%rcx
call   1040 <fread@plt>
cmp    %rbx,%rax
je     1210 <extractFastq+0x80>
mov    %r13,%rdi
call   1050 <fclose@plt>
lea    0xda7(%rip),%rdi
call   1030 <puts@plt>
jmp    1210 <extractFastq+0x80>
mov    %r13,%rdi
call   1050 <fclose@plt>
lea    0xdaa(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1080 <memset@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
movb   $0x0,(%r14,%r12,1)
mov    %r14,%rdi
mov    %r12,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <check_data@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"error: file not found\0A\00"
@SEEK_END = global i32 0
@.str.2 = [24 x i8] c"error: no data in file\0A\00"
@.str.3 = [26 x i8] c"error: file is too small\0A\00"
define i32 @extractFastq(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %7
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %3
%17 = load i32*, i32** %7
%18 = load i32, i32* @SEEK_END
%19 = call i32 @fseek(i32* %17, i32 0, i32 %18)
%20 = load i32*, i32** %7
%21 = call i64 @ftell(i32* %20)
store i64 %21, i64* %8
%22 = load i32*, i32** %7
%23 = call i32 @rewind(i32* %22)
%24 = load i64, i64* %8
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %16
%27 = load i32*, i32** %7
%28 = call i32 @fclose(i32* %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %26, %16
%31 = load i8*, i8** %5
%32 = load i64, i64* %6
%33 = call i32 @memset(i8* %31, i8 signext 0, i64 %32)
store i64 0, i64* %9
br label %34
34: ; preds = %62, %30
%35 = load i64, i64* %9
%36 = load i64, i64* %8
%37 = icmp slt i64 %35, %36
br i1 %37, label %38, label %65
38: ; preds = %34
store i64 1024000000, i64* %10
%39 = load i64, i64* %8
%40 = load i64, i64* %9
%41 = sub nsw i64 %39, %40
%42 = load i64, i64* %10
%43 = icmp slt i64 %41, %42
br i1 %43, label %44, label %48
44: ; preds = %38
%45 = load i64, i64* %8
%46 = load i64, i64* %9
%47 = sub nsw i64 %45, %46
store i64 %47, i64* %10
br label %48
48: ; preds = %44, %38
%49 = load i8*, i8** %5
%50 = load i64, i64* %9
%51 = getelementptr inbounds i8, i8* %49, i64 %50
%52 = load i64, i64* %10
%53 = load i32*, i32** %7
%54 = call i64 @fread(i8* %51, i32 1, i64 %52, i32* %53)
%55 = load i64, i64* %10
%56 = icmp ne i64 %54, %55
br i1 %56, label %57, label %61
57: ; preds = %48
%58 = load i32*, i32** %7
%59 = call i32 @fclose(i32* %58)
%60 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %57, %48
br label %62
62: ; preds = %61
%63 = load i64, i64* %9
%64 = add nsw i64 %63, 1024000000
store i64 %64, i64* %9
br label %34
65: ; preds = %34
%66 = load i32*, i32** %7
%67 = call i32 @fclose(i32* %66)
%68 = load i8*, i8** %5
%69 = load i64, i64* %8
%70 = getelementptr inbounds i8, i8* %68, i64 %69
store i8 0, i8* %70
%71 = load i8*, i8** %5
%72 = load i64, i64* %8
%73 = call i32 @check_data(i8* %71, i64 %72)
ret i32 %73
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@str = [25 x i8] c"error: file is too small\00"
@str.4 = [23 x i8] c"error: no data in file\00"
@str.5 = [22 x i8] c"error: file not found\00"
define i32 @extractFastq(i8* nocapture %0, i8* %1, i64 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.5, i64 0, i64 0))
br label %8
8: ; preds = %6, %3
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %4, i32 0, i32 %9)
%11 = tail call i64 @ftell(i32* %4)
%12 = tail call i32 @rewind(i32* %4)
%13 = icmp eq i64 %11, 0
br i1 %13, label %14, label %18
14: ; preds = %8
%15 = tail call i32 @fclose(i32* %4)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.4, i64 0, i64 0))
%17 = tail call i32 @memset(i8* %1, i8 signext 0, i64 %2)
br label %35
18: ; preds = %8
%19 = tail call i32 @memset(i8* %1, i8 signext 0, i64 %2)
%20 = icmp sgt i64 %11, 0
br i1 %20, label %21, label %35
21: ; preds = %18, %32
%22 = phi i64 [ %33, %32 ], [ 0, %18 ]
%23 = sub nsw i64 %11, %22
%24 = icmp slt i64 %23, 1024000000
%25 = select i1 %24, i64 %23, i64 1024000000
%26 = getelementptr inbounds i8, i8* %1, i64 %22
%27 = tail call i64 @fread(i8* %26, i32 1, i64 %25, i32* %4)
%28 = icmp eq i64 %27, %25
br i1 %28, label %32, label %29
29: ; preds = %21
%30 = tail call i32 @fclose(i32* %4)
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %29, %21
%33 = add nuw nsw i64 %22, 1024000000
%34 = icmp sgt i64 %11, %33
br i1 %34, label %21, label %35
35: ; preds = %32, %14, %18
%36 = tail call i32 @fclose(i32* %4)
%37 = getelementptr inbounds i8, i8* %1, i64 %11
store i8 0, i8* %37
%38 = tail call i32 @check_data(i8* %1, i64 %11)
ret i32 %38
}