#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ isalpha(char);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int tolower(char);
int main(int argc, const char *argv[]) {
  FILE *file = fopen(argv[1], "r");
  char line[1024];
  while (fgets(line, 1024, file)) {
    bool first_word = true;
    for (int i = 0; i < strlen(line); i++) {
      if (isalpha(line[i])) {
        if (first_word) {
          printf("%c", tolower(line[i]));
          first_word = false;
        } else if (!isalpha(line[i - 1]))
          printf(" %c", tolower(line[i]));
        else
          printf("%c", tolower(line[i]));
      }
    }
    printf("\n");
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe78(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12ef <main+0x18f>
movl   $0x1,-0x424(%rbp)
movl   $0x0,-0x428(%rbp)
mov    -0x428(%rbp),%eax
mov    %eax,-0x42c(%rbp)
lea    -0x420(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x42c(%rbp),%eax
cmp    %ecx,%eax
jge    12dc <main+0x17c>
movslq -0x428(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%edi
ff
call   1070 <isalpha@plt>
cmp    $0x0,%rax
je     12c3 <main+0x163>
cmpl   $0x0,-0x424(%rbp)
je     124a <main+0xea>
movslq -0x428(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%edi
ff
call   1060 <tolower@plt>
mov    %eax,%esi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x424(%rbp)
jmp    12be <main+0x15e>
mov    -0x428(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x420(%rbp,%rax,1),%edi
ff
call   1070 <isalpha@plt>
cmp    $0x0,%rax
jne    1295 <main+0x135>
movslq -0x428(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%edi
ff
call   1060 <tolower@plt>
mov    %eax,%esi
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12b9 <main+0x159>
movslq -0x428(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%edi
ff
call   1060 <tolower@plt>
mov    %eax,%esi
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12be <main+0x15e>
jmp    12c3 <main+0x163>
jmp    12c8 <main+0x168>
mov    -0x428(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x428(%rbp)
jmp    11c4 <main+0x64>
lea    0xd23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1191 <main+0x31>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    0x8(%rsi),%rdi
lea    0xe74(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1262 <main+0xf2>
mov    %rsp,%r12
lea    0xe4b(%rip),%r15
jmp    11e3 <main+0x73>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1262 <main+0xf2>
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11c0 <main+0x50>
mov    $0x1,%ebp
xor    %ebx,%ebx
jmp    1225 <main+0xb5>
nopl   0x0(%rax,%rax,1)
movsbl (%rsp,%rbx,1),%edi
call   1070 <tolower@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
add    $0x1,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11c0 <main+0x50>
movsbl (%rsp,%rbx,1),%edi
call   1080 <isalpha@plt>
test   %rax,%rax
je     1212 <main+0xa2>
test   %ebp,%ebp
jne    1200 <main+0x90>
movsbl -0x1(%rsp,%rbx,1),%edi
call   1080 <isalpha@plt>
mov    %rax,%r13
movsbl (%rsp,%rbx,1),%edi
call   1070 <tolower@plt>
test   %r13,%r13
jne    1209 <main+0x99>
xor    %ebp,%ebp
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1212 <main+0xa2>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [4 x i8] c" %c\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
br label %14
14: ; preds = %70, %2
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%16 = load i32*, i32** %6
%17 = call i64 @fgets(i8* %15, i32 1024, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %72
19: ; preds = %14
store i32 1, i32* %8
store i32 0, i32* %9
br label %20
20: ; preds = %67, %19
%21 = load i32, i32* %9
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %70
25: ; preds = %20
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = call i64 @isalpha(i8 signext %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %66
32: ; preds = %25
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = call i32 @tolower(i8 signext %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %40)
store i32 0, i32* %8
br label %65
42: ; preds = %32
%43 = load i32, i32* %9
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = call i64 @isalpha(i8 signext %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %57, label %50
50: ; preds = %42
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = call i32 @tolower(i8 signext %54)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %55)
br label %64
57: ; preds = %42
%58 = load i32, i32* %9
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %59
%61 = load i8, i8* %60
%62 = call i32 @tolower(i8 signext %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %62)
br label %64
64: ; preds = %57, %50
br label %65
65: ; preds = %64, %35
br label %66
66: ; preds = %65, %25
br label %67
67: ; preds = %66
%68 = load i32, i32* %9
%69 = add nsw i32 %68, 1
store i32 %69, i32* %9
br label %20
70: ; preds = %20
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %14
72: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c" %c\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = call i64 @fgets(i8* %7, i32 1024, i32* %6)
%9 = icmp eq i64 %8, 0
br i1 %9, label %48, label %10
10: ; preds = %2, %13
%11 = call i32 @strlen(i8* %7)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %42, %10
%14 = call i32 @putchar(i32 10)
%15 = call i64 @fgets(i8* %7, i32 1024, i32* %6)
%16 = icmp eq i64 %15, 0
br i1 %16, label %48, label %10
17: ; preds = %10, %42
%18 = phi i64 [ %44, %42 ], [ 0, %10 ]
%19 = phi i32 [ %43, %42 ], [ 1, %10 ]
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %18
%21 = load i8, i8* %20
%22 = call i64 @isalpha(i8 signext %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %42, label %24
24: ; preds = %17
%25 = icmp eq i32 %19, 0
br i1 %25, label %30, label %26
26: ; preds = %24
%27 = load i8, i8* %20
%28 = call i32 @tolower(i8 signext %27)
%29 = call i32 @putchar(i32 %28)
br label %42
30: ; preds = %24
%31 = add nsw i64 %18, -1
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = call i64 @isalpha(i8 signext %33)
%35 = icmp eq i64 %34, 0
%36 = load i8, i8* %20
%37 = call i32 @tolower(i8 signext %36)
br i1 %35, label %38, label %40
38: ; preds = %30
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %37)
br label %42
40: ; preds = %30
%41 = call i32 @putchar(i32 %37)
br label %42
42: ; preds = %17, %38, %40, %26
%43 = phi i32 [ 0, %26 ], [ 0, %40 ], [ 0, %38 ], [ %19, %17 ]
%44 = add nuw nsw i64 %18, 1
%45 = call i32 @strlen(i8* %7)
%46 = sext i32 %45 to i64
%47 = icmp slt i64 %44, %46
br i1 %47, label %17, label %13
48: ; preds = %13, %2
ret i32 0
}