#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;
char *calloc(long, int);
int check_data(char *, long);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
long fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int extract_fastq_from_file(char *fname, char **pd, long int *size_pd) {
  FILE *fil;
  long int data_size;
  long int i;
  char *pdata;
  if ((fil = fopen(fname, "r")) == NULL) {
    fprintf(stderr, "Error: file %s not found.\n", fname);
    return 0;
  }
  fseek(fil, 0, SEEK_END);
  data_size = ftell(fil);
  rewind(fil);
  if (data_size == 0) {
    fclose(fil);
    fprintf(stderr, "Error: no data in file %s.\n", fname);
    return 0;
  }
  if ((pdata = calloc(data_size + 1, sizeof(char))) == NULL) {
    fprintf(stderr,
            "Error: unable to allocate memory in extract_fastq_from_file.\n");
    return 0;
  }
  for (i = 0; i < data_size; i += 1024 * 1000000) {
    long int size = 1024 * 1000000;
    if (data_size - i < size)
      size = data_size - i;
    if (fread(pdata + i, sizeof(char), size, fil) != size) {
      fclose(fil);
      fprintf(stderr, "Error: file %s is too small.\n", fname);
      free(pdata);
      return 0;
    }
  }
  fclose(fil);
  pdata[data_size] = 0;
  *pd = pdata;
  *size_pd = data_size + 1;
  return check_data(pdata, data_size);
}


x86 assembly (clang, -O0):
<extract_fastq_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11f9 <extract_fastq_from_file+0x59>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1391 <extract_fastq_from_file+0x1f1>
mov    -0x28(%rbp),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <rewind@plt>
cmpq   $0x0,-0x30(%rbp)
jne    125e <extract_fastq_from_file+0xbe>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1391 <extract_fastq_from_file+0x1f1>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    12a1 <extract_fastq_from_file+0x101>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1391 <extract_fastq_from_file+0x1f1>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    1352 <extract_fastq_from_file+0x1b2>
movq   $0x3d090000,-0x48(%rbp)
3d
mov    -0x30(%rbp),%rax
sub    -0x38(%rbp),%rax
cmp    -0x48(%rbp),%rax
jge    12dd <extract_fastq_from_file+0x13d>
mov    -0x30(%rbp),%rax
sub    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
add    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x48(%rbp),%rax
je     133a <extract_fastq_from_file+0x19a>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd59(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1391 <extract_fastq_from_file+0x1f1>
jmp    133f <extract_fastq_from_file+0x19f>
mov    -0x38(%rbp),%rax
add    $0x3d090000,%rax
mov    %rax,-0x38(%rbp)
jmp    12a9 <extract_fastq_from_file+0x109>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x40(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x40(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
add    $0x1,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <check_data@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_fastq_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0xe42(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12bd <extract_fastq_from_file+0x11d>
mov    %rax,%rbx
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %rbx,%rdi
call   10a0 <ftell@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1060 <rewind@plt>
test   %r12,%r12
je     12cf <extract_fastq_from_file+0x12f>
lea    0x1(%r12),%rdi
mov    %rdi,0x20(%rsp)
mov    $0x1,%esi
call   1080 <calloc@plt>
test   %rax,%rax
je     1302 <extract_fastq_from_file+0x162>
mov    %rax,%r13
mov    %r15,0x10(%rsp)
mov    %r14,0x18(%rsp)
mov    %rbp,0x8(%rsp)
test   %r12,%r12
jle    1281 <extract_fastq_from_file+0xe1>
xor    %r14d,%r14d
mov    %r12,%rbp
nopl   0x0(%rax,%rax,1)
cmp    $0x3d090000,%rbp
mov    $0x3d090000,%r15d
cmovl  %rbp,%r15
lea    (%r14,%r13,1),%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    %r15,%rax
jne    131b <extract_fastq_from_file+0x17b>
add    $0x3d090000,%r14
add    $0xffffffffc2f70000,%rbp
cmp    %r14,%r12
jg     1240 <extract_fastq_from_file+0xa0>
mov    %rbx,%rdi
call   1050 <fclose@plt>
movb   $0x0,0x0(%r13,%r12,1)
mov    0x10(%rsp),%rax
mov    %r13,(%rax)
mov    0x18(%rsp),%rax
mov    0x20(%rsp),%rcx
mov    %rcx,(%rax)
mov    %r13,%rdi
mov    %r12,%rsi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <check_data@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
lea    0xd35(%rip),%rsi
jmp    12e7 <extract_fastq_from_file+0x147>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
lea    0xd36(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
lea    0xd27(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    12f1 <extract_fastq_from_file+0x151>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
lea    0xd44(%rip),%rsi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    12f1 <extract_fastq_from_file+0x151>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Error: file %s not found.\0A\00"
@SEEK_END = global i32 0
@.str.2 = [28 x i8] c"Error: no data in file %s.\0A\00"
@.str.3 = [62 x i8] c"Error: unable to allocate memory in extract_fastq_from_file.\0A\00"
@.str.4 = [30 x i8] c"Error: file %s is too small.\0A\00"
define i32 @extract_fastq_from_file(i8* %0, i8** %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i64* %2, i64** %7
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %8
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %5
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %18)
store i32 0, i32* %4
br label %94
20: ; preds = %3
%21 = load i32*, i32** %8
%22 = load i32, i32* @SEEK_END
%23 = call i32 @fseek(i32* %21, i32 0, i32 %22)
%24 = load i32*, i32** %8
%25 = call i64 @ftell(i32* %24)
store i64 %25, i64* %9
%26 = load i32*, i32** %8
%27 = call i32 @rewind(i32* %26)
%28 = load i64, i64* %9
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %20
%31 = load i32*, i32** %8
%32 = call i32 @fclose(i32* %31)
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %5
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %34)
store i32 0, i32* %4
br label %94
36: ; preds = %20
%37 = load i64, i64* %9
%38 = add nsw i64 %37, 1
%39 = call i8* @calloc(i64 %38, i32 1)
store i8* %39, i8** %11
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %94
44: ; preds = %36
store i64 0, i64* %10
br label %45
45: ; preds = %77, %44
%46 = load i64, i64* %10
%47 = load i64, i64* %9
%48 = icmp slt i64 %46, %47
br i1 %48, label %49, label %80
49: ; preds = %45
store i64 1024000000, i64* %12
%50 = load i64, i64* %9
%51 = load i64, i64* %10
%52 = sub nsw i64 %50, %51
%53 = load i64, i64* %12
%54 = icmp slt i64 %52, %53
br i1 %54, label %55, label %59
55: ; preds = %49
%56 = load i64, i64* %9
%57 = load i64, i64* %10
%58 = sub nsw i64 %56, %57
store i64 %58, i64* %12
br label %59
59: ; preds = %55, %49
%60 = load i8*, i8** %11
%61 = load i64, i64* %10
%62 = getelementptr inbounds i8, i8* %60, i64 %61
%63 = load i64, i64* %12
%64 = load i32*, i32** %8
%65 = call i64 @fread(i8* %62, i32 1, i64 %63, i32* %64)
%66 = load i64, i64* %12
%67 = icmp ne i64 %65, %66
br i1 %67, label %68, label %76
68: ; preds = %59
%69 = load i32*, i32** %8
%70 = call i32 @fclose(i32* %69)
%71 = load i32, i32* @stderr
%72 = load i8*, i8** %5
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %72)
%74 = load i8*, i8** %11
%75 = call i32 @free(i8* %74)
store i32 0, i32* %4
br label %94
76: ; preds = %59
br label %77
77: ; preds = %76
%78 = load i64, i64* %10
%79 = add nsw i64 %78, 1024000000
store i64 %79, i64* %10
br label %45
80: ; preds = %45
%81 = load i32*, i32** %8
%82 = call i32 @fclose(i32* %81)
%83 = load i8*, i8** %11
%84 = load i64, i64* %9
%85 = getelementptr inbounds i8, i8* %83, i64 %84
store i8 0, i8* %85
%86 = load i8*, i8** %11
%87 = load i8**, i8*** %6
store i8* %86, i8** %87
%88 = load i64, i64* %9
%89 = add nsw i64 %88, 1
%90 = load i64*, i64** %7
store i64 %89, i64* %90
%91 = load i8*, i8** %11
%92 = load i64, i64* %9
%93 = call i32 @check_data(i8* %91, i64 %92)
store i32 %93, i32* %4
br label %94
94: ; preds = %80, %68, %41, %30, %16
%95 = load i32, i32* %4
ret i32 %95
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Error: file %s not found.\0A\00"
@SEEK_END = global i32 0
@.str.2 = [28 x i8] c"Error: no data in file %s.\0A\00"
@.str.3 = [62 x i8] c"Error: unable to allocate memory in extract_fastq_from_file.\0A\00"
@.str.4 = [30 x i8] c"Error: file %s is too small.\0A\00"
define i32 @extract_fastq_from_file(i8* %0, i8** nocapture writeonly %1, i64* nocapture writeonly %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 %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %48
9: ; preds = %3
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %4, i32 0, i32 %10)
%12 = tail call i64 @ftell(i32* %4)
%13 = tail call i32 @rewind(i32* %4)
%14 = icmp eq i64 %12, 0
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = tail call i32 @fclose(i32* %4)
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %48
19: ; preds = %9
%20 = add nsw i64 %12, 1
%21 = tail call i8* @calloc(i64 %20, i32 1)
%22 = icmp eq i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = icmp sgt i64 %12, 0
br i1 %24, label %30, label %44
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.3, i64 0, i64 0))
br label %48
28: ; preds = %30
%29 = icmp sgt i64 %12, %38
br i1 %29, label %30, label %44
30: ; preds = %23, %28
%31 = phi i64 [ %38, %28 ], [ 0, %23 ]
%32 = sub nsw i64 %12, %31
%33 = icmp slt i64 %32, 1024000000
%34 = select i1 %33, i64 %32, i64 1024000000
%35 = getelementptr inbounds i8, i8* %21, i64 %31
%36 = tail call i64 @fread(i8* %35, i32 1, i64 %34, i32* %4)
%37 = icmp eq i64 %36, %34
%38 = add nuw nsw i64 %31, 1024000000
br i1 %37, label %28, label %39
39: ; preds = %30
%40 = tail call i32 @fclose(i32* %4)
%41 = load i32, i32* @stderr
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%43 = tail call i32 @free(i8* %21)
br label %48
44: ; preds = %28, %23
%45 = tail call i32 @fclose(i32* %4)
%46 = getelementptr inbounds i8, i8* %21, i64 %12
store i8 0, i8* %46
store i8* %21, i8** %1
store i64 %20, i64* %2
%47 = tail call i32 @check_data(i8* %21, i64 %12)
br label %48
48: ; preds = %39, %44, %25, %15, %6
%49 = phi i32 [ 0, %6 ], [ 0, %15 ], [ 0, %25 ], [ 0, %39 ], [ %47, %44 ]
ret i32 %49
}