#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 */
char EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp;
  int nchars, nwords, nlines;
  int lastnblank;
  char c;
  if (argc != 2) {
    printf("Usage: %s filename\n", argv[0]);
    exit(0);
  }
  if ((fp = fopen(argv[1], "r")) == NULL) {
    perror("fopen");
    exit(0);
  }
  nchars = nwords = nlines = lastnblank = 0;
  while ((c = getc(fp)) != EOF) {
    nchars++;
    if (c == '\n') {
      if (lastnblank)
        nwords++;
      printf("words=%d, characters=%d\n", nwords, nchars);
      nchars = nwords = lastnblank = 0;
      nlines++;
    } else {
      if (((c == ' ') || (c == '\t')) & (lastnblank))
        nwords++;
      lastnblank = ((c != ' ') && (c != '\t'));
    }
  }
  printf("lines=%d\n", nlines);
  fclose(fp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119c <main+0x3c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe69(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d1 <main+0x71>
lea    0xe51(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <getc@plt>
mov    %al,-0x29(%rbp)
movsbl %al,%eax
mov    0x2de5(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12d9 <main+0x179>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x29(%rbp),%eax
cmp    $0xa,%eax
jne    126e <main+0x10e>
cmpl   $0x0,-0x28(%rbp)
je     1237 <main+0xd7>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12d4 <main+0x174>
movsbl -0x29(%rbp),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x2a(%rbp)
je     128d <main+0x12d>
movsbl -0x29(%rbp),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
and    -0x28(%rbp),%eax
cmp    $0x0,%eax
je     12aa <main+0x14a>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movsbl -0x29(%rbp),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x2b(%rbp)
je     12c9 <main+0x169>
movsbl -0x29(%rbp),%eax
cmp    $0x9,%eax
setne  %al
mov    %al,-0x2b(%rbp)
mov    -0x2b(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x28(%rbp)
jmp    11ed <main+0x8d>
mov    -0x24(%rbp),%esi
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    123e <main+0xde>
mov    0x8(%rsi),%rdi
lea    0xe95(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1256 <main+0xf6>
mov    %rax,%r15
mov    %rax,%rdi
call   1080 <getc@plt>
mov    0x2e49(%rip),%r13
xor    %r12d,%r12d
cmp    0x0(%r13),%al
jne    11d2 <main+0x72>
lea    0xe86(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
xor    %r14d,%r14d
xor    %r12d,%r12d
xor    %ebp,%ebp
jmp    1211 <main+0xb1>
xchg   %ax,%ax
cmp    $0x9,%al
sete   %cl
setne  %sil
cmp    $0x20,%al
sete   %al
setne  %dl
or     %cl,%al
movzbl %al,%eax
and    %eax,%r14d
add    %r14d,%ebp
and    %sil,%dl
movzbl %dl,%r14d
mov    %r15,%rdi
call   1080 <getc@plt>
cmp    0x0(%r13),%al
je     11a8 <main+0x48>
add    $0x1,%ebx
cmp    $0xa,%al
jne    11e0 <main+0x80>
cmp    $0x1,%r14d
sbb    $0xffffffff,%ebp
xor    %r14d,%r14d
lea    0xdf3(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r12d
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1203 <main+0xa3>
mov    (%rsi),%rsi
lea    0xdb8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xdb9(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Usage: %s filename\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@EOF = global i8 0
@.str.3 = [25 x i8] c"words=%d, characters=%d\0A\00"
@.str.4 = [10 x i8] c"lines=%d\0A\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 i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %20
store i32 0, i32* %10
store i32 0, i32* %9
store i32 0, i32* %8
store i32 0, i32* %7
br label %30
30: ; preds = %83, %29
%31 = load i32*, i32** %6
%32 = call signext i8 @getc(i32* %31)
store i8 %32, i8* %11
%33 = sext i8 %32 to i32
%34 = load i8, i8* @EOF
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %33, %35
br i1 %36, label %37, label %84
37: ; preds = %30
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
%40 = load i8, i8* %11
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 10
br i1 %42, label %43, label %55
43: ; preds = %37
%44 = load i32, i32* %10
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %49
49: ; preds = %46, %43
%50 = load i32, i32* %8
%51 = load i32, i32* %7
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %50, i32 %51)
store i32 0, i32* %10
store i32 0, i32* %8
store i32 0, i32* %7
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
br label %83
55: ; preds = %37
%56 = load i8, i8* %11
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 32
br i1 %58, label %63, label %59
59: ; preds = %55
%60 = load i8, i8* %11
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 9
br label %63
63: ; preds = %59, %55
%64 = phi i1 [ true, %55 ], [ %62, %59 ]
%65 = zext i1 %64 to i32
%66 = load i32, i32* %10
%67 = and i32 %65, %66
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %63
%70 = load i32, i32* %8
%71 = add nsw i32 %70, 1
store i32 %71, i32* %8
br label %72
72: ; preds = %69, %63
%73 = load i8, i8* %11
%74 = sext i8 %73 to i32
%75 = icmp ne i32 %74, 32
br i1 %75, label %76, label %80
76: ; preds = %72
%77 = load i8, i8* %11
%78 = sext i8 %77 to i32
%79 = icmp ne i32 %78, 9
br label %80
80: ; preds = %76, %72
%81 = phi i1 [ false, %72 ], [ %79, %76 ]
%82 = zext i1 %81 to i32
store i32 %82, i32* %10
br label %83
83: ; preds = %80, %49
br label %30
84: ; preds = %30
%85 = load i32, i32* %9
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %85)
%87 = load i32*, i32** %6
%88 = call i32 @fclose(i32* %87)
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@.str = [20 x i8] c"Usage: %s filename\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@EOF = global i8 0
@.str.3 = [25 x i8] c"words=%d, characters=%d\0A\00"
@.str.4 = [10 x i8] c"lines=%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = tail call signext i8 @getc(i32* %11)
%15 = load i8, i8* @EOF
%16 = icmp eq i8 %14, %15
br i1 %16, label %53, label %20
17: ; preds = %8
%18 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @exit(i32 0)
unreachable
20: ; preds = %13, %45
%21 = phi i8 [ %50, %45 ], [ %14, %13 ]
%22 = phi i32 [ %49, %45 ], [ 0, %13 ]
%23 = phi i32 [ %48, %45 ], [ 0, %13 ]
%24 = phi i32 [ %47, %45 ], [ 0, %13 ]
%25 = phi i32 [ %46, %45 ], [ 0, %13 ]
%26 = add nsw i32 %22, 1
%27 = icmp eq i8 %21, 10
br i1 %27, label %28, label %34
28: ; preds = %20
%29 = icmp ne i32 %23, 0
%30 = zext i1 %29 to i32
%31 = add nsw i32 %25, %30
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %26)
%33 = add nsw i32 %24, 1
br label %45
34: ; preds = %20
%35 = icmp eq i8 %21, 32
%36 = icmp eq i8 %21, 9
%37 = or i1 %35, %36
%38 = zext i1 %37 to i32
%39 = and i32 %23, %38
%40 = add nsw i32 %39, %25
%41 = icmp ne i8 %21, 32
%42 = icmp ne i8 %21, 9
%43 = and i1 %41, %42
%44 = zext i1 %43 to i32
br label %45
45: ; preds = %34, %28
%46 = phi i32 [ 0, %28 ], [ %40, %34 ]
%47 = phi i32 [ %33, %28 ], [ %24, %34 ]
%48 = phi i32 [ 0, %28 ], [ %44, %34 ]
%49 = phi i32 [ 0, %28 ], [ %26, %34 ]
%50 = tail call signext i8 @getc(i32* %11)
%51 = load i8, i8* @EOF
%52 = icmp eq i8 %50, %51
br i1 %52, label %53, label %20
53: ; preds = %45, %13
%54 = phi i32 [ 0, %13 ], [ %47, %45 ]
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %54)
%56 = tail call i32 @fclose(i32* %11)
ret i32 0
}