#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);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ isspace(char);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int i, wcnt, state;
  char ch;
  FILE *in;
  if (argc < 2) {
    fprintf(stderr, "Missing input file(s).\n");
    exit(1);
  }
  for (i = 1; i < argc; i++) {
    in = fopen(argv[i], "r");
    if (in == NULL) {
      perror(argv[i]);
      continue;
    }
    wcnt = 0;
    state = 0;
    while ((ch = fgetc(in)) != EOF) {
      if (isspace(ch)) {
        state = 0;
      } else if (state == 0) {
        wcnt++;
        state = 1;
      }
    }
    printf("%s: %d word(s).\n", argv[i], wcnt);
    fclose(in);
  }
  return 0;
}


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)
jge    11bf <main+0x3f>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12b3 <main+0x133>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe33(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    120f <main+0x8f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1090 <perror@plt>
jmp    12a5 <main+0x125>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x1d(%rbp)
movsbl %al,%eax
mov    0x2db5(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1281 <main+0x101>
movsbl -0x1d(%rbp),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
je     125d <main+0xdd>
movl   $0x0,-0x1c(%rbp)
jmp    127c <main+0xfc>
cmpl   $0x0,-0x1c(%rbp)
jne    1277 <main+0xf7>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    127c <main+0xfc>
jmp    121d <main+0x9d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x18(%rbp),%edx
lea    0xd83(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c6 <main+0x46>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     127c <main+0xfc>
mov    %rsi,%r12
mov    %edi,%eax
mov    %rax,0x8(%rsp)
mov    $0x1,%r14d
mov    0x2e3a(%rip),%rbx
mov    %rsi,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r12,%r14,8),%rdi
lea    0xe4d(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1260 <main+0xe0>
mov    %rax,%r15
mov    %r14,0x10(%rsp)
mov    %rax,%rdi
call   1050 <fgetc@plt>
xor    %r14d,%r14d
xor    %ebp,%ebp
cmp    (%rbx),%al
je     122c <main+0xac>
xor    %r12d,%r12d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1060 <isspace@plt>
xor    $0x1,%r12d
xor    %r13d,%r13d
test   %rax,%rax
sete   %r13b
cmovne %r14d,%r12d
add    %r12d,%ebp
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %r13d,%r12d
cmp    (%rbx),%al
jne    1200 <main+0x80>
mov    (%rsp),%r12
mov    0x10(%rsp),%r14
mov    (%r12,%r14,8),%rsi
lea    0xdda(%rip),%rdi
mov    %ebp,%edx
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
add    $0x1,%r14
cmp    0x8(%rsp),%r14
jne    11c0 <main+0x40>
jmp    126b <main+0xeb>
mov    (%r12,%r14,8),%rdi
call   1090 <perror@plt>
jmp    124f <main+0xcf>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
lea    0xd74(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Missing input file(s).\0A\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [17 x i8] c"%s: %d word(s).\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 i8
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
store i32 1, i32* %6
br label %18
18: ; preds = %69, %17
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %72
22: ; preds = %18
%23 = load i8**, i8*** %5
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %10
%29 = load i32*, i32** %10
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %38
31: ; preds = %22
%32 = load i8**, i8*** %5
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 @perror(i8* %36)
br label %69
38: ; preds = %22
store i32 0, i32* %7
store i32 0, i32* %8
br label %39
39: ; preds = %58, %38
%40 = load i32*, i32** %10
%41 = call signext i8 @fgetc(i32* %40)
store i8 %41, i8* %9
%42 = sext i8 %41 to i32
%43 = load i8, i8* @EOF
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %42, %44
br i1 %45, label %46, label %59
46: ; preds = %39
%47 = load i8, i8* %9
%48 = call i64 @isspace(i8 signext %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %46
store i32 0, i32* %8
br label %58
51: ; preds = %46
%52 = load i32, i32* %8
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
store i32 1, i32* %8
br label %57
57: ; preds = %54, %51
br label %58
58: ; preds = %57, %50
br label %39
59: ; preds = %39
%60 = load i8**, i8*** %5
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %60, i64 %62
%64 = load i8*, i8** %63
%65 = load i32, i32* %7
%66 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %64, i32 %65)
%67 = load i32*, i32** %10
%68 = call i32 @fclose(i32* %67)
br label %69
69: ; preds = %59, %31
%70 = load i32, i32* %6
%71 = add nsw i32 %70, 1
store i32 %71, i32* %6
br label %18
72: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Missing input file(s).\0A\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [17 x i8] c"%s: %d word(s).\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %4, %41
%11 = phi i64 [ 1, %4 ], [ %42, %41 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = tail call signext i8 @fgetc(i32* %14)
%18 = load i8, i8* @EOF
%19 = icmp eq i8 %17, %18
br i1 %19, label %36, label %23
20: ; preds = %10
%21 = load i8*, i8** %12
%22 = tail call i32 @perror(i8* %21)
br label %41
23: ; preds = %16, %23
%24 = phi i8 [ %33, %23 ], [ %17, %16 ]
%25 = phi i32 [ %32, %23 ], [ 0, %16 ]
%26 = phi i32 [ %31, %23 ], [ 0, %16 ]
%27 = tail call i64 @isspace(i8 signext %24)
%28 = icmp eq i64 %27, 0
%29 = xor i32 %25, 1
%30 = select i1 %28, i32 %29, i32 0
%31 = add nuw nsw i32 %30, %26
%32 = zext i1 %28 to i32
%33 = tail call signext i8 @fgetc(i32* %14)
%34 = load i8, i8* @EOF
%35 = icmp eq i8 %33, %34
br i1 %35, label %36, label %23
36: ; preds = %23, %16
%37 = phi i32 [ 0, %16 ], [ %31, %23 ]
%38 = load i8*, i8** %12
%39 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %38, i32 %37)
%40 = tail call i32 @fclose(i32* %14)
br label %41
41: ; preds = %36, %20
%42 = add nuw nsw i64 %11, 1
%43 = icmp eq i64 %42, %5
br i1 %43, label %44, label %10
44: ; preds = %41
ret i32 0
}