#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int i;
  FILE *src_fs;
  int ch;
  int foundCr;
  int lfCount;
  int crCount;
  int crLfCount;
  int crcrLfCount;
  int otherCount;
  if (argc < 2) {
    fprintf(stderr, "Usage: CountLineEndings file ...\n");
    exit(1);
  }
  printf("    LF     CR   CRLF CRCRLF  Other FileName\n");
  printf("------ ------ ------ ------ ------ ---------------------------\n");
  for (i = 1; i < argc; i++) {
    if ((src_fs = fopen(argv[i], "rb")) == NULL) {
      fprintf(stderr, "Unable to open file %s\n", argv[i]);
      exit(1);
    }
    foundCr = 0;
    lfCount = 0;
    crCount = 0;
    crLfCount = 0;
    crcrLfCount = 0;
    otherCount = 0;
    while ((ch = fgetc(src_fs)) != EOF) {
      if (ch == 0x0D) {
        foundCr++;
        continue;
      }
      if (ch == 0x0A) {
        switch (foundCr) {
        case 0:
          lfCount++;
          break;
        case 1:
          crLfCount++;
          break;
        case 2:
          crcrLfCount++;
          break;
        default:
          otherCount++;
          break;
        }
        foundCr = 0;
        continue;
      }
      if (foundCr > 0) {
        crCount += foundCr;
        foundCr = 0;
      }
    }
    fclose(src_fs);
    printf("%6d %6d %6d %6d %6d %s\n", lfCount, crCount, crLfCount, crcrLfCount,
           otherCount, argv[i]);
  }
  exit(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a1 <main+0x41>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1363 <main+0x203>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xeac(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1223 <main+0xc3>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d88(%rip),%rcx
cmp    (%rcx),%eax
je     131d <main+0x1bd>
cmpl   $0xd,-0x24(%rbp)
jne    1280 <main+0x120>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    124d <main+0xed>
cmpl   $0xa,-0x24(%rbp)
jne    12fe <main+0x19e>
mov    -0x28(%rbp),%eax
mov    %eax,-0x40(%rbp)
test   %eax,%eax
je     12bf <main+0x15f>
jmp    129d <main+0x13d>
mov    -0x40(%rbp),%eax
sub    $0x1,%eax
je     12cd <main+0x16d>
jmp    12ae <main+0x14e>
mov    -0x40(%rbp),%eax
sub    $0x2,%eax
je     12db <main+0x17b>
jmp    12e9 <main+0x189>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12f2 <main+0x192>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12f2 <main+0x192>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    12f2 <main+0x192>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x28(%rbp)
jmp    124d <main+0xed>
cmpl   $0x0,-0x28(%rbp)
jle    1318 <main+0x1b8>
mov    -0x28(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x28(%rbp)
jmp    124d <main+0xed>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    -0x38(%rbp),%r8d
mov    -0x3c(%rbp),%r9d
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rdi
mov    (%rax,%rdi,8),%rax
lea    0xd60(%rip),%rdi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c4 <main+0x64>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x1,%edi
jg     11a4 <main+0x34>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %rsi,%r15
mov    %edi,%ebx
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
mov    %rax,0x20(%rsp)
mov    $0x1,%r13d
mov    0x2e13(%rip),%r12
mov    %r15,0x18(%rsp)
jmp    1224 <main+0xb4>
nopl   0x0(%rax)
mov    0x8(%rsp),%r14d
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    (%r15,%r13,8),%rax
mov    %rax,(%rsp)
lea    0xe41(%rip),%rdi
mov    0xc(%rsp),%esi
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%ecx
mov    %r14d,%r8d
mov    %ebp,%r9d
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r13
cmp    0x20(%rsp),%r13
je     1349 <main+0x1d9>
mov    (%r15,%r13,8),%rdi
lea    0xdf3(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1350 <main+0x1e0>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
movl   $0x0,0xc(%rsp)
movl   $0x0,0x10(%rsp)
mov    $0x0,%r14d
mov    $0x0,%ebp
movl   $0x0,0x14(%rsp)
cmp    (%r12),%eax
je     11e5 <main+0x75>
xor    %ebp,%ebp
xor    %r14d,%r14d
movl   $0x0,0x10(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0xc(%rsp)
mov    %r14d,0x8(%rsp)
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
cmp    $0xd,%eax
jne    12bc <main+0x14c>
add    $0x1,%r14d
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r12),%eax
jne    12a0 <main+0x130>
jmp    11e0 <main+0x70>
cmp    $0xa,%eax
je     1300 <main+0x190>
test   %r14d,%r14d
mov    %r14d,%r15d
mov    $0x0,%eax
cmovg  %eax,%r15d
cmovle %eax,%r14d
add    %r14d,0x14(%rsp)
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    %r15d,%r14d
mov    0x18(%rsp),%r15
cmp    (%r12),%eax
jne    12a0 <main+0x130>
jmp    11e0 <main+0x70>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x2,%r14d
je     1318 <main+0x1a8>
cmp    $0x1,%r14d
je     1323 <main+0x1b3>
test   %r14d,%r14d
jne    132a <main+0x1ba>
addl   $0x1,0xc(%rsp)
jmp    132d <main+0x1bd>
mov    0x8(%rsp),%r14d
add    $0x1,%r14d
jmp    1332 <main+0x1c2>
addl   $0x1,0x10(%rsp)
jmp    132d <main+0x1bd>
add    $0x1,%ebp
mov    0x8(%rsp),%r14d
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r12),%eax
jne    1292 <main+0x122>
jmp    11e5 <main+0x75>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
mov    (%r15,%r13,8),%rdx
lea    0xcc1(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Usage: CountLineEndings file ...\0A\00"
@.str.1 = [45 x i8] c" LF CR CRLF CRCRLF Other FileName\0A\00"
@.str.2 = [64 x i8] c"------ ------ ------ ------ ------ ---------------------------\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [24 x i8] c"Unable to open file %s\0A\00"
@EOF = global i32 0
@.str.5 = [24 x i8] c"%6d %6d %6d %6d %6d %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 i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %6
br label %24
24: ; preds = %97, %21
%25 = load i32, i32* %6
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %100
28: ; preds = %24
%29 = load i8**, i8*** %5
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %34, i32** %7
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %45
36: ; preds = %28
%37 = load i32, i32* @stderr
%38 = load i8**, i8*** %5
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %28
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
br label %46
46: ; preds = %82, %74, %54, %45
%47 = load i32*, i32** %7
%48 = call i32 @fgetc(i32* %47)
store i32 %48, i32* %8
%49 = load i32, i32* @EOF
%50 = icmp ne i32 %48, %49
br i1 %50, label %51, label %83
51: ; preds = %46
%52 = load i32, i32* %8
%53 = icmp eq i32 %52, 13
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %46
57: ; preds = %51
%58 = load i32, i32* %8
%59 = icmp eq i32 %58, 10
br i1 %59, label %60, label %75
60: ; preds = %57
%61 = load i32, i32* %9
switch i32 %61, label %71 [
i32 0, label %62
i32 1, label %65
i32 2, label %68
]
62: ; preds = %60
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %10
br label %74
65: ; preds = %60
%66 = load i32, i32* %12
%67 = add nsw i32 %66, 1
store i32 %67, i32* %12
br label %74
68: ; preds = %60
%69 = load i32, i32* %13
%70 = add nsw i32 %69, 1
store i32 %70, i32* %13
br label %74
71: ; preds = %60
%72 = load i32, i32* %14
%73 = add nsw i32 %72, 1
store i32 %73, i32* %14
br label %74
74: ; preds = %71, %68, %65, %62
store i32 0, i32* %9
br label %46
75: ; preds = %57
%76 = load i32, i32* %9
%77 = icmp sgt i32 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %75
%79 = load i32, i32* %9
%80 = load i32, i32* %11
%81 = add nsw i32 %80, %79
store i32 %81, i32* %11
store i32 0, i32* %9
br label %82
82: ; preds = %78, %75
br label %46
83: ; preds = %46
%84 = load i32*, i32** %7
%85 = call i32 @fclose(i32* %84)
%86 = load i32, i32* %10
%87 = load i32, i32* %11
%88 = load i32, i32* %12
%89 = load i32, i32* %13
%90 = load i32, i32* %14
%91 = load i8**, i8*** %5
%92 = load i32, i32* %6
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8*, i8** %91, i64 %93
%95 = load i8*, i8** %94
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %86, i32 %87, i32 %88, i32 %89, i32 %90, i8* %95)
br label %97
97: ; preds = %83
%98 = load i32, i32* %6
%99 = add nsw i32 %98, 1
store i32 %99, i32* %6
br label %24
100: ; preds = %24
%101 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Usage: CountLineEndings file ...\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [24 x i8] c"Unable to open file %s\0A\00"
@EOF = global i32 0
@.str.5 = [24 x i8] c"%6d %6d %6d %6d %6d %s\0A\00"
@str = [44 x i8] c" LF CR CRLF CRCRLF Other FileName\00"
@str.6 = [63 x i8] c"------ ------ ------ ------ ------ ---------------------------\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.6, i64 0, i64 0))
%11 = zext i32 %0 to i64
br label %12
12: ; preds = %8, %71
%13 = phi i64 [ 1, %8 ], [ %80, %71 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %22, label %18
18: ; preds = %12
%19 = tail call i32 @fgetc(i32* %16)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %71, label %52
22: ; preds = %12
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %14
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %59, %30
%28 = phi i32 [ %60, %59 ], [ %32, %30 ]
%29 = phi i32 [ %62, %59 ], [ %31, %30 ]
switch i32 %28, label %63 [
i32 13, label %30
i32 10, label %35
]
30: ; preds = %27
%31 = add nsw i32 %29, 1
%32 = tail call i32 @fgetc(i32* %16)
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %71, label %27
35: ; preds = %27
switch i32 %29, label %42 [
i32 0, label %36
i32 1, label %38
i32 2, label %40
]
36: ; preds = %35
%37 = add nsw i32 %58, 1
br label %44
38: ; preds = %35
%39 = add nsw i32 %56, 1
br label %44
40: ; preds = %35
%41 = add nsw i32 %55, 1
br label %44
42: ; preds = %35
%43 = add nsw i32 %54, 1
br label %44
44: ; preds = %42, %40, %38, %36
%45 = phi i32 [ %58, %42 ], [ %58, %40 ], [ %58, %38 ], [ %37, %36 ]
%46 = phi i32 [ %56, %42 ], [ %56, %40 ], [ %39, %38 ], [ %56, %36 ]
%47 = phi i32 [ %55, %42 ], [ %41, %40 ], [ %55, %38 ], [ %55, %36 ]
%48 = phi i32 [ %43, %42 ], [ %54, %40 ], [ %54, %38 ], [ %54, %36 ]
%49 = tail call i32 @fgetc(i32* %16)
%50 = load i32, i32* @EOF
%51 = icmp eq i32 %49, %50
br i1 %51, label %71, label %52
52: ; preds = %18, %44
%53 = phi i32 [ %49, %44 ], [ %19, %18 ]
%54 = phi i32 [ %48, %44 ], [ 0, %18 ]
%55 = phi i32 [ %47, %44 ], [ 0, %18 ]
%56 = phi i32 [ %46, %44 ], [ 0, %18 ]
%57 = phi i32 [ %61, %44 ], [ 0, %18 ]
%58 = phi i32 [ %45, %44 ], [ 0, %18 ]
br label %59
59: ; preds = %52, %63
%60 = phi i32 [ %53, %52 ], [ %68, %63 ]
%61 = phi i32 [ %57, %52 ], [ %67, %63 ]
%62 = phi i32 [ 0, %52 ], [ %65, %63 ]
br label %27
63: ; preds = %27
%64 = icmp sgt i32 %29, 0
%65 = select i1 %64, i32 0, i32 %29
%66 = select i1 %64, i32 %29, i32 0
%67 = add nsw i32 %61, %66
%68 = tail call i32 @fgetc(i32* %16)
%69 = load i32, i32* @EOF
%70 = icmp eq i32 %68, %69
br i1 %70, label %71, label %59
71: ; preds = %44, %63, %30, %18
%72 = phi i32 [ 0, %18 ], [ %58, %30 ], [ %58, %63 ], [ %45, %44 ]
%73 = phi i32 [ 0, %18 ], [ %56, %30 ], [ %56, %63 ], [ %46, %44 ]
%74 = phi i32 [ 0, %18 ], [ %55, %30 ], [ %55, %63 ], [ %47, %44 ]
%75 = phi i32 [ 0, %18 ], [ %54, %30 ], [ %54, %63 ], [ %48, %44 ]
%76 = phi i32 [ 0, %18 ], [ %61, %30 ], [ %67, %63 ], [ %61, %44 ]
%77 = tail call i32 @fclose(i32* %16)
%78 = load i8*, i8** %14
%79 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %72, i32 %76, i32 %73, i32 %74, i32 %75, i8* %78)
%80 = add nuw nsw i64 %13, 1
%81 = icmp eq i64 %80, %11
br i1 %81, label %82, label %12
82: ; preds = %71
%83 = tail call i32 @exit(i32 0)
unreachable
}