#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  FILE *input = NULL;
  int cr = 0, nl = 0, TempChar;
  if (argc < 3) {
    fprintf(stderr, "\nUsage: %s mode inputfile\n\n", argv[0]);
    return -1;
  }
  if ((input = fopen(argv[2], "r")) == NULL) {
    fprintf(stderr, "Unable to open file %s.\n", argv[2]);
    return -1;
  }
  while ((TempChar = getc(input)) != EOF) {
    if (TempChar == '\r') {
      cr++;
      break;
    }
    if (TempChar == '\n')
      nl++;
  }
  if (strcmp(argv[1], "dos") == 0)
    return cr;
  else if (strcmp(argv[1], "mac") == 0) {
    if (nl != 6)
      return nl;
    return cr;
  } else
    return -1;
}


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)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    119e <main+0x5e>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe73(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a7 <main+0x167>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe6f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e9 <main+0xa9>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe46(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a7 <main+0x167>
jmp    11ee <main+0xae>
mov    -0x18(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2de7(%rip),%rcx
cmp    (%rcx),%eax
je     1239 <main+0xf9>
cmpl   $0xd,-0x24(%rbp)
jne    1221 <main+0xe1>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1239 <main+0xf9>
cmpl   $0xa,-0x24(%rbp)
jne    1234 <main+0xf4>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11ee <main+0xae>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdef(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1262 <main+0x122>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12a7 <main+0x167>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdca(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    12a0 <main+0x160>
cmpl   $0x6,-0x20(%rbp)
je     1295 <main+0x155>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12a7 <main+0x167>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12a7 <main+0x167>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
cmp    $0x2,%edi
jg     1165 <main+0x25>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe9d(%rip),%rsi
jmp    11d7 <main+0x97>
mov    0x10(%r14),%rdi
lea    0xeac(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11c3 <main+0x83>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <getc@plt>
mov    0x2e5c(%rip),%r12
xor    %ebp,%ebp
mov    $0x0,%r15d
cmp    (%r12),%eax
je     11e6 <main+0xa6>
xor    %ebp,%ebp
jmp    11b1 <main+0x71>
xchg   %ax,%ax
add    $0x1,%ebp
mov    %rbx,%rdi
call   1060 <getc@plt>
cmp    (%r12),%eax
je     11e3 <main+0xa3>
cmp    $0xa,%eax
je     11a0 <main+0x60>
cmp    $0xd,%eax
jne    11a3 <main+0x63>
mov    $0x1,%r15d
jmp    11e6 <main+0xa6>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r14),%rdx
lea    0xe47(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1222 <main+0xe2>
xor    %r15d,%r15d
mov    0x8(%r14),%rdi
lea    0xe46(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     121f <main+0xdf>
mov    0x8(%r14),%rdi
lea    0xe35(%rip),%rsi
call   1030 <strcmp@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1222 <main+0xe2>
cmp    $0x6,%ebp
cmovne %ebp,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"\0AUsage: %s mode inputfile\0A\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"Unable to open file %s.\0A\00"
@EOF = global i32 0
@.str.3 = [4 x i8] c"dos\00"
@.str.4 = [4 x i8] c"mac\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %45
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%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 i32 @getc(i32* %11)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %31, label %21
17: ; preds = %8
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %9
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %45
21: ; preds = %13, %26
%22 = phi i32 [ %28, %26 ], [ %14, %13 ]
%23 = phi i32 [ %27, %26 ], [ 0, %13 ]
switch i32 %22, label %26 [
i32 13, label %31
i32 10, label %24
]
24: ; preds = %21
%25 = add nsw i32 %23, 1
br label %26
26: ; preds = %21, %24
%27 = phi i32 [ %25, %24 ], [ %23, %21 ]
%28 = tail call i32 @getc(i32* %11)
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %21
31: ; preds = %26, %21, %13
%32 = phi i32 [ 0, %13 ], [ %23, %21 ], [ %27, %26 ]
%33 = phi i32 [ 0, %13 ], [ 1, %21 ], [ 0, %26 ]
%34 = getelementptr inbounds i8*, i8** %1, i64 1
%35 = load i8*, i8** %34
%36 = tail call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %45, label %38
38: ; preds = %31
%39 = load i8*, i8** %34
%40 = tail call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = icmp eq i32 %32, 6
%44 = select i1 %43, i32 %33, i32 %32
br label %45
45: ; preds = %38, %42, %31, %17, %4
%46 = phi i32 [ -1, %4 ], [ -1, %17 ], [ %33, %31 ], [ %44, %42 ], [ -1, %38 ]
ret i32 %46
}