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

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int count_syllables(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int findword(char *, size_t, int *, int *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ print_counts(char *, int, int, int);
char *realloc(char *, int);
size_t strnlen(char *, int);
int process(const char *input) {
  FILE *fp;
  char *buf;
  size_t readlen;
  uint32_t buflen = 4096;
  int start, end, wordlen, nsyls;
  end = 0;
  fp = fopen(input, "r");
  if (!fp)
    return -1;
  buf = malloc(buflen * sizeof(*buf));
  while (fgets(buf, 4096, fp) != NULL) {
    readlen = strnlen(buf, 4096);
    if (!((readlen > 0) && (buf[readlen - 1] == '\n'))) {
      fseek(fp, -buflen, SEEK_CUR);
      buflen *= 2;
      buf = realloc(buf, buflen);
    }
    start = 0;
    for (int i = 0; i < readlen; i++) {
      wordlen = findword(buf, readlen, &start, &end);
      if (wordlen == -1)
        continue;
      nsyls = count_syllables(buf + start, wordlen);
      print_counts(buf, start, end, nsyls);
      start = end + 1;
    }
  }
  fclose(fp);
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x1000,-0x2c(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f5 <process+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    132a <process+0x17a>
movslq -0x2c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1000,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     1311 <process+0x161>
mov    -0x20(%rbp),%rdi
mov    $0x1000,%esi
call   1080 <strnlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jbe    125a <process+0xaa>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     128a <process+0xda>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
sub    -0x2c(%rbp),%esi
mov    0x2d7e(%rip),%rax
mov    (%rax),%edx
call   10b0 <fseek@plt>
mov    -0x2c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   10c0 <realloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x40(%rbp)
movslq -0x40(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    130c <process+0x15c>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x34(%rbp),%rcx
call   1050 <findword@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    12cd <process+0x11d>
jmp    12fe <process+0x14e>
mov    -0x20(%rbp),%rdi
movslq -0x30(%rbp),%rax
add    %rax,%rdi
mov    -0x38(%rbp),%esi
call   1070 <count_syllables@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
mov    -0x3c(%rbp),%ecx
call   1030 <print_counts@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1298 <process+0xe8>
jmp    1208 <process+0x58>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x10(%rsp)
lea    0xe33(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1302 <process+0x152>
mov    %rax,%r15
mov    $0x1000,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     12ee <process+0x13e>
movl   $0x1000,0x14(%rsp)
lea    0xc(%rsp),%r12
lea    0x10(%rsp),%r13
jmp    1239 <process+0x89>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     12ee <process+0x13e>
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1080 <strnlen@plt>
mov    %rax,%r14
test   %rax,%rax
je     1260 <process+0xb0>
cmpb   $0xa,-0x1(%r14,%rbx,1)
jne    1260 <process+0xb0>
movl   $0x0,0xc(%rsp)
jmp    1299 <process+0xe9>
mov    0x14(%rsp),%ebp
mov    %ebp,%esi
neg    %esi
mov    0x2d79(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
call   10b0 <fseek@plt>
add    %ebp,%ebp
mov    %rbx,%rdi
mov    %ebp,0x14(%rsp)
mov    %ebp,%esi
call   10c0 <realloc@plt>
mov    %rax,%rbx
movl   $0x0,0xc(%rsp)
test   %r14,%r14
je     1220 <process+0x70>
mov    %r14,%rbp
jmp    12aa <process+0xfa>
xchg   %ax,%ax
add    $0xffffffffffffffff,%rbp
je     1220 <process+0x70>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1050 <findword@plt>
cmp    $0xffffffff,%eax
je     12a0 <process+0xf0>
movslq 0xc(%rsp),%rdi
add    %rbx,%rdi
mov    %eax,%esi
call   1070 <count_syllables@plt>
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%edx
mov    %rbx,%rdi
mov    %eax,%ecx
call   1030 <print_counts@plt>
mov    0x10(%rsp),%eax
add    $0x1,%eax
mov    %eax,0xc(%rsp)
jmp    12a0 <process+0xf0>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
xor    %eax,%eax
jmp    1307 <process+0x157>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_CUR = global i32 0
define i32 @process(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %58, label %8
8: ; preds = %1
%9 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%10 = call i32* @fgets(i8* %9, i32 4096, i32* %6)
%11 = icmp eq i32* %10, null
br i1 %11, label %54, label %17
12: ; preds = %51, %28
%13 = phi i8* [ %33, %28 ], [ %35, %51 ]
%14 = phi i32 [ %32, %28 ], [ %36, %51 ]
%15 = call i32* @fgets(i8* %13, i32 4096, i32* %6)
%16 = icmp eq i32* %15, null
br i1 %16, label %54, label %17
17: ; preds = %8, %12
%18 = phi i8* [ %13, %12 ], [ %9, %8 ]
%19 = phi i32 [ %14, %12 ], [ 4096, %8 ]
%20 = call i64 @strnlen(i8* %18, i32 4096)
%21 = icmp eq i64 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %17
%23 = add i64 %20, -1
%24 = getelementptr inbounds i8, i8* %18, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 10
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 0, i32* %2
br label %34
28: ; preds = %17, %22
%29 = sub nsw i32 0, %19
%30 = load i32, i32* @SEEK_CUR
%31 = call i32 @fseek(i32* %6, i32 %29, i32 %30)
%32 = shl nsw i32 %19, 1
%33 = call i8* @realloc(i8* %18, i32 %32)
store i32 0, i32* %2
br i1 %21, label %12, label %34
34: ; preds = %27, %28
%35 = phi i8* [ %18, %27 ], [ %33, %28 ]
%36 = phi i32 [ %19, %27 ], [ %32, %28 ]
br label %37
37: ; preds = %34, %51
%38 = phi i64 [ 0, %34 ], [ %52, %51 ]
%39 = call i32 @findword(i8* %35, i64 %20, i32* %2, i32* %3)
%40 = icmp eq i32 %39, -1
br i1 %40, label %51, label %41
41: ; preds = %37
%42 = load i32, i32* %2
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %35, i64 %43
%45 = call i32 @count_syllables(i8* %44, i32 %39)
%46 = load i32, i32* %2
%47 = load i32, i32* %3
%48 = call i32 @print_counts(i8* %35, i32 %46, i32 %47, i32 %45)
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1
store i32 %50, i32* %2
br label %51
51: ; preds = %37, %41
%52 = add nuw i64 %38, 1
%53 = icmp eq i64 %52, %20
br i1 %53, label %12, label %37
54: ; preds = %12, %8
%55 = phi i8* [ %9, %8 ], [ %13, %12 ]
%56 = call i32 @fclose(i32* %6)
%57 = call i32 @free(i8* %55)
br label %58
58: ; preds = %1, %54
%59 = phi i32 [ 0, %54 ], [ -1, %1 ]
ret i32 %59
}