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

/* Variables and functions */
char EOF;
int /*<<< orphan*/ gzclose(int /*<<< orphan*/);
char gzgetc(int /*<<< orphan*/);
int /*<<< orphan*/ util_must_gzopen(char const *, char *);
long util_count_lines(const char *filename) {
  char c;
  long line_count;
  gzFile gzf;
  gzf = util_must_gzopen(filename, "rb");
  line_count = 0;
  while ((c = gzgetc(gzf)) != EOF) {
    if (c == '\n') {
      line_count += 1;
    }
  }
  gzclose(gzf);
  return line_count;
}


x86 assembly (clang, -O0):
<util_count_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <util_must_gzopen@plt>
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <gzgetc@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
mov    0x2e7c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1195 <util_count_lines+0x65>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    1190 <util_count_lines+0x60>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1157 <util_count_lines+0x27>
mov    -0x1c(%rbp),%edi
call   1030 <gzclose@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_count_lines>:
push   %rbp
push   %r14
push   %rbx
lea    0xec5(%rip),%rsi
call   1050 <util_must_gzopen@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <gzgetc@plt>
mov    0x2e98(%rip),%r14
cmp    (%r14),%al
jne    1159 <util_count_lines+0x29>
xor    %ebx,%ebx
jmp    1176 <util_count_lines+0x46>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %rcx,%rbx
mov    %ebp,%edi
call   1040 <gzgetc@plt>
cmp    (%r14),%al
jne    1160 <util_count_lines+0x30>
mov    %ebp,%edi
call   1030 <gzclose@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@EOF = global i8 0
define i64 @util_count_lines(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @util_must_gzopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %7, i32* %5
store i64 0, i64* %4
br label %8
8: ; preds = %22, %1
%9 = load i32, i32* %5
%10 = call signext i8 @gzgetc(i32 %9)
store i8 %10, i8* %3
%11 = sext i8 %10 to i32
%12 = load i8, i8* @EOF
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %11, %13
br i1 %14, label %15, label %23
15: ; preds = %8
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i64, i64* %4
%21 = add nsw i64 %20, 1
store i64 %21, i64* %4
br label %22
22: ; preds = %19, %15
br label %8
23: ; preds = %8
%24 = load i32, i32* %5
%25 = call i32 @gzclose(i32 %24)
%26 = load i64, i64* %4
ret i64 %26
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@EOF = global i8 0
define i64 @util_count_lines(i8* %0) {
%2 = tail call i32 @util_must_gzopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = tail call signext i8 @gzgetc(i32 %2)
%4 = load i8, i8* @EOF
%5 = icmp eq i8 %3, %4
br i1 %5, label %15, label %6
6: ; preds = %1, %6
%7 = phi i8 [ %12, %6 ], [ %3, %1 ]
%8 = phi i64 [ %11, %6 ], [ 0, %1 ]
%9 = icmp eq i8 %7, 10
%10 = zext i1 %9 to i64
%11 = add nuw nsw i64 %8, %10
%12 = tail call signext i8 @gzgetc(i32 %2)
%13 = load i8, i8* @EOF
%14 = icmp eq i8 %12, %13
br i1 %14, label %15, label %6
15: ; preds = %6, %1
%16 = phi i64 [ 0, %1 ], [ %11, %6 ]
%17 = tail call i32 @gzclose(i32 %2)
ret i64 %16
}