#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 size_t uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgetc(int /*<<< orphan*/ *);
char *malloc(size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
char *realloc(char *, size_t);
char *readWords(FILE *file) {
  size_t n = 20000;
  char *words = malloc(n * sizeof(char));
  memset(words, 0, (n * sizeof(char)));
  char c;
  (void)fgetc(file);
  for (uint32_t i = 0; i < n; i++) {
    c = (char)fgetc(file);
    if (c == EOF)
      break;
    if (i + 1 == n) {
      n *= 2;
      char *tmp = realloc(words, (n * sizeof(char)));
      if (!tmp)
        exit(2);
      words = tmp;
    }
    words[i] = c;
  }
  char *tmp = words;
  while (*tmp) {
    *tmp = (*tmp == '"' || *tmp == ',') ? '\0' : *tmp;
    tmp++;
  }
  *++tmp = EOF;
  fclose(file);
  return words;
}


x86 assembly (clang, -O0):
<readWords>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x4e20,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
shl    $0x0,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
shl    $0x0,%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    124d <readWords+0xed>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
mov    0x2e1a(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11de <readWords+0x7e>
jmp    124d <readWords+0xed>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
cmp    -0x10(%rbp),%rax
jne    122e <readWords+0xce>
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
shl    $0x0,%rsi
call   1070 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1226 <readWords+0xc6>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x19(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11a9 <readWords+0x49>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     12b2 <readWords+0x152>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
je     1282 <readWords+0x122>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
jne    128c <readWords+0x12c>
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
jmp    1296 <readWords+0x136>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1255 <readWords+0xf5>
mov    0x2d2f(%rip),%rax
mov    (%rax),%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,0x1(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readWords>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x4e20,%r12d
mov    $0x4e20,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
xor    %r13d,%r13d
mov    $0x4e20,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
jmp    11ac <readWords+0x4c>
nopl   (%rax)
mov    %bl,(%r15,%r13,1)
mov    %rbp,%r13
cmp    %r12,%rbp
jae    11eb <readWords+0x8b>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %rax,%rbx
mov    0x2e2a(%rip),%rax
cmp    %bl,(%rax)
je     11eb <readWords+0x8b>
lea    0x1(%r13),%rbp
cmp    %r12,%rbp
jne    11a0 <readWords+0x40>
add    %r12,%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <realloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11a0 <readWords+0x40>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    %r15,%rax
jmp    11f8 <readWords+0x98>
mov    %ecx,%edx
mov    %dl,(%rax)
add    $0x1,%rax
movzbl (%rax),%ecx
xor    %edx,%edx
cmp    $0x22,%cl
je     11f2 <readWords+0x92>
cmp    $0x2c,%cl
je     11f2 <readWords+0x92>
test   %cl,%cl
jne    11f0 <readWords+0x90>
mov    0x2dd6(%rip),%rcx
mov    (%rcx),%cl
mov    %cl,0x1(%rax)
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i8 0
define i8* @readWords(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
store i32* %0, i32** %2
store i64 20000, i64* %3
%9 = load i64, i64* %3
%10 = mul i64 %9, 1
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = load i64, i64* %3
%14 = mul i64 %13, 1
%15 = call i32 @memset(i8* %12, i32 0, i64 %14)
%16 = load i32*, i32** %2
%17 = call i64 @fgetc(i32* %16)
store i64 0, i64* %6
br label %18
18: ; preds = %55, %1
%19 = load i64, i64* %6
%20 = load i64, i64* %3
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %58
22: ; preds = %18
%23 = load i32*, i32** %2
%24 = call i64 @fgetc(i32* %23)
%25 = trunc i64 %24 to i8
store i8 %25, i8* %5
%26 = load i8, i8* %5
%27 = sext i8 %26 to i32
%28 = load i8, i8* @EOF
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %27, %29
br i1 %30, label %31, label %32
31: ; preds = %22
br label %58
32: ; preds = %22
%33 = load i64, i64* %6
%34 = add i64 %33, 1
%35 = load i64, i64* %3
%36 = icmp eq i64 %34, %35
br i1 %36, label %37, label %50
37: ; preds = %32
%38 = load i64, i64* %3
%39 = mul i64 %38, 2
store i64 %39, i64* %3
%40 = load i8*, i8** %4
%41 = load i64, i64* %3
%42 = mul i64 %41, 1
%43 = call i8* @realloc(i8* %40, i64 %42)
store i8* %43, i8** %7
%44 = load i8*, i8** %7
%45 = icmp ne i8* %44, null
br i1 %45, label %48, label %46
46: ; preds = %37
%47 = call i32 @exit(i32 2)
unreachable
48: ; preds = %37
%49 = load i8*, i8** %7
store i8* %49, i8** %4
br label %50
50: ; preds = %48, %32
%51 = load i8, i8* %5
%52 = load i8*, i8** %4
%53 = load i64, i64* %6
%54 = getelementptr inbounds i8, i8* %52, i64 %53
store i8 %51, i8* %54
br label %55
55: ; preds = %50
%56 = load i64, i64* %6
%57 = add i64 %56, 1
store i64 %57, i64* %6
br label %18
58: ; preds = %31, %18
%59 = load i8*, i8** %4
store i8* %59, i8** %8
br label %60
60: ; preds = %79, %58
%61 = load i8*, i8** %8
%62 = load i8, i8* %61
%63 = icmp ne i8 %62, 0
br i1 %63, label %64, label %85
64: ; preds = %60
%65 = load i8*, i8** %8
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %67, 34
br i1 %68, label %74, label %69
69: ; preds = %64
%70 = load i8*, i8** %8
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 44
br i1 %73, label %74, label %75
74: ; preds = %69, %64
br label %79
75: ; preds = %69
%76 = load i8*, i8** %8
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
br label %79
79: ; preds = %75, %74
%80 = phi i32 [ 0, %74 ], [ %78, %75 ]
%81 = trunc i32 %80 to i8
%82 = load i8*, i8** %8
store i8 %81, i8* %82
%83 = load i8*, i8** %8
%84 = getelementptr inbounds i8, i8* %83, i32 1
store i8* %84, i8** %8
br label %60
85: ; preds = %60
%86 = load i8, i8* @EOF
%87 = load i8*, i8** %8
%88 = getelementptr inbounds i8, i8* %87, i32 1
store i8* %88, i8** %8
store i8 %86, i8* %88
%89 = load i32*, i32** %2
%90 = call i32 @fclose(i32* %89)
%91 = load i8*, i8** %4
ret i8* %91
}

LLVM IR (-O2):
@EOF = global i8 0
define i8* @readWords(i32* nocapture %0) {
%2 = tail call dereferenceable_or_null(20000) i8* @malloc(i64 20000)
%3 = tail call i32 @memset(i8* %2, i32 0, i64 20000)
%4 = tail call i64 @fgetc(i32* %0)
br label %5
5: ; preds = %1, %22
%6 = phi i64 [ 20000, %1 ], [ %24, %22 ]
%7 = phi i64 [ 0, %1 ], [ %14, %22 ]
%8 = phi i8* [ %2, %1 ], [ %23, %22 ]
%9 = tail call i64 @fgetc(i32* %0)
%10 = trunc i64 %9 to i8
%11 = load i8, i8* @EOF
%12 = icmp eq i8 %11, %10
br i1 %12, label %27, label %13
13: ; preds = %5
%14 = add nuw i64 %7, 1
%15 = icmp eq i64 %14, %6
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = shl i64 %6, 1
%18 = tail call i8* @realloc(i8* %8, i64 %17)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = tail call i32 @exit(i32 2)
unreachable
22: ; preds = %16, %13
%23 = phi i8* [ %8, %13 ], [ %18, %16 ]
%24 = phi i64 [ %6, %13 ], [ %17, %16 ]
%25 = getelementptr inbounds i8, i8* %23, i64 %7
store i8 %10, i8* %25
%26 = icmp ult i64 %14, %24
br i1 %26, label %5, label %27
27: ; preds = %5, %22
%28 = phi i8* [ %8, %5 ], [ %23, %22 ]
br label %29
29: ; preds = %33, %27
%30 = phi i8* [ %28, %27 ], [ %35, %33 ]
%31 = load i8, i8* %30
switch i8 %31, label %32 [
i8 0, label %36
i8 34, label %33
i8 44, label %33
]
32: ; preds = %29
br label %33
33: ; preds = %29, %29, %32
%34 = phi i8 [ %31, %32 ], [ 0, %29 ], [ 0, %29 ]
store i8 %34, i8* %30
%35 = getelementptr inbounds i8, i8* %30, i64 1
br label %29
36: ; preds = %29
%37 = load i8, i8* @EOF
%38 = getelementptr inbounds i8, i8* %30, i64 1
store i8 %37, i8* %38
%39 = tail call i32 @fclose(i32* %0)
ret i8* %28
}