#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_max(const char *filename, long max_lines) {
  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;
      if (line_count >= max_lines) {
        return max_lines;
      }
    }
  }
  gzclose(gzf);
  return line_count;
}


x86 assembly (clang, -O0):
<util_count_lines_max>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <util_must_gzopen@plt>
mov    %eax,-0x2c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
call   1040 <gzgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2e78(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11b9 <util_count_lines_max+0x89>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    11b4 <util_count_lines_max+0x84>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jl     11af <util_count_lines_max+0x7f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c9 <util_count_lines_max+0x99>
jmp    11b4 <util_count_lines_max+0x84>
jmp    115b <util_count_lines_max+0x2b>
mov    -0x2c(%rbp),%edi
call   1030 <gzclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_count_lines_max>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xebf(%rip),%rsi
call   1050 <util_must_gzopen@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <gzgetc@plt>
mov    0x2e92(%rip),%r15
cmp    (%r15),%al
jne    1175 <util_count_lines_max+0x45>
xor    %ebx,%ebx
mov    %ebp,%edi
call   1030 <gzclose@plt>
mov    %rbx,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
jmp    118c <util_count_lines_max+0x5c>
nopl   0x0(%rax)
mov    %ebp,%edi
call   1040 <gzgetc@plt>
cmp    (%r15),%al
je     115d <util_count_lines_max+0x2d>
cmp    $0xa,%al
jne    1180 <util_count_lines_max+0x50>
add    $0x1,%rbx
cmp    %r14,%rbx
jl     1180 <util_count_lines_max+0x50>
jmp    1167 <util_count_lines_max+0x37>

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

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