#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ mystrupr(char *);
int words_starting_with(const char *dictionary, char letter) {
  int wordCount = 0;
  char buffer[50 + 2];
  FILE *infile;
  if (letter >= 'a' && letter <= 'z') {
    letter += ('A' - 'a');
  }
  infile = fopen(dictionary, "rt");
  if (infile != NULL) {
    while (!feof(infile)) {
      fgets(buffer, 50 + 1, infile);
      mystrupr(buffer);
      if (buffer[0] == letter) {
        wordCount++;
      } else if (buffer[0] > letter) {
        break;
      }
    }
    fclose(infile);
  } else {
    return -2;
  }
  return wordCount;
}


x86 assembly (clang, -O0):
<words_starting_with>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x61,%eax
jl     118d <words_starting_with+0x3d>
movsbl -0x11(%rbp),%eax
cmp    $0x7a,%eax
jg     118d <words_starting_with+0x3d>
movsbl -0x11(%rbp),%eax
add    $0xffffffe0,%eax
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1235 <words_starting_with+0xe5>
jmp    11b1 <words_starting_with+0x61>
mov    -0x58(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11cf <words_starting_with+0x7f>
jmp    1227 <words_starting_with+0xd7>
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    $0x33,%esi
call   1040 <fgets@plt>
lea    -0x50(%rbp),%rdi
call   1060 <mystrupr@plt>
movsbl -0x50(%rbp),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    1208 <words_starting_with+0xb8>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1222 <words_starting_with+0xd2>
movsbl -0x50(%rbp),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jle    121d <words_starting_with+0xcd>
jmp    1227 <words_starting_with+0xd7>
jmp    1222 <words_starting_with+0xd2>
jmp    11b1 <words_starting_with+0x61>
mov    -0x58(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1241 <words_starting_with+0xf1>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1247 <words_starting_with+0xf7>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<words_starting_with>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    -0x61(%rsi),%eax
lea    -0x20(%rsi),%ecx
cmp    $0x1a,%al
movzbl %cl,%r15d
cmovae %esi,%r15d
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1196 <words_starting_with+0x46>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     11a8 <words_starting_with+0x58>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    119b <words_starting_with+0x4b>
mov    $0xfffffffe,%ebp
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
mov    %rsp,%r14
jmp    11bf <words_starting_with+0x6f>
nop
add    $0x1,%ebp
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    118c <words_starting_with+0x3c>
mov    %r14,%rdi
mov    $0x33,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    %r14,%rdi
call   1060 <mystrupr@plt>
cmp    %r15b,(%rsp)
je     11b0 <words_starting_with+0x60>
jle    11b3 <words_starting_with+0x63>
jmp    118c <words_starting_with+0x3c>

LLVM IR (-O0):
@.str = [3 x i8] c"rt\00"
define i32 @words_starting_with(i8* %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca [52 x i8]
%8 = alloca i32*
store i8* %0, i8** %4
store i8 %1, i8* %5
store i32 0, i32* %6
%9 = load i8, i8* %5
%10 = sext i8 %9 to i32
%11 = icmp sge i32 %10, 97
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = load i8, i8* %5
%14 = sext i8 %13 to i32
%15 = icmp sle i32 %14, 122
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i8, i8* %5
%18 = sext i8 %17 to i32
%19 = add nsw i32 %18, -32
%20 = trunc i32 %19 to i8
store i8 %20, i8* %5
br label %21
21: ; preds = %16, %12, %2
%22 = load i8*, i8** %4
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %8
%24 = load i32*, i32** %8
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %60
26: ; preds = %21
br label %27
27: ; preds = %56, %26
%28 = load i32*, i32** %8
%29 = call i32 @feof(i32* %28)
%30 = icmp ne i32 %29, 0
%31 = xor i1 %30, true
br i1 %31, label %32, label %57
32: ; preds = %27
%33 = getelementptr inbounds [52 x i8], [52 x i8]* %7, i64 0, i64 0
%34 = load i32*, i32** %8
%35 = call i32 @fgets(i8* %33, i32 51, i32* %34)
%36 = getelementptr inbounds [52 x i8], [52 x i8]* %7, i64 0, i64 0
%37 = call i32 @mystrupr(i8* %36)
%38 = getelementptr inbounds [52 x i8], [52 x i8]* %7, i64 0, i64 0
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = load i8, i8* %5
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %40, %42
br i1 %43, label %44, label %47
44: ; preds = %32
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %56
47: ; preds = %32
%48 = getelementptr inbounds [52 x i8], [52 x i8]* %7, i64 0, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = load i8, i8* %5
%52 = sext i8 %51 to i32
%53 = icmp sgt i32 %50, %52
br i1 %53, label %54, label %55
54: ; preds = %47
br label %57
55: ; preds = %47
br label %56
56: ; preds = %55, %44
br label %27
57: ; preds = %54, %27
%58 = load i32*, i32** %8
%59 = call i32 @fclose(i32* %58)
br label %61
60: ; preds = %21
store i32 -2, i32* %3
br label %63
61: ; preds = %57
%62 = load i32, i32* %6
store i32 %62, i32* %3
br label %63
63: ; preds = %61, %60
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
define i32 @words_starting_with(i8* nocapture %0, i8 signext %1) {
%3 = alloca [52 x i8]
%4 = getelementptr inbounds [52 x i8], [52 x i8]* %3, i64 0, i64 0
%5 = add i8 %1, -97
%6 = icmp ult i8 %5, 26
%7 = add i8 %1, -32
%8 = select i1 %6, i8 %7, i8 %1
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %31, label %11
11: ; preds = %2
%12 = call i32 @feof(i32* %9)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %28
14: ; preds = %11, %24
%15 = phi i32 [ %25, %24 ], [ 0, %11 ]
%16 = call i32 @fgets(i8* %4, i32 51, i32* %9)
%17 = call i32 @mystrupr(i8* %4)
%18 = load i8, i8* %4
%19 = icmp eq i8 %18, %8
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = add nsw i32 %15, 1
br label %24
22: ; preds = %14
%23 = icmp sgt i8 %18, %8
br i1 %23, label %28, label %24
24: ; preds = %22, %20
%25 = phi i32 [ %21, %20 ], [ %15, %22 ]
%26 = call i32 @feof(i32* %9)
%27 = icmp eq i32 %26, 0
br i1 %27, label %14, label %28
28: ; preds = %24, %22, %11
%29 = phi i32 [ 0, %11 ], [ %15, %22 ], [ %25, %24 ]
%30 = call i32 @fclose(i32* %9)
br label %31
31: ; preds = %2, %28
%32 = phi i32 [ %29, %28 ], [ -2, %2 ]
ret i32 %32
}