#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*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  int fd, cant, cont_2, cont_h, cont;
  char caracter;
  char texto[1024];
  int longitud, total;
  float num;
  char *concatenacion;
  char cadena[50];
  longitud = strlen(argv[2]);
  concatenacion = (char *)malloc(total + 1);
  strcat(concatenacion, argv[2]);
  printf("La cadena escrita es: %s\n", concatenacion);
  if (argc < 3) {
    perror("Ingresa una cadena");
    exit(-1);
  }
  fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    perror("Error al abrir el archivo");
    exit(-1);
  }
  do {
    cant = read(fd, (char *)&caracter, 1);
    printf("%c", caracter);
    if (caracter == ' ') {
      cont++;
    }
    if (caracter == texto[cont_2]) {
      cont_h++;
    }
  } while (cant > 0);
  printf("%d\n", cont_h);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x434(%rbp)
mov    -0x438(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x448(%rbp)
mov    -0x448(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1090 <strcat@plt>
mov    -0x448(%rbp),%rsi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x3,-0x8(%rbp)
jge    120a <main+0x8a>
lea    0xe1f(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1243 <main+0xc3>
lea    0xdf9(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
jmp    1248 <main+0xc8>
mov    -0x14(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
movsbl -0x25(%rbp),%esi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x25(%rbp),%eax
cmp    $0x20,%eax
jne    1284 <main+0x104>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movsbl -0x25(%rbp),%eax
movslq -0x1c(%rbp),%rcx
movsbl -0x430(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
jne    12a5 <main+0x125>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12aa <main+0x12a>
cmpl   $0x0,-0x18(%rbp)
jg     1248 <main+0xc8>
mov    -0x20(%rbp),%esi
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x480,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x10(%rsi),%rdi
call   1040 <strlen@plt>
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    0x10(%rbx),%rsi
mov    %rax,%rdi
call   10a0 <strcat@plt>
lea    0xe3f(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2,%r14d
jle    1230 <main+0xa0>
mov    0x8(%rbx),%rdi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     1239 <main+0xa9>
mov    %eax,%r15d
lea    0x7(%rsp),%r14
nop
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,%ebx
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
test   %ebx,%ebx
jg     11f0 <main+0x60>
lea    0xe2d(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde3(%rip),%rdi
jmp    1240 <main+0xb0>
lea    0xded(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

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

LLVM IR (-O2):
@.str = [26 x i8] c"La cadena escrita es: %s\0A\00"
@.str.1 = [19 x i8] c"Ingresa una cadena\00"
@O_RDONLY = global i32 0
@.str.2 = [26 x i8] c"Error al abrir el archivo\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = getelementptr inbounds i8*, i8** %1, i64 2
%5 = load i8*, i8** %4
%6 = tail call i32 @strlen(i8* %5)
%7 = tail call i64 @malloc(i32 undef)
%8 = inttoptr i64 %7 to i8*
%9 = load i8*, i8** %4
%10 = tail call i32 @strcat(i8* %8, i8* %9)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %8)
%12 = icmp slt i32 %0, 3
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = tail call i32 @open(i8* %18, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @exit(i32 -1)
unreachable
25: ; preds = %16, %25
%26 = phi i32 [ %31, %25 ], [ undef, %16 ]
%27 = call i32 @read(i32 %20, i8* %3, i32 1)
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = tail call i32 @putchar(i32 %29)
%31 = add nsw i32 %26, 1
%32 = icmp sgt i32 %27, 0
br i1 %32, label %25, label %33
33: ; preds = %25
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %31)
ret i32 0
}