#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*/ assert(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isalpha(char);
int getLength(char *filename) {
  FILE *file;
  char buffer[1024], ch;
  int length = 0;
  file = fopen(filename, "r");
  assert(file);
  fgets(buffer, 1024, file);
  while (!feof(file)) {
    ch = fgetc(file);
    if (ch == '>')
      break;
    if (isalpha(ch) || ch == '.' || ch == '-')
      length++;
  }
  fclose(file);
  return length;
}


x86 assembly (clang, -O0):
<getLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x418(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <assert@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d9 <getLength+0x69>
jmp    1247 <getLength+0xd7>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x411(%rbp)
movsbl -0x411(%rbp),%eax
cmp    $0x3e,%eax
jne    11fd <getLength+0x8d>
jmp    1247 <getLength+0xd7>
movsbl -0x411(%rbp),%edi
call   1080 <isalpha@plt>
cmp    $0x0,%rax
jne    1233 <getLength+0xc3>
movsbl -0x411(%rbp),%eax
cmp    $0x2e,%eax
je     1233 <getLength+0xc3>
movsbl -0x411(%rbp),%eax
cmp    $0x2d,%eax
jne    1242 <getLength+0xd2>
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
jmp    11bb <getLength+0x4b>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x418(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLength>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
lea    0xe7e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <assert@plt>
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
mov    %r14,%rdi
call   1070 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    11f8 <getLength+0x88>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    $0x3e,%al
je     11f8 <getLength+0x88>
mov    %eax,%ebx
movsbl %al,%edi
call   1080 <isalpha@plt>
test   %rax,%rax
setne  %al
add    $0xd3,%bl
cmp    $0x2,%bl
setb   %cl
or     %al,%cl
movzbl %cl,%eax
add    %eax,%ebp
mov    %r14,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11c0 <getLength+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @getLength(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [1024 x i8]
%5 = alloca i8
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %6
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = call i32 @assert(i32* %9)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%12 = load i32*, i32** %3
%13 = call i32 @fgets(i8* %11, i32 1024, i32* %12)
br label %14
14: ; preds = %41, %1
%15 = load i32*, i32** %3
%16 = call i32 @feof(i32* %15)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %42
19: ; preds = %14
%20 = load i32*, i32** %3
%21 = call signext i8 @fgetc(i32* %20)
store i8 %21, i8* %5
%22 = load i8, i8* %5
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 62
br i1 %24, label %25, label %26
25: ; preds = %19
br label %42
26: ; preds = %19
%27 = load i8, i8* %5
%28 = call i64 @isalpha(i8 signext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %38, label %30
30: ; preds = %26
%31 = load i8, i8* %5
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 46
br i1 %33, label %38, label %34
34: ; preds = %30
%35 = load i8, i8* %5
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 45
br i1 %37, label %38, label %41
38: ; preds = %34, %30, %26
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %41
41: ; preds = %38, %34
br label %14
42: ; preds = %25, %14
%43 = load i32*, i32** %3
%44 = call i32 @fclose(i32* %43)
%45 = load i32, i32* %6
ret i32 %45
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @getLength(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @assert(i32* %4)
%6 = call i32 @fgets(i8* %3, i32 1024, i32* %4)
%7 = call i32 @feof(i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %1, %13
%10 = phi i32 [ %20, %13 ], [ 0, %1 ]
%11 = call signext i8 @fgetc(i32* %4)
%12 = icmp eq i8 %11, 62
br i1 %12, label %23, label %13
13: ; preds = %9
%14 = call i64 @isalpha(i8 signext %11)
%15 = icmp ne i64 %14, 0
%16 = add i8 %11, -45
%17 = icmp ult i8 %16, 2
%18 = or i1 %17, %15
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %10, %19
%21 = call i32 @feof(i32* %4)
%22 = icmp eq i32 %21, 0
br i1 %22, label %9, label %23
23: ; preds = %13, %9, %1
%24 = phi i32 [ 0, %1 ], [ %10, %9 ], [ %20, %13 ]
%25 = call i32 @fclose(i32* %4)
ret i32 %24
}