#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 *);
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 (((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) || 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    0xe7c(%rip),%rsi
call   1080 <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    11c9 <getLength+0x69>
jmp    1261 <getLength+0x101>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x411(%rbp)
movsbl -0x411(%rbp),%eax
cmp    $0x3e,%eax
jne    11ed <getLength+0x8d>
jmp    1261 <getLength+0x101>
movsbl -0x411(%rbp),%eax
cmp    $0x41,%eax
jl     120d <getLength+0xad>
movsbl -0x411(%rbp),%eax
cmp    $0x5a,%eax
jle    124d <getLength+0xed>
movsbl -0x411(%rbp),%eax
cmp    $0x61,%eax
jl     122d <getLength+0xcd>
movsbl -0x411(%rbp),%eax
cmp    $0x7a,%eax
jle    124d <getLength+0xed>
movsbl -0x411(%rbp),%eax
cmp    $0x2e,%eax
je     124d <getLength+0xed>
movsbl -0x411(%rbp),%eax
cmp    $0x2d,%eax
jne    125c <getLength+0xfc>
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
jmp    11ab <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   %rbx
sub    $0x408,%rsp
lea    0xe90(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <assert@plt>
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     11b2 <getLength+0x52>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret
xor    %ebp,%ebp
jmp    11cf <getLength+0x6f>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    119e <getLength+0x3e>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    $0x3e,%al
je     119e <getLength+0x3e>
lea    -0x41(%rax),%ecx
cmp    $0x1a,%cl
jb     11c0 <getLength+0x60>
lea    -0x2d(%rax),%ecx
cmp    $0x2,%cl
jb     11c0 <getLength+0x60>
add    $0x9f,%al
cmp    $0x19,%al
ja     11c3 <getLength+0x63>
jmp    11c0 <getLength+0x60>

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 = %53, %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 %54
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 %54
26: ; preds = %19
%27 = load i8, i8* %5
%28 = sext i8 %27 to i32
%29 = icmp sge i32 %28, 65
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i8, i8* %5
%32 = sext i8 %31 to i32
%33 = icmp sle i32 %32, 90
br i1 %33, label %50, label %34
34: ; preds = %30, %26
%35 = load i8, i8* %5
%36 = sext i8 %35 to i32
%37 = icmp sge i32 %36, 97
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i8, i8* %5
%40 = sext i8 %39 to i32
%41 = icmp sle i32 %40, 122
br i1 %41, label %50, label %42
42: ; preds = %38, %34
%43 = load i8, i8* %5
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 46
br i1 %45, label %50, label %46
46: ; preds = %42
%47 = load i8, i8* %5
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 45
br i1 %49, label %50, label %53
50: ; preds = %46, %42, %38, %30
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %53
53: ; preds = %50, %46
br label %14
54: ; preds = %25, %14
%55 = load i32*, i32** %3
%56 = call i32 @fclose(i32* %55)
%57 = load i32, i32* %6
ret i32 %57
}

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 %28
9: ; preds = %1, %24
%10 = phi i32 [ %25, %24 ], [ 0, %1 ]
%11 = call signext i8 @fgetc(i32* %4)
%12 = icmp eq i8 %11, 62
br i1 %12, label %28, label %13
13: ; preds = %9
%14 = add i8 %11, -65
%15 = icmp ult i8 %14, 26
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = add i8 %11, -97
%18 = icmp ult i8 %17, 26
%19 = add i8 %11, -45
%20 = icmp ult i8 %19, 2
%21 = or i1 %20, %18
br i1 %21, label %22, label %24
22: ; preds = %16, %13
%23 = add nsw i32 %10, 1
br label %24
24: ; preds = %16, %22
%25 = phi i32 [ %23, %22 ], [ %10, %16 ]
%26 = call i32 @feof(i32* %4)
%27 = icmp eq i32 %26, 0
br i1 %27, label %9, label %28
28: ; preds = %24, %9, %1
%29 = phi i32 [ 0, %1 ], [ %10, %9 ], [ %25, %24 ]
%30 = call i32 @fclose(i32* %4)
ret i32 %29
}