#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  FILE *fichero;
  char x;
  int espacios = 0, no_espacios = 0;
  fichero = fopen("datos2.txt", "r");
  if (fichero == NULL) {
    printf("El fichero no se ha abierto correctamente.");
  } else {
    while (!feof(fichero)) {
      fscanf(fichero, "%c", &x);
      if ((x != ' ') && (x != '\n')) {
        no_espacios++;
      } else if (x == ' ') {
        espacios++;
      }
    }
  }
  fclose(fichero);
  printf("\nHay %d espacios y %d no-espacios.\n", espacios, no_espacios);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe8c(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a2 <main+0x52>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1226 <main+0xd6>
jmp    11a7 <main+0x57>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c5 <main+0x75>
jmp    1221 <main+0xd1>
mov    -0x10(%rbp),%rdi
lea    0xe68(%rip),%rsi
lea    -0x11(%rbp),%rdx
call   1050 <fscanf@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x20,%eax
je     1201 <main+0xb1>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
je     1201 <main+0xb1>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    121c <main+0xcc>
movsbl -0x11(%rbp),%eax
cmp    $0x20,%eax
jne    1217 <main+0xc7>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    121c <main+0xcc>
jmp    11a7 <main+0x57>
jmp    1226 <main+0xd6>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9d(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d0 <main+0x80>
mov    %rbx,%rdi
call   1060 <feof@plt>
xor    %r14d,%r14d
mov    $0x0,%ebp
test   %eax,%eax
jne    11e3 <main+0x93>
xor    %ebp,%ebp
lea    0xea4(%rip),%r15
lea    0xf(%rsp),%r12
xor    %r14d,%r14d
jmp    11af <main+0x5f>
xchg   %ax,%ax
add    $0x1,%ebp
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11e3 <main+0x93>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
movzbl 0xf(%rsp),%eax
cmp    $0xa,%al
je     11a3 <main+0x53>
cmp    $0x20,%al
jne    11a0 <main+0x50>
add    $0x1,%r14d
jmp    11a3 <main+0x53>
lea    0xe36(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe49(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"datos2.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [43 x i8] c"El fichero no se ha abierto correctamente.\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [36 x i8] c"\0AHay %d espacios y %d no-espacios.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %5
%6 = 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* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %40
11: ; preds = %0
br label %12
12: ; preds = %38, %11
%13 = load i32*, i32** %2
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %39
17: ; preds = %12
%18 = load i32*, i32** %2
%19 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%20 = load i8, i8* %3
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 32
br i1 %22, label %23, label %30
23: ; preds = %17
%24 = load i8, i8* %3
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 10
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %38
30: ; preds = %23, %17
%31 = load i8, i8* %3
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 32
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %37
37: ; preds = %34, %30
br label %38
38: ; preds = %37, %27
br label %12
39: ; preds = %12
br label %40
40: ; preds = %39, %9
%41 = load i32*, i32** %2
%42 = call i32 @fclose(i32* %41)
%43 = load i32, i32* %4
%44 = load i32, i32* %5
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %43, i32 %44)
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str = [11 x i8] c"datos2.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [43 x i8] c"El fichero no se ha abierto correctamente.\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [36 x i8] c"\0AHay %d espacios y %d no-espacios.\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = 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))
%3 = icmp eq i32* %2, null
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = call i32 @feof(i32* %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %23
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %23
9: ; preds = %4, %18
%10 = phi i32 [ %20, %18 ], [ 0, %4 ]
%11 = phi i32 [ %19, %18 ], [ 0, %4 ]
%12 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%13 = load i8, i8* %1
switch i8 %13, label %14 [
i8 32, label %16
i8 10, label %18
]
14: ; preds = %9
%15 = add nsw i32 %10, 1
br label %18
16: ; preds = %9
%17 = add nsw i32 %11, 1
br label %18
18: ; preds = %9, %16, %14
%19 = phi i32 [ %11, %14 ], [ %17, %16 ], [ %11, %9 ]
%20 = phi i32 [ %15, %14 ], [ %10, %16 ], [ %10, %9 ]
%21 = call i32 @feof(i32* %2)
%22 = icmp eq i32 %21, 0
br i1 %22, label %9, label %23
23: ; preds = %18, %4, %7
%24 = phi i32 [ 0, %7 ], [ 0, %4 ], [ %19, %18 ]
%25 = phi i32 [ 0, %7 ], [ 0, %4 ], [ %20, %18 ]
%26 = call i32 @fclose(i32* %2)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %24, i32 %25)
ret i32 0
}