#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 == '.')
      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    1237 <getLength+0xc7>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x411(%rbp)
movsbl -0x411(%rbp),%eax
cmp    $0x3e,%eax
jne    11fd <getLength+0x8d>
jmp    1237 <getLength+0xc7>
movsbl -0x411(%rbp),%edi
call   1080 <isalpha@plt>
cmp    $0x0,%rax
jne    1223 <getLength+0xb3>
movsbl -0x411(%rbp),%eax
cmp    $0x2e,%eax
jne    1232 <getLength+0xc2>
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    11f5 <getLength+0x85>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    $0x3e,%al
je     11f5 <getLength+0x85>
mov    %eax,%ebx
movsbl %al,%edi
call   1080 <isalpha@plt>
test   %rax,%rax
setne  %al
cmp    $0x2e,%bl
sete   %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 = %37, %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 %38
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 %38
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 %34, 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 %34, label %37
34: ; preds = %30, %26
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %37
37: ; preds = %34, %30
br label %14
38: ; preds = %25, %14
%39 = load i32*, i32** %3
%40 = call i32 @fclose(i32* %39)
%41 = load i32, i32* %6
ret i32 %41
}

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 %22
9: ; preds = %1, %13
%10 = phi i32 [ %19, %13 ], [ 0, %1 ]
%11 = call signext i8 @fgetc(i32* %4)
%12 = icmp eq i8 %11, 62
br i1 %12, label %22, label %13
13: ; preds = %9
%14 = call i64 @isalpha(i8 signext %11)
%15 = icmp ne i64 %14, 0
%16 = icmp eq i8 %11, 46
%17 = or i1 %16, %15
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %10, %18
%20 = call i32 @feof(i32* %4)
%21 = icmp eq i32 %20, 0
br i1 %21, label %9, label %22
22: ; preds = %13, %9, %1
%23 = phi i32 [ 0, %1 ], [ %10, %9 ], [ %19, %13 ]
%24 = call i32 @fclose(i32* %4)
ret i32 %23
}