#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*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ isspace(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    puts("Please specify a file name");
    return 1;
  }
  FILE *f = fopen(argv[1], "rt");
  if (f == NULL) {
    perror("main");
    return 2;
  }
  int lines = 0;
  int chrs = 0;
  int c;
  int first = 1;
  puts(argv[1]);
  while ((c = fgetc(f)) != EOF) {
    if (c == '\n') {
      lines++;
      first = 1;
    } else {
      first = 0;
    }
    if (!isspace(c))
      chrs++;
  }
  if (first != 1)
    lines++;
  printf("[LINES]\n%d\n\n", lines);
  printf("[CHARACTERS]\n%d\n\n", chrs);
  fclose(f);
  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)
je     11a8 <main+0x38>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a6 <main+0x136>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe64(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e3 <main+0x73>
lea    0xe4c(%rip),%rdi
call   1090 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12a6 <main+0x136>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dd0(%rip),%rcx
cmp    (%rcx),%eax
je     1265 <main+0xf5>
cmpl   $0xa,-0x24(%rbp)
jne    123f <main+0xcf>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    1246 <main+0xd6>
movl   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1070 <isspace@plt>
cmp    $0x0,%eax
jne    1260 <main+0xf0>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1205 <main+0x95>
cmpl   $0x1,-0x28(%rbp)
je     1278 <main+0x108>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xda1(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%esi
lea    0xd9f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
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    1239 <main+0xc9>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     125d <main+0xed>
mov    %rax,%r15
mov    0x8(%rbx),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1060 <fgetc@plt>
mov    0x2e2d(%rip),%r13
xor    %r14d,%r14d
mov    $0x0,%r12d
mov    $0x0,%ebx
cmp    0x0(%r13),%eax
je     1212 <main+0xa2>
xor    %r12d,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%ebp
xor    %eax,%eax
cmp    $0xa,%ebp
sete   %al
add    %eax,%ebx
mov    %ebp,%edi
call   1070 <isspace@plt>
cmp    $0x1,%eax
adc    $0x0,%r12d
mov    %r15,%rdi
call   1060 <fgetc@plt>
cmp    0x0(%r13),%eax
jne    11e0 <main+0x70>
xor    %eax,%eax
cmp    $0xa,%ebp
setne  %al
add    %eax,%ebx
lea    0xe0a(%rip),%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
lea    0xe09(%rip),%rdi
mov    %r12d,%esi
call   1050 <printf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
jmp    124b <main+0xdb>
lea    0xdc0(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdba(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2,%r14d
jmp    124b <main+0xdb>

LLVM IR (-O0):
@.str = [27 x i8] c"Please specify a file name\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [5 x i8] c"main\00"
@EOF = global i32 0
@.str.3 = [13 x i8] c"[LINES]\0A%d\0A\0A\00"
@.str.4 = [18 x i8] c"[CHARACTERS]\0A%d\0A\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %62
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %62
24: ; preds = %15
store i32 0, i32* %7
store i32 0, i32* %8
store i32 1, i32* %10
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @puts(i8* %27)
br label %29
29: ; preds = %48, %24
%30 = load i32*, i32** %6
%31 = call i32 @fgetc(i32* %30)
store i32 %31, i32* %9
%32 = load i32, i32* @EOF
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %49
34: ; preds = %29
%35 = load i32, i32* %9
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
store i32 1, i32* %10
br label %41
40: ; preds = %34
store i32 0, i32* %10
br label %41
41: ; preds = %40, %37
%42 = load i32, i32* %9
%43 = call i32 @isspace(i32 %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %41
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %48
48: ; preds = %45, %41
br label %29
49: ; preds = %29
%50 = load i32, i32* %10
%51 = icmp ne i32 %50, 1
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %55
55: ; preds = %52, %49
%56 = load i32, i32* %7
%57 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %56)
%58 = load i32, i32* %8
%59 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %58)
%60 = load i32*, i32** %6
%61 = call i32 @fclose(i32* %60)
store i32 0, i32* %3
br label %62
62: ; preds = %55, %22, %13
%63 = load i32, i32* %3
ret i32 %63
}

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