#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*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int main(int argc, char *argv[]) {
  int i;
  for (i = 1; i < argc; i++) {
    FILE *f;
    int c;
    int cnt = 0;
    f = fopen(argv[i], "r");
    if (!f) {
      perror(argv[i]);
      exit(1);
    }
    while ((c = fgetc(f)) != EOF) {
      if (c == '\n') {
        cnt++;
      }
    }
    printf("%s: %d lines\n", argv[i], cnt);
    fclose(f);
  }
  exit(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)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    123c <main+0xdc>
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe5d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d2 <main+0x72>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11d7 <main+0x77>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dfe(%rip),%rcx
cmp    (%rcx),%eax
je     120a <main+0xaa>
cmpl   $0xa,-0x24(%rbp)
jne    1205 <main+0xa5>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11d7 <main+0x77>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x28(%rbp),%edx
lea    0xde2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117d <main+0x1d>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11f9 <main+0x99>
mov    %rsi,%r12
mov    %edi,%r13d
mov    $0x1,%r14d
mov    0x2e61(%rip),%r15
jmp    11b3 <main+0x53>
nopl   0x0(%rax)
mov    (%r12,%r14,8),%rsi
lea    0xe67(%rip),%rdi
mov    %ebp,%edx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x1,%r14
cmp    %r13,%r14
je     11f9 <main+0x99>
mov    (%r12,%r14,8),%rdi
lea    0xe42(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1200 <main+0xa0>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
xor    %ebp,%ebp
cmp    (%r15),%eax
je     1190 <main+0x30>
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%eax
jne    11e0 <main+0x80>
jmp    1190 <main+0x30>
xor    %edi,%edi
call   1080 <exit@plt>
mov    (%r12,%r14,8),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

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