#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 long ssize_t;
typedef double clock_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
double clock();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
long getline(char **, size_t *, int /*<<< orphan*/ *);
char *malloc(size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, long, long, double, double);
void count_lines(FILE *f, char *name) {
  size_t linsiz = 256;
  clock_t stc = clock();
  char *linbuf = malloc(linsiz);
  long lincnt = 0;
  long linwidth = 0;
  if (!linbuf) {
    perror("malloc linbuf");
    exit(EXIT_FAILURE);
  };
  memset(linbuf, 0, linsiz);
  do {
    ssize_t linlen = getline(&linbuf, &linsiz, f);
    if (linlen < 0)
      break;
    lincnt++;
    if (linwidth < linlen)
      linwidth = linlen;
  } while (!feof(f));
  clock_t stf = clock();
  double cput = (stf - stc) * 1.0e-6;
  printf("%s: %ld lines, maxwidth %ld in %.4f cpu sec, %.3f µs/l\n", name,
         lincnt, linwidth, cput, (cput * 1.0e6) / lincnt);
  free(linbuf);
}


x86 assembly (clang, -O0):
<count_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x100,-0x18(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f6 <count_lines+0x66>
lea    0xe2d(%rip),%rdi
call   1090 <perror@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x8(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10a0 <getline@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jge    122a <count_lines+0x9a>
jmp    126a <count_lines+0xda>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
jge    124c <count_lines+0xbc>
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1251 <count_lines+0xc1>
mov    -0x8(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1205 <count_lines+0x75>
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  0xd80(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
movsd  -0x50(%rbp),%xmm0
movsd  0xd56(%rip),%xmm1
mulsd  -0x50(%rbp),%xmm1
cvtsi2sdq -0x30(%rbp),%xmm2
divsd  %xmm2,%xmm1
lea    0xd5e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_lines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x18(%rsp)
mov    %rdi,%r15
movq   $0x100,0x20(%rsp)
xor    %eax,%eax
call   1040 <clock@plt>
movsd  %xmm0,0x10(%rsp)
mov    $0x100,%edi
call   1080 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     128c <count_lines+0xfc>
xor    %r14d,%r14d
mov    $0x100,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    0x8(%rsp),%r13
lea    0x20(%rsp),%rbp
xor    %r12d,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   10a0 <getline@plt>
cmp    %rax,%r14
cmovl  %rax,%rbx
test   %rax,%rax
js     122f <count_lines+0x9f>
mov    %r15,%rdi
call   1070 <feof@plt>
add    $0x1,%r12
mov    %rbx,%r14
test   %eax,%eax
je     1200 <count_lines+0x70>
jmp    1232 <count_lines+0xa2>
mov    %r14,%rbx
xor    %eax,%eax
call   1040 <clock@plt>
subsd  0x10(%rsp),%xmm0
mulsd  0xdb9(%rip),%xmm0
movsd  0xdb9(%rip),%xmm1
mulsd  %xmm0,%xmm1
cvtsi2sd %r12,%xmm2
divsd  %xmm2,%xmm1
lea    0xdbb(%rip),%rdi
mov    0x18(%rsp),%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1050 <printf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd7d(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"malloc linbuf\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [57 x i8] c"%s: %ld lines, maxwidth %ld in %.4f cpu sec, %.3f \C2\B5s/l\0A\00"
define void @count_lines(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca double
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca double
%12 = alloca double
store i32* %0, i32** %3
store i8* %1, i8** %4
store i64 256, i64* %5
%13 = call double (...) @clock()
store double %13, double* %6
%14 = load i64, i64* %5
%15 = call i8* @malloc(i64 %14)
store i8* %15, i8** %7
store i64 0, i64* %8
store i64 0, i64* %9
%16 = load i8*, i8** %7
%17 = icmp ne i8* %16, null
br i1 %17, label %22, label %18
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = load i8*, i8** %7
%24 = load i64, i64* %5
%25 = call i32 @memset(i8* %23, i32 0, i64 %24)
br label %26
26: ; preds = %41, %22
%27 = load i32*, i32** %3
%28 = call i64 @getline(i8** %7, i64* %5, i32* %27)
store i64 %28, i64* %10
%29 = load i64, i64* %10
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
br label %46
32: ; preds = %26
%33 = load i64, i64* %8
%34 = add nsw i64 %33, 1
store i64 %34, i64* %8
%35 = load i64, i64* %9
%36 = load i64, i64* %10
%37 = icmp slt i64 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = load i64, i64* %10
store i64 %39, i64* %9
br label %40
40: ; preds = %38, %32
br label %41
41: ; preds = %40
%42 = load i32*, i32** %3
%43 = call i32 @feof(i32* %42)
%44 = icmp ne i32 %43, 0
%45 = xor i1 %44, true
br i1 %45, label %26, label %46
46: ; preds = %41, %31
%47 = call double (...) @clock()
store double %47, double* %11
%48 = load double, double* %11
%49 = load double, double* %6
%50 = fsub double %48, %49
%51 = fmul double %50, 0x3EB0C6F7A0B5ED8D
store double %51, double* %12
%52 = load i8*, i8** %4
%53 = load i64, i64* %8
%54 = load i64, i64* %9
%55 = load double, double* %12
%56 = load double, double* %12
%57 = fmul double %56, 1.000000e+06
%58 = load i64, i64* %8
%59 = sitofp i64 %58 to double
%60 = fdiv double %57, %59
%61 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i8* %52, i64 %53, i64 %54, double %55, double %60)
%62 = load i8*, i8** %7
%63 = call i32 @free(i8* %62)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"malloc linbuf\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [57 x i8] c"%s: %ld lines, maxwidth %ld in %.4f cpu sec, %.3f \C2\B5s/l\0A\00"
define void @count_lines(i32* %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = bitcast i64* %3 to i8*
store i64 256, i64* %3
%6 = tail call double (...) @clock()
%7 = bitcast i8** %4 to i8*
%8 = tail call dereferenceable_or_null(256) i8* @malloc(i64 256)
store i8* %8, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = tail call i32 @memset(i8* %8, i32 0, i64 256)
br label %16
16: ; preds = %24, %14
%17 = phi i64 [ 0, %14 ], [ %23, %24 ]
%18 = phi i64 [ 0, %14 ], [ %21, %24 ]
%19 = call i64 @getline(i8** %4, i64* %3, i32* %0)
%20 = icmp slt i64 %19, 0
%21 = add nuw nsw i64 %18, 1
%22 = icmp slt i64 %17, %19
%23 = select i1 %22, i64 %19, i64 %17
br i1 %20, label %27, label %24
24: ; preds = %16
%25 = call i32 @feof(i32* %0)
%26 = icmp eq i32 %25, 0
br i1 %26, label %16, label %27
27: ; preds = %16, %24
%28 = phi i64 [ %18, %16 ], [ %21, %24 ]
%29 = phi i64 [ %17, %16 ], [ %23, %24 ]
%30 = call double (...) @clock()
%31 = fsub double %30, %6
%32 = fmul double %31, 0x3EB0C6F7A0B5ED8D
%33 = fmul double %32, 1.000000e+06
%34 = sitofp i64 %28 to double
%35 = fdiv double %33, %34
%36 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i8* %1, i64 %28, i64 %29, double %32, double %35)
%37 = load i8*, i8** %4
%38 = call i32 @free(i8* %37)
ret void
}