#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 countCharacters(char *);
int countCharactersWithSpace(char *);
int countWords(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, char **);
int /*<<< orphan*/ *stdin;
void main() {
  FILE *fp;
  char buffer[256];
  char *userInput = malloc(512);
  char FileName[512 / 2];
  int characters = 0;
  int charactersWithSpace = 0;
  int words = 0;
  printf("Hello Welcome To My Program");
  printf("\nType filename Make user add extension like .txt");
  printf("\nInput: ");
  fgets(buffer, 512 / 2, stdin);
  sscanf(buffer, "%s", &FileName);
  fp = fopen(FileName, "r");
  if (fp == NULL) {
    perror("Error: ");
  } else {
    fgets(userInput, 512, fp);
  }
  fclose(fp);
  words = countWords(userInput);
  characters = countCharacters(userInput);
  charactersWithSpace = countCharactersWithSpace(userInput);
  printf("\nAmount of words from input is: %d", words);
  printf("\nAmount of Characters without spacing from input is: %d",
         characters);
  printf("\nAmount of Characters with spacing from input is: %d",
         charactersWithSpace);
  free(userInput);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    $0x200,%edi
call   1090 <malloc@plt>
mov    %rax,-0x118(%rbp)
movl   $0x0,-0x224(%rbp)
movl   $0x0,-0x228(%rbp)
movl   $0x0,-0x22c(%rbp)
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2dc6(%rip),%rax
mov    (%rax),%rdx
mov    $0x100,%esi
call   1080 <fgets@plt>
lea    -0x110(%rbp),%rdi
lea    -0x220(%rbp),%rdx
lea    0xe12(%rip),%rsi
call   10a0 <sscanf@plt>
lea    -0x220(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    127c <main+0xcc>
lea    0xde9(%rip),%rdi
call   10d0 <perror@plt>
jmp    1291 <main+0xe1>
mov    -0x118(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x200,%esi
call   1080 <fgets@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x118(%rbp),%rdi
call   1070 <countWords@plt>
mov    %eax,-0x22c(%rbp)
mov    -0x118(%rbp),%rdi
call   10b0 <countCharacters@plt>
mov    %eax,-0x224(%rbp)
mov    -0x118(%rbp),%rdi
call   1040 <countCharactersWithSpace@plt>
mov    %eax,-0x228(%rbp)
mov    -0x22c(%rbp),%esi
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x224(%rbp),%esi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x228(%rbp),%esi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x118(%rbp),%rdi
call   1030 <free@plt>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    $0x200,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
lea    0xe2f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe3d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe60(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%rdx
lea    0x100(%rsp),%r15
mov    %r15,%rdi
mov    $0x100,%esi
call   1080 <fgets@plt>
lea    0xe3c(%rip),%rsi
mov    %rsp,%rbx
mov    %r15,%rdi
mov    %rbx,%rdx
call   10a0 <sscanf@plt>
lea    0xe2a(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12bd <main+0x10d>
mov    %r14,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1070 <countWords@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   10b0 <countCharacters@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <countCharactersWithSpace@plt>
mov    %eax,%r15d
lea    0xde6(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdf9(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe21(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd97(%rip),%rdi
call   10d0 <perror@plt>
jmp    124f <main+0x9f>

LLVM IR (-O0):
@.str = [28 x i8] c"Hello Welcome To My Program\00"
@.str.1 = [49 x i8] c"\0AType filename Make user add extension like .txt\00"
@.str.2 = [9 x i8] c"\0AInput: \00"
@stdin = global i32* null
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [8 x i8] c"Error: \00"
@.str.6 = [35 x i8] c"\0AAmount of words from input is: %d\00"
@.str.7 = [56 x i8] c"\0AAmount of Characters without spacing from input is: %d\00"
@.str.8 = [53 x i8] c"\0AAmount of Characters with spacing from input is: %d\00"
define void @main() {
%1 = alloca i32*
%2 = alloca [256 x i8]
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = call i8* @malloc(i32 512)
store i8* %8, i8** %3
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%13 = load i32*, i32** @stdin
%14 = call i32 @fgets(i8* %12, i32 256, i32* %13)
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%16 = bitcast [256 x i8]* %4 to i8**
%17 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %16)
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %19, i32** %1
%20 = load i32*, i32** %1
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %28
24: ; preds = %0
%25 = load i8*, i8** %3
%26 = load i32*, i32** %1
%27 = call i32 @fgets(i8* %25, i32 512, i32* %26)
br label %28
28: ; preds = %24, %22
%29 = load i32*, i32** %1
%30 = call i32 @fclose(i32* %29)
%31 = load i8*, i8** %3
%32 = call i32 @countWords(i8* %31)
store i32 %32, i32* %7
%33 = load i8*, i8** %3
%34 = call i32 @countCharacters(i8* %33)
store i32 %34, i32* %5
%35 = load i8*, i8** %3
%36 = call i32 @countCharactersWithSpace(i8* %35)
store i32 %36, i32* %6
%37 = load i32, i32* %7
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %5
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.7, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.8, i64 0, i64 0), i32 %41)
%43 = load i8*, i8** %3
%44 = call i32 @free(i8* %43)
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"Hello Welcome To My Program\00"
@.str.1 = [49 x i8] c"\0AType filename Make user add extension like .txt\00"
@.str.2 = [9 x i8] c"\0AInput: \00"
@stdin = global i32* null
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [8 x i8] c"Error: \00"
@.str.6 = [35 x i8] c"\0AAmount of words from input is: %d\00"
@.str.7 = [56 x i8] c"\0AAmount of Characters without spacing from input is: %d\00"
@.str.8 = [53 x i8] c"\0AAmount of Characters with spacing from input is: %d\00"
define void @main() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32*, i32** @stdin
%10 = call i32 @fgets(i8* %3, i32 256, i32* %9)
%11 = bitcast [256 x i8]* %2 to i8**
%12 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %11)
%13 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %19
17: ; preds = %0
%18 = call i32 @fgets(i8* %4, i32 512, i32* %13)
br label %19
19: ; preds = %17, %15
%20 = call i32 @fclose(i32* %13)
%21 = call i32 @countWords(i8* %4)
%22 = call i32 @countCharacters(i8* %4)
%23 = call i32 @countCharactersWithSpace(i8* %4)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32 %21)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.7, i64 0, i64 0), i32 %22)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.8, i64 0, i64 0), i32 %23)
%27 = call i32 @free(i8* %4)
ret void
}