#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ findWords(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  FILE *fp;
  char *line = malloc(sizeof(char) * 100);
  if (line == NULL) {
    printf("%s", "Memoria insuficient!");
    exit(1);
  }
  if (argc != 2) {
    printf("Utilitzacio: %s <nom fitxer>\n", argv[0]);
    exit(2);
  }
  fp = fopen(argv[1], "r");
  if (!fp) {
    printf("%s", "Ha succeit un problema al obrir obrir el fitxer!");
    exit(3);
  }
  while (fgets(line, 100, fp) != NULL)
    findWords(line);
  fclose(fp);
  free(line);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cc <main+0x4c>
lea    0xe4a(%rip),%rdi
lea    0xe46(%rip),%rsi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
je     11f3 <main+0x73>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe34(%rip),%rdi
call   1050 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe34(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1233 <main+0xb3>
lea    0xde3(%rip),%rdi
lea    0xe14(%rip),%rsi
call   1050 <printf@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>
jmp    1238 <main+0xb8>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1262 <main+0xe2>
mov    -0x20(%rbp),%rdi
call   1070 <findWords@plt>
jmp    1238 <main+0xb8>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x64,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     11f6 <main+0x76>
cmp    $0x2,%ebp
jne    1213 <main+0x93>
mov    %rax,%rbx
mov    0x8(%r14),%rdi
lea    0xe8b(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     122c <main+0xac>
mov    %rax,%r14
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11df <main+0x5f>
mov    %rbx,%rdi
call   1070 <findWords@plt>
jmp    11c0 <main+0x40>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe03(%rip),%rdi
lea    0xdff(%rip),%rsi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    (%r14),%rsi
lea    0xdfb(%rip),%rdi
call   1050 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    0xdcd(%rip),%rdi
lea    0xdfe(%rip),%rsi
call   1050 <printf@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [21 x i8] c"Memoria insuficient!\00"
@.str.2 = [30 x i8] c"Utilitzacio: %s <nom fitxer>\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [49 x i8] c"Ha succeit un problema al obrir obrir el fitxer!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i8* @malloc(i32 100)
store i8* %8, i8** %7
%9 = load i8*, i8** %7
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 2)
unreachable
23: ; preds = %14
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %27, i32** %6
%28 = load i32*, i32** %6
%29 = icmp ne i32* %28, null
br i1 %29, label %33, label %30
30: ; preds = %23
%31 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @exit(i32 3)
unreachable
33: ; preds = %23
br label %34
34: ; preds = %39, %33
%35 = load i8*, i8** %7
%36 = load i32*, i32** %6
%37 = call i32* @fgets(i8* %35, i32 100, i32* %36)
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = load i8*, i8** %7
%41 = call i32 @findWords(i8* %40)
br label %34
42: ; preds = %34
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
%45 = load i8*, i8** %7
%46 = call i32 @free(i8* %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [21 x i8] c"Memoria insuficient!\00"
@.str.2 = [30 x i8] c"Utilitzacio: %s <nom fitxer>\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [49 x i8] c"Ha succeit un problema al obrir obrir el fitxer!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = icmp eq i32 %0, 2
br i1 %9, label %14, label %10
10: ; preds = %8
%11 = load i8*, i8** %1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 2)
unreachable
14: ; preds = %8
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = tail call i32* @fgets(i8* %3, i32 100, i32* %17)
%21 = icmp eq i32* %20, null
br i1 %21, label %29, label %25
22: ; preds = %14
%23 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0))
%24 = tail call i32 @exit(i32 3)
unreachable
25: ; preds = %19, %25
%26 = tail call i32 @findWords(i8* %3)
%27 = tail call i32* @fgets(i8* %3, i32 100, i32* %17)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %25
29: ; preds = %25, %19
%30 = tail call i32 @fclose(i32* %17)
%31 = tail call i32 @free(i8* %3)
ret i32 0
}