#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 */

/* Variables and functions */
int /*<<< orphan*/ file2arr(char *, char *);
int ocurrencias(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main(int argc, char *argv[]) {
  char *filename;
  char *searchStr;
  char buffer[1024];
  printf("\t\tPrograma que Busca incidencias de una Frase en un Archivo.\n\n");
  if (argc != 2) {
    printf("Introduce el nombre del archivo sin espacios: ");
    scanf(" %s", filename);
  } else {
    filename = argv[1];
  }
  file2arr(filename, buffer);
  if (argc != 3) {
    printf("Introduce un String a buscar: ");
    scanf(" %s", &searchStr);
  } else {
    searchStr = argv[2];
  }
  printf("La palabra %s, aparece %d veces en el archivo %s.\n", searchStr,
         ocurrencias(searchStr, buffer), filename);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
je     1196 <main+0x56>
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xee4(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
jmp    11a2 <main+0x62>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1030 <file2arr@plt>
cmpl   $0x3,-0x8(%rbp)
je     11e1 <main+0xa1>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9d(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
jmp    11ed <main+0xad>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x428(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1060 <ocurrencias@plt>
mov    -0x428(%rbp),%rsi
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xf1e(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x2,%ebp
jne    1184 <main+0x34>
mov    0x8(%rbx),%r14
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1040 <file2arr@plt>
jmp    11ba <main+0x6a>
lea    0xe75(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0x10(%rsp),%rsi
call   1040 <file2arr@plt>
cmp    $0x3,%ebp
jne    11ba <main+0x6a>
mov    0x10(%rbx),%rbx
mov    %rbx,0x8(%rsp)
jmp    11e0 <main+0x90>
lea    0xe72(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe60(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x8(%rsp),%rbx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <ocurrencias@plt>
lea    0xe5e(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [63 x i8] c"\09\09Programa que Busca incidencias de una Frase en un Archivo.\0A\0A\00"
@.str.1 = [47 x i8] c"Introduce el nombre del archivo sin espacios: \00"
@.str.2 = [4 x i8] c" %s\00"
@.str.3 = [31 x i8] c"Introduce un String a buscar: \00"
@.str.4 = [51 x i8] c"La palabra %s, aparece %d veces en el archivo %s.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%14 = load i8*, i8** %6
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %20
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %6
br label %20
20: ; preds = %16, %12
%21 = load i8*, i8** %6
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%23 = call i32 @file2arr(i8* %21, i8* %22)
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 3
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %7)
br label %33
29: ; preds = %20
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
store i8* %32, i8** %7
br label %33
33: ; preds = %29, %26
%34 = load i8*, i8** %7
%35 = load i8*, i8** %7
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%37 = call i32 @ocurrencias(i8* %35, i8* %36)
%38 = load i8*, i8** %6
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %34, i32 %37, i8* %38)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [47 x i8] c"Introduce el nombre del archivo sin espacios: \00"
@.str.2 = [4 x i8] c" %s\00"
@.str.3 = [31 x i8] c"Introduce un String a buscar: \00"
@.str.4 = [51 x i8] c"La palabra %s, aparece %d veces en el archivo %s.\0A\00"
@str = [62 x i8] c"\09\09Programa que Busca incidencias de una Frase en un Archivo.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = bitcast i8** %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0))
%8 = icmp eq i32 %0, 2
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @file2arr(i8* %11, i8* %6)
br label %18
13: ; preds = %2
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* undef)
%16 = call i32 @file2arr(i8* undef, i8* %6)
%17 = icmp eq i32 %0, 3
br i1 %17, label %23, label %18
18: ; preds = %9, %13
%19 = phi i8* [ %11, %9 ], [ undef, %13 ]
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %3)
%22 = load i8*, i8** %3
br label %26
23: ; preds = %13
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
store i8* %25, i8** %3
br label %26
26: ; preds = %23, %18
%27 = phi i8* [ %25, %23 ], [ %22, %18 ]
%28 = phi i8* [ undef, %23 ], [ %19, %18 ]
%29 = call i32 @ocurrencias(i8* %27, i8* %6)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %27, i32 %29, i8* %28)
ret i32 0
}