#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
scalar_t__ isalnum(int);
int /*<<< orphan*/ printf(char *, char *);
int getWords(char *filename, int word_size, char a[][word_size]) {
  FILE *srcf;
  int ch1, new_word = 1, word_count = 0, char_count = 0;
  srcf = fopen(filename, "r");
  if (srcf == NULL)
    printf("Cannot open %s for reading\n", filename);
  else {
    ch1 = getc(srcf);
    while (ch1 != EOF) {
      if (isalnum(ch1)) {
        new_word = 0;
        a[word_count][char_count] = ch1;
        char_count++;
      } else if (!new_word) {
        new_word = 1;
        char_count = 0;
        word_count++;
      }
      ch1 = getc(srcf);
    }
    fclose(srcf);
  }
  return (word_count);
}


x86 assembly (clang, -O0):
<getWords>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %rax,-0x38(%rbp)
movl   $0x1,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b3 <getWords+0x63>
mov    -0x8(%rbp),%rsi
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
jmp    1257 <getWords+0x107>
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%eax
je     124e <getWords+0xfe>
mov    -0x24(%rbp),%edi
call   1050 <isalnum@plt>
cmp    $0x0,%rax
je     1217 <getWords+0xc7>
mov    -0x38(%rbp),%rsi
movl   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   %rsi,%rcx
add    %rcx,%rax
movslq -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    123d <getWords+0xed>
cmpl   $0x0,-0x28(%rbp)
jne    1238 <getWords+0xe8>
movl   $0x1,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    123d <getWords+0xed>
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x24(%rbp)
jmp    11bf <getWords+0x6f>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getWords>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
mov    %esi,%r12d
mov    %rdi,%rbx
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119a <getWords+0x4a>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <getc@plt>
mov    %eax,%ebx
mov    0x2e5e(%rip),%rax
xor    %ebp,%ebp
cmp    (%rax),%ebx
jne    11bc <getWords+0x6c>
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    11ab <getWords+0x5b>
lea    0xe61(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12d,%r12d
mov    $0x1,%r14d
xor    %r13d,%r13d
xor    %ebp,%ebp
jmp    11f9 <getWords+0xa9>
nopl   0x0(%rax)
xor    %eax,%eax
test   %r14d,%r14d
sete   %al
cmove  %r14d,%r13d
add    %eax,%ebp
mov    $0x1,%r14d
mov    %r15,%rdi
call   1070 <getc@plt>
mov    %eax,%ebx
mov    0x2df3(%rip),%rax
cmp    (%rax),%ebx
je     1190 <getWords+0x40>
mov    %ebx,%edi
call   1050 <isalnum@plt>
test   %rax,%rax
je     11d0 <getWords+0x80>
movslq %ebp,%rax
imul   %r12,%rax
add    (%rsp),%rax
movslq %r13d,%r13
mov    %bl,0x0(%r13,%rax,1)
add    $0x1,%r13d
xor    %r14d,%r14d
jmp    11e4 <getWords+0x94>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"Cannot open %s for reading\0A\00"
@EOF = global i32 0
define i32 @getWords(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%12 = load i32, i32* %5
%13 = zext i32 %12 to i64
store i32 1, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%14 = load i8*, i8** %4
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %7
%16 = load i32*, i32** %7
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load i8*, i8** %4
%20 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %58
21: ; preds = %3
%22 = load i32*, i32** %7
%23 = call i32 @getc(i32* %22)
store i32 %23, i32* %8
br label %24
24: ; preds = %52, %21
%25 = load i32, i32* %8
%26 = load i32, i32* @EOF
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %55
28: ; preds = %24
%29 = load i32, i32* %8
%30 = call i64 @isalnum(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %45
32: ; preds = %28
store i32 0, i32* %9
%33 = load i32, i32* %8
%34 = trunc i32 %33 to i8
%35 = load i8*, i8** %6
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = mul nsw i64 %37, %13
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %34, i8* %42
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
store i32 %44, i32* %11
br label %52
45: ; preds = %28
%46 = load i32, i32* %9
%47 = icmp ne i32 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %45
store i32 1, i32* %9
store i32 0, i32* %11
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
br label %51
51: ; preds = %48, %45
br label %52
52: ; preds = %51, %32
%53 = load i32*, i32** %7
%54 = call i32 @getc(i32* %53)
store i32 %54, i32* %8
br label %24
55: ; preds = %24
%56 = load i32*, i32** %7
%57 = call i32 @fclose(i32* %56)
br label %58
58: ; preds = %55, %18
%59 = load i32, i32* %10
ret i32 %59
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"Cannot open %s for reading\0A\00"
@EOF = global i32 0
define i32 @getWords(i8* %0, i32 %1, i8* nocapture writeonly %2) {
%4 = zext i32 %1 to i64
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %43
9: ; preds = %3
%10 = tail call i32 @getc(i32* %5)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %40, label %13
13: ; preds = %9, %33
%14 = phi i32 [ %36, %33 ], [ 0, %9 ]
%15 = phi i32 [ %35, %33 ], [ 0, %9 ]
%16 = phi i32 [ %34, %33 ], [ 1, %9 ]
%17 = phi i32 [ %37, %33 ], [ %10, %9 ]
%18 = tail call i64 @isalnum(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %13
%21 = trunc i32 %17 to i8
%22 = sext i32 %15 to i64
%23 = mul nsw i64 %22, %4
%24 = getelementptr inbounds i8, i8* %2, i64 %23
%25 = sext i32 %14 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8 %21, i8* %26
%27 = add nsw i32 %14, 1
br label %33
28: ; preds = %13
%29 = icmp eq i32 %16, 0
%30 = zext i1 %29 to i32
%31 = add nsw i32 %15, %30
%32 = select i1 %29, i32 0, i32 %14
br label %33
33: ; preds = %28, %20
%34 = phi i32 [ 0, %20 ], [ 1, %28 ]
%35 = phi i32 [ %15, %20 ], [ %31, %28 ]
%36 = phi i32 [ %27, %20 ], [ %32, %28 ]
%37 = tail call i32 @getc(i32* %5)
%38 = load i32, i32* @EOF
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %13
40: ; preds = %33, %9
%41 = phi i32 [ 0, %9 ], [ %35, %33 ]
%42 = tail call i32 @fclose(i32* %5)
br label %43
43: ; preds = %40, %7
%44 = phi i32 [ 0, %7 ], [ %41, %40 ]
ret i32 %44
}