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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
char tolower(char);
int main(int argc, char const *argv[]) {
  FILE *fp1, *fp2;
  char line[16];
  fp1 = fopen("./all-names.txt", "r");
  if (fp1 == NULL) {
    printf("cannot open ./all-names.txt\n");
    return 0;
  }
  fp2 = fopen("./all-names2.txt", "a");
  int i = 0;
  while (fgets(line, sizeof(line), fp1) != NULL) {
    while (((line[i] >= 'a' && line[i] <= 'z') ||
            (line[i] >= 'A' && line[i] <= 'Z'))) {
      i++;
    }
    line[i] = '\0';
    line[0] = tolower(line[0]);
    fwrite(line, sizeof(char), i, fp2);
    putc('\n', fp2);
    i = 0;
  }
  fclose(fp1);
  fclose(fp2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c0 <main+0x50>
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d2 <main+0x162>
lea    0xe68(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x10,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12b9 <main+0x149>
jmp    11ff <main+0x8f>
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x61,%eax
jl     1228 <main+0xb8>
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%ecx
mov    $0x1,%al
cmp    $0x7a,%ecx
mov    %al,-0x35(%rbp)
jle    1257 <main+0xe7>
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%ecx
xor    %eax,%eax
cmp    $0x41,%ecx
mov    %al,-0x36(%rbp)
jl     1251 <main+0xe1>
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x5a,%eax
setle  %al
mov    %al,-0x36(%rbp)
mov    -0x36(%rbp),%al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    1267 <main+0xf7>
jmp    1275 <main+0x105>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ff <main+0x8f>
movslq -0x34(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
movsbl -0x30(%rbp),%edi
call   1070 <tolower@plt>
mov    %al,-0x30(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
mov    -0x20(%rbp),%rsi
mov    $0xa,%edi
call   1060 <putc@plt>
movl   $0x0,-0x34(%rbp)
jmp    11de <main+0x6e>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe9f(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1240 <main+0xd0>
mov    %rax,%r14
lea    0xe61(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x10,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     122e <main+0xbe>
xor    %ecx,%ecx
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
mov    %rcx,%rbx
movzbl (%rsp,%rcx,1),%eax
and    $0xdf,%al
add    $0xbf,%al
add    $0x1,%rcx
cmp    $0x1a,%al
jb     11d0 <main+0x60>
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
movsbl (%rsp),%edi
call   1070 <tolower@plt>
mov    %al,(%rsp)
mov    %r15,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r12,%rcx
call   1090 <fwrite@plt>
mov    $0xa,%edi
mov    %r12,%rsi
call   1060 <putc@plt>
mov    %r15,%rdi
mov    $0x10,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
mov    $0x0,%ecx
test   %rax,%rax
jne    11d0 <main+0x60>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
jmp    124c <main+0xdc>
lea    0xdce(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"./all-names.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"cannot open ./all-names.txt\0A\00"
@.str.3 = [17 x i8] c"./all-names2.txt\00"
@.str.4 = [2 x i8] c"a\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [16 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %77
15: ; preds = %2
%16 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %16, i32** %7
store i32 0, i32* %9
br label %17
17: ; preds = %58, %15
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%19 = load i32*, i32** %6
%20 = call i32* @fgets(i8* %18, i32 16, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %72
22: ; preds = %17
br label %23
23: ; preds = %55, %22
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp sge i32 %28, 97
br i1 %29, label %30, label %37
30: ; preds = %23
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp sle i32 %35, 122
br i1 %36, label %53, label %37
37: ; preds = %30, %23
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp sge i32 %42, 65
br i1 %43, label %44, label %51
44: ; preds = %37
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp sle i32 %49, 90
br label %51
51: ; preds = %44, %37
%52 = phi i1 [ false, %37 ], [ %50, %44 ]
br label %53
53: ; preds = %51, %30
%54 = phi i1 [ true, %30 ], [ %52, %51 ]
br i1 %54, label %55, label %58
55: ; preds = %53
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 1
store i32 %57, i32* %9
br label %23
58: ; preds = %53
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 %60
store i8 0, i8* %61
%62 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%63 = load i8, i8* %62
%64 = call signext i8 @tolower(i8 signext %63)
%65 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
store i8 %64, i8* %65
%66 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%67 = load i32, i32* %9
%68 = load i32*, i32** %7
%69 = call i32 @fwrite(i8* %66, i32 1, i32 %67, i32* %68)
%70 = load i32*, i32** %7
%71 = call i32 @putc(i8 signext 10, i32* %70)
store i32 0, i32* %9
br label %17
72: ; preds = %17
%73 = load i32*, i32** %6
%74 = call i32 @fclose(i32* %73)
%75 = load i32*, i32** %7
%76 = call i32 @fclose(i32* %75)
store i32 0, i32* %3
br label %77
77: ; preds = %72, %13
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@.str = [16 x i8] c"./all-names.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [17 x i8] c"./all-names2.txt\00"
@.str.4 = [2 x i8] c"a\00"
@str = [28 x i8] c"cannot open ./all-names.txt\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %36
9: ; preds = %2
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32* @fgets(i8* %4, i32 16, i32* %5)
%12 = icmp eq i32* %11, null
br i1 %12, label %33, label %13
13: ; preds = %9, %21
%14 = phi i64 [ %22, %21 ], [ 0, %9 ]
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = and i8 %16, -33
%18 = add i8 %17, -65
%19 = icmp ult i8 %18, 26
%20 = add nuw i64 %14, 1
br i1 %19, label %21, label %23
21: ; preds = %13, %23
%22 = phi i64 [ %20, %13 ], [ 0, %23 ]
br label %13
23: ; preds = %13
%24 = trunc i64 %14 to i32
%25 = and i64 %14, 4294967295
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %25
store i8 0, i8* %26
%27 = load i8, i8* %4
%28 = call signext i8 @tolower(i8 signext %27)
store i8 %28, i8* %4
%29 = call i32 @fwrite(i8* %4, i32 1, i32 %24, i32* %10)
%30 = call i32 @putc(i8 signext 10, i32* %10)
%31 = call i32* @fgets(i8* %4, i32 16, i32* %5)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %21
33: ; preds = %23, %9
%34 = call i32 @fclose(i32* %5)
%35 = call i32 @fclose(i32* %10)
br label %36
36: ; preds = %33, %7
ret i32 0
}