#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 */

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ close(int);
int lseek(int, int, int /*<<< orphan*/);
char *mmap(char *, int, int /*<<< orphan*/, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
int time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  char *memory = NULL;
  int file_length = 0;
  char *start_address = 0;
  int line_num = 0;
  int time_start = time(NULL);
  int costs;
  int fd = open("intel.txt", O_RDONLY);
  if (fd > 0) {
    file_length = lseek(fd, 1, SEEK_END);
    printf("file_length:%d\n", file_length);
    memory = mmap(start_address, file_length, PROT_READ, MAP_SHARED, fd, 0);
    int i = 0;
    for (; i < file_length; i++) {
      if (memory[i] == '\n') {
        ++line_num;
      }
    }
    close(fd);
    munmap(memory, file_length);
    costs = time(NULL) - time_start;
    printf(
        "Finished, total lines is %d \n total costed time %d sec\n time:%ld\n",
        line_num, costs, time(NULL));
  }
  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)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x30(%rbp)
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
lea    0xe40(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jle    12b7 <main+0x147>
mov    -0x38(%rbp),%edi
mov    0x2dfc(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1050 <lseek@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2dee(%rip),%rax
mov    (%rax),%edx
mov    0x2dd5(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1269 <main+0xf9>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1256 <main+0xe6>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    125b <main+0xeb>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    122c <main+0xbc>
mov    -0x38(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <munmap@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
sub    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x40(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    -0x44(%rbp),%esi
mov    -0x40(%rbp),%edx
mov    %eax,%ecx
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %ebx,%ebx
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%r14d
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    0xe8c(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
jle    137f <main+0x20f>
mov    %eax,%r15d
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    $0x1,%esi
call   1050 <lseek@plt>
mov    %eax,%r12d
lea    0xe66(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
mov    0x2e0b(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r12d,%esi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbp
test   %r12d,%r12d
jle    1345 <main+0x1d5>
mov    %r12d,%eax
cmp    $0x8,%r12d
jae    120d <main+0x9d>
xor    %ecx,%ecx
xor    %ebx,%ebx
jmp    1330 <main+0x1c0>
mov    %eax,%ecx
and    $0xfffffff8,%ecx
lea    -0x8(%rcx),%rsi
mov    %rsi,%rdx
shr    $0x3,%rdx
add    $0x1,%rdx
test   %rsi,%rsi
je     138a <main+0x21a>
mov    %rdx,%rdi
and    $0xfffffffffffffffe,%rdi
pxor   %xmm0,%xmm0
xor    %esi,%esi
movdqa 0xdc1(%rip),%xmm2
movdqa 0xdc9(%rip),%xmm3
pxor   %xmm1,%xmm1
nopl   0x0(%rax,%rax,1)
movd   0x0(%rbp,%rsi,1),%xmm5
movd   0x4(%rbp,%rsi,1),%xmm4
pcmpeqb %xmm2,%xmm5
punpcklbw %xmm5,%xmm5
punpcklwd %xmm5,%xmm5
pand   %xmm3,%xmm5
paddd  %xmm0,%xmm5
pcmpeqb %xmm2,%xmm4
punpcklbw %xmm4,%xmm4
punpcklwd %xmm4,%xmm4
pand   %xmm3,%xmm4
paddd  %xmm1,%xmm4
movd   0x8(%rbp,%rsi,1),%xmm0
movd   0xc(%rbp,%rsi,1),%xmm1
pcmpeqb %xmm2,%xmm0
punpcklbw %xmm0,%xmm0
punpcklwd %xmm0,%xmm0
pand   %xmm3,%xmm0
paddd  %xmm5,%xmm0
pcmpeqb %xmm2,%xmm1
punpcklbw %xmm1,%xmm1
punpcklwd %xmm1,%xmm1
pand   %xmm3,%xmm1
paddd  %xmm4,%xmm1
add    $0x10,%rsi
add    $0xfffffffffffffffe,%rdi
jne    1250 <main+0xe0>
test   $0x1,%dl
je     130b <main+0x19b>
movd   0x0(%rbp,%rsi,1),%xmm2
movd   0x4(%rbp,%rsi,1),%xmm3
movdqa 0xd25(%rip),%xmm4
pcmpeqb %xmm4,%xmm2
punpcklbw %xmm2,%xmm2
punpcklwd %xmm2,%xmm2
movdqa 0xd21(%rip),%xmm5
pand   %xmm5,%xmm2
paddd  %xmm2,%xmm0
pcmpeqb %xmm4,%xmm3
punpcklbw %xmm3,%xmm3
punpcklwd %xmm3,%xmm3
pand   %xmm5,%xmm3
paddd  %xmm3,%xmm1
paddd  %xmm1,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%ebx
cmp    %rax,%rcx
je     1345 <main+0x1d5>
nopw   0x0(%rax,%rax,1)
xor    %edx,%edx
cmpb   $0xa,0x0(%rbp,%rcx,1)
sete   %dl
add    %edx,%ebx
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1330 <main+0x1c0>
mov    %r15d,%edi
call   1060 <close@plt>
mov    %rbp,%rdi
mov    %r12d,%esi
call   1080 <munmap@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%ebp
sub    %r14d,%ebp
xor    %edi,%edi
call   1070 <time@plt>
lea    0xcc8(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
pxor   %xmm0,%xmm0
xor    %esi,%esi
pxor   %xmm1,%xmm1
test   $0x1,%dl
jne    12c7 <main+0x157>
jmp    130b <main+0x19b>

LLVM IR (-O0):
@.str = [10 x i8] c"intel.txt\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@.str.1 = [16 x i8] c"file_length:%d\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.2 = [66 x i8] c"Finished, total lines is %d \0A total costed time %d sec\0A time:%ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32 0, i32* %7
store i8* null, i8** %8
store i32 0, i32* %9
%14 = call i32 @time(i32* null)
store i32 %14, i32* %10
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %12
%17 = load i32, i32* %12
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %63
19: ; preds = %2
%20 = load i32, i32* %12
%21 = load i32, i32* @SEEK_END
%22 = call i32 @lseek(i32 %20, i32 1, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i8*, i8** %8
%26 = load i32, i32* %7
%27 = load i32, i32* @PROT_READ
%28 = load i32, i32* @MAP_SHARED
%29 = load i32, i32* %12
%30 = call i8* @mmap(i8* %25, i32 %26, i32 %27, i32 %28, i32 %29, i32 0)
store i8* %30, i8** %6
store i32 0, i32* %13
br label %31
31: ; preds = %47, %19
%32 = load i32, i32* %13
%33 = load i32, i32* %7
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %50
35: ; preds = %31
%36 = load i8*, i8** %6
%37 = load i32, i32* %13
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 10
br i1 %42, label %43, label %46
43: ; preds = %35
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %46
46: ; preds = %43, %35
br label %47
47: ; preds = %46
%48 = load i32, i32* %13
%49 = add nsw i32 %48, 1
store i32 %49, i32* %13
br label %31
50: ; preds = %31
%51 = load i32, i32* %12
%52 = call i32 @close(i32 %51)
%53 = load i8*, i8** %6
%54 = load i32, i32* %7
%55 = call i32 @munmap(i8* %53, i32 %54)
%56 = call i32 @time(i32* null)
%57 = load i32, i32* %10
%58 = sub nsw i32 %56, %57
store i32 %58, i32* %11
%59 = load i32, i32* %9
%60 = load i32, i32* %11
%61 = call i32 @time(i32* null)
%62 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i32 %59, i32 %60, i32 %61)
br label %63
63: ; preds = %50, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"intel.txt\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@.str.1 = [16 x i8] c"file_length:%d\0A\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.2 = [66 x i8] c"Finished, total lines is %d \0A total costed time %d sec\0A time:%ld\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @time(i32* null)
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %107
7: ; preds = %2
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @lseek(i32 %5, i32 1, i32 %8)
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @PROT_READ
%12 = load i32, i32* @MAP_SHARED
%13 = tail call i8* @mmap(i8* null, i32 %9, i32 %11, i32 %12, i32 %5, i32 0)
%14 = icmp sgt i32 %9, 0
br i1 %14, label %15, label %99
15: ; preds = %7
%16 = zext i32 %9 to i64
%17 = icmp ult i32 %9, 8
br i1 %17, label %86, label %18
18: ; preds = %15
%19 = and i64 %16, 4294967288
%20 = add nsw i64 %19, -8
%21 = lshr exact i64 %20, 3
%22 = add nuw nsw i64 %21, 1
%23 = and i64 %22, 1
%24 = icmp eq i64 %20, 0
br i1 %24, label %60, label %25
25: ; preds = %18
%26 = and i64 %22, 4611686018427387902
br label %27
27: ; preds = %27, %25
%28 = phi i64 [ 0, %25 ], [ %57, %27 ]
%29 = phi <4 x i32> [ zeroinitializer, %25 ], [ %55, %27 ]
%30 = phi <4 x i32> [ zeroinitializer, %25 ], [ %56, %27 ]
%31 = phi i64 [ 0, %25 ], [ %58, %27 ]
%32 = getelementptr inbounds i8, i8* %13, i64 %28
%33 = bitcast i8* %32 to <4 x i8>*
%34 = load <4 x i8>, <4 x i8>* %33
%35 = getelementptr inbounds i8, i8* %32, i64 4
%36 = bitcast i8* %35 to <4 x i8>*
%37 = load <4 x i8>, <4 x i8>* %36
%38 = icmp eq <4 x i8> %34, <i8 10, i8 10, i8 10, i8 10>
%39 = icmp eq <4 x i8> %37, <i8 10, i8 10, i8 10, i8 10>
%40 = zext <4 x i1> %38 to <4 x i32>
%41 = zext <4 x i1> %39 to <4 x i32>
%42 = add <4 x i32> %29, %40
%43 = add <4 x i32> %30, %41
%44 = or i64 %28, 8
%45 = getelementptr inbounds i8, i8* %13, i64 %44
%46 = bitcast i8* %45 to <4 x i8>*
%47 = load <4 x i8>, <4 x i8>* %46
%48 = getelementptr inbounds i8, i8* %45, i64 4
%49 = bitcast i8* %48 to <4 x i8>*
%50 = load <4 x i8>, <4 x i8>* %49
%51 = icmp eq <4 x i8> %47, <i8 10, i8 10, i8 10, i8 10>
%52 = icmp eq <4 x i8> %50, <i8 10, i8 10, i8 10, i8 10>
%53 = zext <4 x i1> %51 to <4 x i32>
%54 = zext <4 x i1> %52 to <4 x i32>
%55 = add <4 x i32> %42, %53
%56 = add <4 x i32> %43, %54
%57 = add nuw i64 %28, 16
%58 = add i64 %31, 2
%59 = icmp eq i64 %58, %26
br i1 %59, label %60, label %27
60: ; preds = %27, %18
%61 = phi <4 x i32> [ undef, %18 ], [ %55, %27 ]
%62 = phi <4 x i32> [ undef, %18 ], [ %56, %27 ]
%63 = phi i64 [ 0, %18 ], [ %57, %27 ]
%64 = phi <4 x i32> [ zeroinitializer, %18 ], [ %55, %27 ]
%65 = phi <4 x i32> [ zeroinitializer, %18 ], [ %56, %27 ]
%66 = icmp eq i64 %23, 0
br i1 %66, label %80, label %67
67: ; preds = %60
%68 = getelementptr inbounds i8, i8* %13, i64 %63
%69 = bitcast i8* %68 to <4 x i8>*
%70 = load <4 x i8>, <4 x i8>* %69
%71 = getelementptr inbounds i8, i8* %68, i64 4
%72 = bitcast i8* %71 to <4 x i8>*
%73 = load <4 x i8>, <4 x i8>* %72
%74 = icmp eq <4 x i8> %70, <i8 10, i8 10, i8 10, i8 10>
%75 = icmp eq <4 x i8> %73, <i8 10, i8 10, i8 10, i8 10>
%76 = zext <4 x i1> %74 to <4 x i32>
%77 = zext <4 x i1> %75 to <4 x i32>
%78 = add <4 x i32> %64, %76
%79 = add <4 x i32> %65, %77
br label %80
80: ; preds = %60, %67
%81 = phi <4 x i32> [ %61, %60 ], [ %78, %67 ]
%82 = phi <4 x i32> [ %62, %60 ], [ %79, %67 ]
%83 = add <4 x i32> %82, %81
%84 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %83)
%85 = icmp eq i64 %19, %16
br i1 %85, label %99, label %86
86: ; preds = %15, %80
%87 = phi i64 [ 0, %15 ], [ %19, %80 ]
%88 = phi i32 [ 0, %15 ], [ %84, %80 ]
br label %89
89: ; preds = %86, %89
%90 = phi i64 [ %97, %89 ], [ %87, %86 ]
%91 = phi i32 [ %96, %89 ], [ %88, %86 ]
%92 = getelementptr inbounds i8, i8* %13, i64 %90
%93 = load i8, i8* %92
%94 = icmp eq i8 %93, 10
%95 = zext i1 %94 to i32
%96 = add nuw nsw i32 %91, %95
%97 = add nuw nsw i64 %90, 1
%98 = icmp eq i64 %97, %16
br i1 %98, label %99, label %89
99: ; preds = %89, %80, %7
%100 = phi i32 [ 0, %7 ], [ %84, %80 ], [ %96, %89 ]
%101 = tail call i32 @close(i32 %5)
%102 = tail call i32 @munmap(i8* %13, i32 %9)
%103 = tail call i32 @time(i32* null)
%104 = sub nsw i32 %103, %3
%105 = tail call i32 @time(i32* null)
%106 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i32 %100, i32 %104, i32 %105)
br label %107
107: ; preds = %99, %2
ret i32 0
}