#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int readGenes(char *search, int n) {
  FILE *f;
  if ((f = fopen("db/tmp.fsa", "r")) == NULL) {
    printf("Cannot open file.\n");
  }
  char *tmp = (char *)malloc(1000);
  int i = 0, tmp_i = 0;
  int l = 0;
  l = fscanf(f, "%s\0", tmp);
  while (l != -1) {
    while (tmp[tmp_i] != '\0' && tmp[tmp_i] != '\n') {
      search[i] = tmp[tmp_i];
      tmp_i++;
      i++;
      if (i >= n)
        break;
    }
    if (i >= n)
      break;
    tmp_i = 0;
    l = fscanf(f, "%s\0", tmp);
  }
  free(tmp);
  fclose(f);
  return i;
}


x86 assembly (clang, -O0):
<readGenes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    119c <readGenes+0x3c>
lea    0xe76(%rip),%rdi
call   1050 <printf@plt>
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe52(%rip),%rsi
call   1060 <fscanf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
je     1296 <readGenes+0x136>
jmp    11e5 <readGenes+0x85>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x2d(%rbp)
je     1214 <readGenes+0xb4>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    1224 <readGenes+0xc4>
jmp    1262 <readGenes+0x102>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     125d <readGenes+0xfd>
jmp    1262 <readGenes+0x102>
jmp    11e5 <readGenes+0x85>
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     1273 <readGenes+0x113>
jmp    1296 <readGenes+0x136>
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd97(%rip),%rsi
call   1060 <fscanf@plt>
mov    %eax,-0x2c(%rbp)
jmp    11d6 <readGenes+0x76>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readGenes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,0xc(%rsp)
mov    %rdi,0x10(%rsp)
lea    0xe82(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    119e <readGenes+0x3e>
lea    0xe74(%rip),%rdi
call   1040 <puts@plt>
mov    $0x3e8,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
lea    0xe6d(%rip),%rsi
mov    %r12,%rdi
mov    %rax,%rdx
call   1060 <fscanf@plt>
cmp    $0xffffffff,%eax
je     1247 <readGenes+0xe7>
movslq 0xc(%rsp),%r13
xor    %r15d,%r15d
mov    %r15d,%ebx
movslq %r15d,%rax
mov    0x10(%rsp),%rcx
add    %rax,%rcx
xor    %r14d,%r14d
nop
movzbl 0x0(%rbp,%r14,1),%edx
test   %dl,%dl
je     1210 <readGenes+0xb0>
cmp    $0xa,%dl
je     1210 <readGenes+0xb0>
mov    %dl,(%rcx,%r14,1)
lea    (%rax,%r14,1),%rdx
add    $0x1,%rdx
add    $0x1,%r14
cmp    %r13,%rdx
jl     11e0 <readGenes+0x80>
jmp    1239 <readGenes+0xd9>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%r15d
add    %r14,%r15
cmp    0xc(%rsp),%r15d
jge    1234 <readGenes+0xd4>
mov    %r12,%rdi
lea    0xdf8(%rip),%rsi
mov    %rbp,%rdx
call   1060 <fscanf@plt>
cmp    $0xffffffff,%eax
jne    11ce <readGenes+0x6e>
add    %r14d,%ebx
jmp    1249 <readGenes+0xe9>
add    $0x1,%ebx
mov    0xc(%rsp),%eax
cmp    %ebx,%eax
cmovg  %eax,%ebx
jmp    1249 <readGenes+0xe9>
xor    %ebx,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"db/tmp.fsa\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Cannot open file.\0A\00"
@.str.3 = [4 x i8] c"%s\00\00"
define i32 @readGenes(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = call i64 @malloc(i32 1000)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%17 = load i32*, i32** %5
%18 = load i8*, i8** %6
%19 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %18)
store i32 %19, i32* %9
br label %20
20: ; preds = %66, %14
%21 = load i32, i32* %9
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %70
23: ; preds = %20
br label %24
24: ; preds = %60, %23
%25 = load i8*, i8** %6
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %40
32: ; preds = %24
%33 = load i8*, i8** %6
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 10
br label %40
40: ; preds = %32, %24
%41 = phi i1 [ false, %24 ], [ %39, %32 ]
br i1 %41, label %42, label %61
42: ; preds = %40
%43 = load i8*, i8** %6
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = load i8*, i8** %3
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 %47, i8* %51
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
%56 = load i32, i32* %7
%57 = load i32, i32* %4
%58 = icmp sge i32 %56, %57
br i1 %58, label %59, label %60
59: ; preds = %42
br label %61
60: ; preds = %42
br label %24
61: ; preds = %59, %40
%62 = load i32, i32* %7
%63 = load i32, i32* %4
%64 = icmp sge i32 %62, %63
br i1 %64, label %65, label %66
65: ; preds = %61
br label %70
66: ; preds = %61
store i32 0, i32* %8
%67 = load i32*, i32** %5
%68 = load i8*, i8** %6
%69 = call i32 @fscanf(i32* %67, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %68)
store i32 %69, i32* %9
br label %20
70: ; preds = %65, %20
%71 = load i8*, i8** %6
%72 = call i32 @free(i8* %71)
%73 = load i32*, i32** %5
%74 = call i32 @fclose(i32* %73)
%75 = load i32, i32* %7
ret i32 %75
}

LLVM IR (-O2):
@.str = [11 x i8] c"db/tmp.fsa\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%s\00\00"
@str = [18 x i8] c"Cannot open file.\00"
define i32 @readGenes(i8* nocapture writeonly %0, i32 %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
%8 = tail call i64 @malloc(i32 1000)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %38, label %12
12: ; preds = %7
%13 = sext i32 %1 to i64
br label %14
14: ; preds = %12, %30
%15 = phi i32 [ %28, %30 ], [ 0, %12 ]
%16 = sext i32 %15 to i64
br label %17
17: ; preds = %14, %22
%18 = phi i64 [ 0, %14 ], [ %24, %22 ]
%19 = phi i64 [ %16, %14 ], [ %25, %22 ]
%20 = getelementptr inbounds i8, i8* %9, i64 %18
%21 = load i8, i8* %20
switch i8 %21, label %22 [
i8 0, label %27
i8 10, label %27
]
22: ; preds = %17
%23 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 %21, i8* %23
%24 = add nuw nsw i64 %18, 1
%25 = add nsw i64 %19, 1
%26 = icmp slt i64 %25, %13
br i1 %26, label %17, label %33
27: ; preds = %17, %17
%28 = trunc i64 %19 to i32
%29 = icmp slt i32 %28, %1
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = tail call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%32 = icmp eq i32 %31, -1
br i1 %32, label %36, label %14
33: ; preds = %22
%34 = add nsw i32 %15, 1
%35 = call i32 @llvm.smax.i32(i32 %1, i32 %34)
br label %38
36: ; preds = %27, %30
%37 = trunc i64 %19 to i32
br label %38
38: ; preds = %36, %33, %7
%39 = phi i32 [ 0, %7 ], [ %35, %33 ], [ %37, %36 ]
%40 = tail call i32 @free(i8* %9)
%41 = tail call i32 @fclose(i32* %3)
ret i32 %39
}