#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 scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ read(int, char *, int);
int main(int argc, char *argv[]) {
  int fd, cont = 0, indice = 0, cont_linea = 1, linea;
  char caracter;
  ssize_t cant;
  if (argc < 3) {
    exit(0);
  }
  fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    perror("Error al abrir el archivo");
    exit(-1);
  }
  do {
    cant = read(fd, (char *)&caracter, 1);
    if (caracter == '\n')
      cont_linea++;
    if (caracter == argv[2][indice]) {
      indice++;
      if (argv[2][indice] == '\0') {
        indice = 0;
        cont++;
        linea = cont_linea;
        printf("Frase detectada en linea %d\n", linea);
      }
    } else {
      indice = 0;
    }
  } while (cant > 0);
  printf("La cantidad de veces que encontro la frase es %d\n", cont);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    118c <main+0x3c>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c5 <main+0x75>
lea    0xe4a(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    11ca <main+0x7a>
mov    -0x14(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %rax,-0x30(%rbp)
movsbl -0x25(%rbp),%eax
cmp    $0xa,%eax
jne    11f5 <main+0xa5>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movsbl -0x25(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    0x10(%rcx),%rcx
movslq -0x1c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    125d <main+0x10d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1258 <main+0x108>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xdc7(%rip),%rdi
call   1030 <printf@plt>
jmp    1264 <main+0x114>
movl   $0x0,-0x1c(%rbp)
jmp    1269 <main+0x119>
cmpq   $0x0,-0x30(%rbp)
jg     11ca <main+0x7a>
mov    -0x18(%rbp),%esi
lea    0xdb9(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jle    1216 <main+0xc6>
mov    %rsi,%r13
mov    0x8(%rsi),%rdi
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     121d <main+0xcd>
mov    %eax,%ebp
mov    $0x1,%ebx
xor    %r14d,%r14d
movl   $0x0,0x4(%rsp)
jmp    11b0 <main+0x60>
addl   $0x1,0x4(%rsp)
lea    0xe79(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %r14d,%r14d
test   %r12,%r12
jle    11f5 <main+0xa5>
mov    %ebx,%r15d
mov    %ebp,%edi
lea    0x3(%rsp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %rax,%r12
movzbl 0x3(%rsp),%ecx
xor    %ebx,%ebx
cmp    $0xa,%cl
sete   %bl
add    %r15d,%ebx
mov    0x10(%r13),%rax
movslq %r14d,%r14
cmp    (%rax,%r14,1),%cl
jne    11a8 <main+0x58>
cmpb   $0x0,0x1(%rax,%r14,1)
je     1195 <main+0x45>
add    $0x1,%r14
test   %r12,%r12
jg     11b0 <main+0x60>
lea    0xe3b(%rip),%rdi
mov    0x4(%rsp),%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xddc(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [26 x i8] c"Error al abrir el archivo\00"
@.str.1 = [29 x i8] c"Frase detectada en linea %d\0A\00"
@.str.2 = [50 x i8] c"La cantidad de veces que encontro la frase es %d\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 i32
%11 = alloca i8
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
store i32 1, i32* %9
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %17
br label %29
29: ; preds = %71, %28
%30 = load i32, i32* %6
%31 = call i64 @read(i32 %30, i8* %11, i32 1)
store i64 %31, i64* %12
%32 = load i8, i8* %11
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
br label %38
38: ; preds = %35, %29
%39 = load i8, i8* %11
%40 = sext i8 %39 to i32
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%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 = sext i8 %47 to i32
%49 = icmp eq i32 %40, %48
br i1 %49, label %50, label %69
50: ; preds = %38
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = load i8*, i8** %54
%56 = load i32, i32* %8
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %50
store i32 0, i32* %8
%63 = load i32, i32* %7
%64 = add nsw i32 %63, 1
store i32 %64, i32* %7
%65 = load i32, i32* %9
store i32 %65, i32* %10
%66 = load i32, i32* %10
%67 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %62, %50
br label %70
69: ; preds = %38
store i32 0, i32* %8
br label %70
70: ; preds = %69, %68
br label %71
71: ; preds = %70
%72 = load i64, i64* %12
%73 = icmp sgt i64 %72, 0
br i1 %73, label %29, label %74
74: ; preds = %71
%75 = load i32, i32* %7
%76 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i32 %75)
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [26 x i8] c"Error al abrir el archivo\00"
@.str.1 = [29 x i8] c"Frase detectada en linea %d\0A\00"
@.str.2 = [50 x i8] c"La cantidad de veces que encontro la frase es %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp slt i32 %0, 3
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = getelementptr inbounds i8*, i8** %1, i64 2
br label %18
15: ; preds = %7
%16 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %13, %41
%19 = phi i32 [ %42, %41 ], [ 0, %13 ]
%20 = phi i32 [ %26, %41 ], [ 1, %13 ]
%21 = phi i32 [ %43, %41 ], [ 0, %13 ]
%22 = call i64 @read(i32 %11, i8* %3, i32 1)
%23 = load i8, i8* %3
%24 = icmp eq i8 %23, 10
%25 = zext i1 %24 to i32
%26 = add nuw nsw i32 %20, %25
%27 = load i8*, i8** %14
%28 = sext i32 %19 to i64
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = load i8, i8* %29
%31 = icmp eq i8 %23, %30
br i1 %31, label %32, label %41
32: ; preds = %18
%33 = add nsw i32 %19, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %27, i64 %34
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = add nsw i32 %21, 1
%40 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %41
41: ; preds = %18, %38, %32
%42 = phi i32 [ 0, %38 ], [ %33, %32 ], [ 0, %18 ]
%43 = phi i32 [ %39, %38 ], [ %21, %32 ], [ %21, %18 ]
%44 = icmp sgt i64 %22, 0
br i1 %44, label %18, label %45
45: ; preds = %41
%46 = tail call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i32 %43)
ret i32 0
}