#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isalnum(char);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main() {
  int i, inWord;
  int count = 0, totalwords = 0;
  char row[100], zbor[20];
  FILE *ptr;
  if ((ptr = fopen("D:\\_strukturno\\vlez.txt", "r")) == NULL) {
    printf("Vlez.txt can not be opened!");
    return -1;
  }
  while (fgets(row, 100, ptr) != NULL) {
    inWord = count = 0;
    for (i = 0; i < strlen(row); i++) {
      if (isalnum(row[i])) {
        if (!inWord) {
          inWord = 1;
        }
        zbor[count++] = row[i];
      } else if (inWord) {
        inWord = 0;
        zbor[count] = '\0';
        totalwords++;
        count = 0;
      }
    }
  }
  printf("Total words: %d\n", totalwords);
  fclose(ptr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe79(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0xa8(%rbp)
cmp    $0x0,%rax
jne    11be <main+0x5e>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d1 <main+0x171>
jmp    11c3 <main+0x63>
lea    -0x80(%rbp),%rdi
mov    -0xa8(%rbp),%rdx
mov    $0x64,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12ad <main+0x14d>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xac(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0xac(%rbp),%eax
cmp    %ecx,%eax
jge    12a8 <main+0x148>
movslq -0x8(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%edi
call   1060 <isalnum@plt>
cmp    $0x0,%rax
je     1263 <main+0x103>
cmpl   $0x0,-0xc(%rbp)
jne    1242 <main+0xe2>
movl   $0x1,-0xc(%rbp)
movslq -0x8(%rbp),%rax
mov    -0x80(%rbp,%rax,1),%cl
mov    -0x10(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
cltq
mov    %cl,-0xa0(%rbp,%rax,1)
jmp    1295 <main+0x135>
cmpl   $0x0,-0xc(%rbp)
je     1290 <main+0x130>
movl   $0x0,-0xc(%rbp)
movslq -0x10(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
jmp    1295 <main+0x135>
jmp    129a <main+0x13a>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11f7 <main+0x97>
jmp    11c3 <main+0x63>
mov    -0x14(%rbp),%esi
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xa8(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe8b(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1240 <main+0xe0>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
mov    $0x0,%ebp
test   %rax,%rax
je     1224 <main+0xc4>
xor    %ebp,%ebp
mov    %rsp,%r13
mov    $0x1,%r12d
jmp    11d5 <main+0x75>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1224 <main+0xc4>
mov    %r13,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11c0 <main+0x60>
xor    %ebx,%ebx
xor    %r14d,%r14d
jmp    120d <main+0xad>
nopl   0x0(%rax,%rax,1)
cmp    $0x1,%r14d
sbb    $0xffffffff,%ebp
xor    %r14d,%r14d
add    $0x1,%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11c0 <main+0x60>
movsbl (%rsp,%rbx,1),%edi
call   1060 <isalnum@plt>
test   %rax,%rax
je     11f0 <main+0x90>
test   %r14d,%r14d
cmove  %r12d,%r14d
jmp    11fa <main+0x9a>
lea    0xe0b(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1253 <main+0xf3>
lea    0xdd3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"D:\\_strukturno\\vlez.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"Vlez.txt can not be opened!\00"
@.str.3 = [17 x i8] c"Total words: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100 x i8]
%7 = alloca [20 x i8]
%8 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %5
%9 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %8
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %65
13: ; preds = %0
br label %14
14: ; preds = %59, %13
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%16 = load i32*, i32** %8
%17 = call i32* @fgets(i8* %15, i32 100, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %60
19: ; preds = %14
store i32 0, i32* %4
store i32 0, i32* %3
store i32 0, i32* %2
br label %20
20: ; preds = %56, %19
%21 = load i32, i32* %2
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %59
25: ; preds = %20
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = call i64 @isalnum(i8 signext %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %45
32: ; preds = %25
%33 = load i32, i32* %3
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %32
store i32 1, i32* %3
br label %36
36: ; preds = %35, %32
%37 = load i32, i32* %2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 %43
store i8 %40, i8* %44
br label %55
45: ; preds = %25
%46 = load i32, i32* %3
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %54
48: ; preds = %45
store i32 0, i32* %3
%49 = load i32, i32* %4
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 %50
store i8 0, i8* %51
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
store i32 0, i32* %4
br label %54
54: ; preds = %48, %45
br label %55
55: ; preds = %54, %36
br label %56
56: ; preds = %55
%57 = load i32, i32* %2
%58 = add nsw i32 %57, 1
store i32 %58, i32* %2
br label %20
59: ; preds = %20
br label %14
60: ; preds = %14
%61 = load i32, i32* %5
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %61)
%63 = load i32*, i32** %8
%64 = call i32 @fclose(i32* %63)
store i32 0, i32* %1
br label %65
65: ; preds = %60, %11
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
@.str = [24 x i8] c"D:\\_strukturno\\vlez.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"Vlez.txt can not be opened!\00"
@.str.3 = [17 x i8] c"Total words: %d\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 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 %8, label %5
5: ; preds = %0
%6 = call i32* @fgets(i8* %2, i32 100, i32* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %40, label %14
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %44
10: ; preds = %33, %14
%11 = phi i32 [ %15, %14 ], [ %35, %33 ]
%12 = call i32* @fgets(i8* %2, i32 100, i32* %3)
%13 = icmp eq i32* %12, null
br i1 %13, label %40, label %14
14: ; preds = %5, %10
%15 = phi i32 [ %11, %10 ], [ 0, %5 ]
%16 = call i32 @strlen(i8* %2)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %10
18: ; preds = %14, %33
%19 = phi i64 [ %36, %33 ], [ 0, %14 ]
%20 = phi i32 [ %35, %33 ], [ %15, %14 ]
%21 = phi i32 [ %34, %33 ], [ 0, %14 ]
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %19
%23 = load i8, i8* %22
%24 = call i64 @isalnum(i8 signext %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %18
%27 = icmp eq i32 %21, 0
%28 = select i1 %27, i32 1, i32 %21
br label %33
29: ; preds = %18
%30 = icmp ne i32 %21, 0
%31 = zext i1 %30 to i32
%32 = add nsw i32 %20, %31
br label %33
33: ; preds = %29, %26
%34 = phi i32 [ %28, %26 ], [ 0, %29 ]
%35 = phi i32 [ %20, %26 ], [ %32, %29 ]
%36 = add nuw nsw i64 %19, 1
%37 = call i32 @strlen(i8* %2)
%38 = sext i32 %37 to i64
%39 = icmp slt i64 %36, %38
br i1 %39, label %18, label %10
40: ; preds = %10, %5
%41 = phi i32 [ 0, %5 ], [ %11, %10 ]
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = call i32 @fclose(i32* %3)
br label %44
44: ; preds = %40, %8
%45 = phi i32 [ -1, %8 ], [ 0, %40 ]
ret i32 %45
}