#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 */
char EOF;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
char *malloc(long);
int /*<<< orphan*/ stderr;
long readfile(char *filename, char *text[]) {
  FILE *fin;
  long len;
  int i = 0;
  char c;
  if (!(fin = fopen(filename, "r"))) {
    fprintf(stderr, "I can't open the file: %s\n", filename);
    exit(1);
  }
  fseek(fin, 0, SEEK_END);
  len = ftell(fin);
  fseek(fin, 0, SEEK_SET);
  *text = malloc(len + 1);
  while ((c = (fgetc(fin))) != EOF) {
    if ((c == 'a') || (c == 'c') || (c == 'g') || (c == 't') || (c == 'A') ||
        (c == 'C') || (c == 'G') || (c == 'T')) {
      (*text)[i] = c;
      i++;
    }
  }
  fclose(fin);
  return i;
}


x86 assembly (clang, -O0):
<readfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d8 <readfile+0x58>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe39(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e05(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dc4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x25(%rbp)
movsbl %al,%eax
mov    0x2da6(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12cc <readfile+0x14c>
movsbl -0x25(%rbp),%eax
cmp    $0x61,%eax
je     12ad <readfile+0x12d>
movsbl -0x25(%rbp),%eax
cmp    $0x63,%eax
je     12ad <readfile+0x12d>
movsbl -0x25(%rbp),%eax
cmp    $0x67,%eax
je     12ad <readfile+0x12d>
movsbl -0x25(%rbp),%eax
cmp    $0x74,%eax
je     12ad <readfile+0x12d>
movsbl -0x25(%rbp),%eax
cmp    $0x41,%eax
je     12ad <readfile+0x12d>
movsbl -0x25(%rbp),%eax
cmp    $0x43,%eax
je     12ad <readfile+0x12d>
movsbl -0x25(%rbp),%eax
cmp    $0x47,%eax
je     12ad <readfile+0x12d>
movsbl -0x25(%rbp),%eax
cmp    $0x54,%eax
jne    12c7 <readfile+0x147>
mov    -0x25(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1224 <readfile+0xa4>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movslq -0x24(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readfile>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe6a(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     124c <readfile+0xcc>
mov    %rax,%r12
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
mov    %r12,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r12,%rdi
call   1060 <ftell@plt>
mov    %rax,%r15
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
add    $0x1,%r15
mov    %r15,%rdi
call   1070 <malloc@plt>
mov    %rax,(%r14)
mov    %r12,%rdi
call   1040 <fgetc@plt>
mov    0x2de8(%rip),%r15
cmp    (%r15),%al
jne    1212 <readfile+0x92>
mov    %r12,%rdi
call   1030 <fclose@plt>
movslq %ebx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %ebx,%ebx
movabs $0x8004500080045,%r13
jmp    122d <readfile+0xad>
mov    %r12,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%al
je     11fd <readfile+0x7d>
lea    -0x41(%rax),%ecx
cmp    $0x33,%cl
ja     1220 <readfile+0xa0>
movzbl %cl,%ecx
bt     %rcx,%r13
jae    1220 <readfile+0xa0>
mov    (%r14),%rcx
movslq %ebx,%rbx
mov    %al,(%rcx,%rbx,1)
add    $0x1,%ebx
jmp    1220 <readfile+0xa0>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"I can't open the file: %s\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@EOF = global i8 0
define i64 @readfile(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 0, i32* %7
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %3
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32*, i32** %5
%19 = load i32, i32* @SEEK_END
%20 = call i32 @fseek(i32* %18, i32 0, i32 %19)
%21 = load i32*, i32** %5
%22 = call i64 @ftell(i32* %21)
store i64 %22, i64* %6
%23 = load i32*, i32** %5
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @fseek(i32* %23, i32 0, i32 %24)
%26 = load i64, i64* %6
%27 = add nsw i64 %26, 1
%28 = call i8* @malloc(i64 %27)
%29 = load i8**, i8*** %4
store i8* %28, i8** %29
br label %30
30: ; preds = %78, %17
%31 = load i32*, i32** %5
%32 = call signext i8 @fgetc(i32* %31)
store i8 %32, i8* %8
%33 = sext i8 %32 to i32
%34 = load i8, i8* @EOF
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %33, %35
br i1 %36, label %37, label %79
37: ; preds = %30
%38 = load i8, i8* %8
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 97
br i1 %40, label %69, label %41
41: ; preds = %37
%42 = load i8, i8* %8
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 99
br i1 %44, label %69, label %45
45: ; preds = %41
%46 = load i8, i8* %8
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 103
br i1 %48, label %69, label %49
49: ; preds = %45
%50 = load i8, i8* %8
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 116
br i1 %52, label %69, label %53
53: ; preds = %49
%54 = load i8, i8* %8
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 65
br i1 %56, label %69, label %57
57: ; preds = %53
%58 = load i8, i8* %8
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 67
br i1 %60, label %69, label %61
61: ; preds = %57
%62 = load i8, i8* %8
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 71
br i1 %64, label %69, label %65
65: ; preds = %61
%66 = load i8, i8* %8
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %67, 84
br i1 %68, label %69, label %78
69: ; preds = %65, %61, %57, %53, %49, %45, %41, %37
%70 = load i8, i8* %8
%71 = load i8**, i8*** %4
%72 = load i8*, i8** %71
%73 = load i32, i32* %7
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
store i8 %70, i8* %75
%76 = load i32, i32* %7
%77 = add nsw i32 %76, 1
store i32 %77, i32* %7
br label %78
78: ; preds = %69, %65
br label %30
79: ; preds = %30
%80 = load i32*, i32** %5
%81 = call i32 @fclose(i32* %80)
%82 = load i32, i32* %7
%83 = sext i32 %82 to i64
ret i64 %83
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"I can't open the file: %s\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@EOF = global i8 0
define i64 @readfile(i8* %0, i8** nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %3, i32 0, i32 %10)
%12 = tail call i64 @ftell(i32* %3)
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @fseek(i32* %3, i32 0, i32 %13)
%15 = add nsw i64 %12, 1
%16 = tail call i8* @malloc(i64 %15)
store i8* %16, i8** %1
%17 = tail call signext i8 @fgetc(i32* %3)
%18 = load i8, i8* @EOF
%19 = icmp eq i8 %17, %18
br i1 %19, label %33, label %20
20: ; preds = %9, %28
%21 = phi i8 [ %30, %28 ], [ %17, %9 ]
%22 = phi i32 [ %29, %28 ], [ 0, %9 ]
switch i8 %21, label %28 [
i8 116, label %23
i8 103, label %23
i8 99, label %23
i8 97, label %23
i8 84, label %23
i8 71, label %23
i8 67, label %23
i8 65, label %23
]
23: ; preds = %20, %20, %20, %20, %20, %20, %20, %20
%24 = load i8*, i8** %1
%25 = sext i32 %22 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8 %21, i8* %26
%27 = add nsw i32 %22, 1
br label %28
28: ; preds = %20, %23
%29 = phi i32 [ %27, %23 ], [ %22, %20 ]
%30 = tail call signext i8 @fgetc(i32* %3)
%31 = load i8, i8* @EOF
%32 = icmp eq i8 %30, %31
br i1 %32, label %33, label %20
33: ; preds = %28, %9
%34 = phi i32 [ 0, %9 ], [ %29, %28 ]
%35 = tail call i32 @fclose(i32* %3)
%36 = sext i32 %34 to i64
ret i64 %36
}