#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 */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ *gzgets(int /*<<< orphan*/, char *, int);
scalar_t__ gzseek(int /*<<< orphan*/, long, int /*<<< orphan*/);
int /*<<< orphan*/ my_err(char *, char *, int, ...);
int strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
long util_gzcount_lines_match(gzFile gzf, const char *starts_with) {
  char buf[16348];
  long line_count;
  int started_with, at_line_start;
  int match_len, len;
  if (gzseek(gzf, 0L, SEEK_SET) != 0) {
    my_err("%s:%d: could not rewind filehandle",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/"
           "util.c",
           289);
  }
  match_len = strlen(starts_with);
  if (match_len == 0) {
    return 0;
  }
  if (match_len > 16348) {
    my_err("%s:%d: length of string to match must be"
           "<= %d bytes",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/"
           "util.c",
           299, 16348);
  }
  line_count = 0;
  started_with = 0;
  at_line_start = 1;
  while (gzgets(gzf, buf, 16348) != NULL) {
    if (at_line_start) {
      if (strncmp(starts_with, buf, match_len) == 0) {
        started_with = 1;
      }
    }
    len = strlen(buf);
    if (buf[len - 1] == '\n') {
      if (started_with) {
        line_count++;
        started_with = 0;
      }
      at_line_start = 1;
    } else {
      at_line_start = 0;
    }
  }
  if (gzseek(gzf, 0L, SEEK_SET) != 0) {
    my_err("%s:%d: could not rewind filehandle",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/"
           "util.c",
           328);
  }
  return line_count;
}


x86 assembly (clang, -O0):
<util_gzcount_lines_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4020,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e74(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gzseek@plt>
cmp    $0x0,%rax
je     119b <util_gzcount_lines_match+0x4b>
lea    0xe78(%rip),%rdi
lea    0xe94(%rip),%rsi
mov    $0x121,%edx
mov    $0x0,%al
call   1070 <my_err@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x4014(%rbp)
cmpl   $0x0,-0x4014(%rbp)
jne    11c4 <util_gzcount_lines_match+0x74>
movq   $0x0,-0x8(%rbp)
jmp    1325 <util_gzcount_lines_match+0x1d5>
cmpl   $0x3fdc,-0x4014(%rbp)
jle    11f3 <util_gzcount_lines_match+0xa3>
lea    0xed1(%rip),%rdi
lea    0xe41(%rip),%rsi
mov    $0x12b,%edx
mov    $0x3fdc,%ecx
mov    $0x0,%al
call   1070 <my_err@plt>
movq   $0x0,-0x4008(%rbp)
movl   $0x0,-0x400c(%rbp)
movl   $0x1,-0x4010(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x4000(%rbp),%rsi
mov    $0x3fdc,%edx
call   1040 <gzgets@plt>
cmp    $0x0,%rax
je     12e1 <util_gzcount_lines_match+0x191>
cmpl   $0x0,-0x4010(%rbp)
je     126c <util_gzcount_lines_match+0x11c>
mov    -0x18(%rbp),%rdi
lea    -0x4000(%rbp),%rsi
mov    -0x4014(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1267 <util_gzcount_lines_match+0x117>
movl   $0x1,-0x400c(%rbp)
jmp    126c <util_gzcount_lines_match+0x11c>
lea    -0x4000(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x4018(%rbp)
mov    -0x4018(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x4000(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    12d2 <util_gzcount_lines_match+0x182>
cmpl   $0x0,-0x400c(%rbp)
je     12c3 <util_gzcount_lines_match+0x173>
mov    -0x4008(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x4008(%rbp)
movl   $0x0,-0x400c(%rbp)
movl   $0x1,-0x4010(%rbp)
jmp    12dc <util_gzcount_lines_match+0x18c>
movl   $0x0,-0x4010(%rbp)
jmp    1212 <util_gzcount_lines_match+0xc2>
mov    -0xc(%rbp),%edi
mov    0x2cf5(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gzseek@plt>
cmp    $0x0,%rax
je     131a <util_gzcount_lines_match+0x1ca>
lea    0xcf9(%rip),%rdi
lea    0xd15(%rip),%rsi
mov    $0x148,%edx
mov    $0x0,%al
call   1070 <my_err@plt>
mov    -0x4008(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_gzcount_lines_match>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3ff8,%rsp
mov    %rsi,0x8(%rsp)
mov    %edi,%r12d
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <gzseek@plt>
test   %rax,%rax
je     1198 <util_gzcount_lines_match+0x48>
lea    0xe7b(%rip),%rdi
lea    0xe97(%rip),%rsi
mov    $0x121,%edx
xor    %eax,%eax
call   1070 <my_err@plt>
mov    0x8(%rsp),%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     129a <util_gzcount_lines_match+0x14a>
mov    %eax,%r15d
cmp    $0x3fdd,%eax
jl     11d3 <util_gzcount_lines_match+0x83>
lea    0xef1(%rip),%rdi
lea    0xe61(%rip),%rsi
mov    $0x12b,%edx
mov    $0x3fdc,%ecx
xor    %eax,%eax
call   1070 <my_err@plt>
lea    0x10(%rsp),%rbx
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x3fdc,%edx
call   1040 <gzgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1266 <util_gzcount_lines_match+0x116>
mov    $0x1,%r13d
xor    %r14d,%r14d
jmp    1243 <util_gzcount_lines_match+0xf3>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
test   %r14d,%r14d
setne  %cl
xor    %r13d,%r13d
cmpb   $0xa,-0x1(%rax,%rbx,1)
mov    $0x0,%eax
cmove  %eax,%r14d
sete   %r13b
and    %r13b,%cl
movzbl %cl,%eax
add    %rax,%rbp
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x3fdc,%edx
call   1040 <gzgets@plt>
test   %rax,%rax
je     1266 <util_gzcount_lines_match+0x116>
test   %r13d,%r13d
je     1200 <util_gzcount_lines_match+0xb0>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
mov    $0x1,%eax
cmove  %eax,%r14d
jmp    1200 <util_gzcount_lines_match+0xb0>
mov    0x2d73(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1060 <gzseek@plt>
test   %rax,%rax
je     129c <util_gzcount_lines_match+0x14c>
lea    0xd7b(%rip),%rdi
lea    0xd97(%rip),%rsi
mov    $0x148,%edx
xor    %eax,%eax
call   1070 <my_err@plt>
jmp    129c <util_gzcount_lines_match+0x14c>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x3ff8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [35 x i8] c"%s:%d: could not rewind filehandle\00"
@.str.1 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/util.c\00"
@.str.2 = [52 x i8] c"%s:%d: length of string to match must be<= %d bytes\00"
define i64 @util_gzcount_lines_match(i32 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [16348 x i8]
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%12 = load i32, i32* %4
%13 = load i32, i32* @SEEK_SET
%14 = call i64 @gzseek(i32 %12, i64 0, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, i8*, i32, ...) @my_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 289)
br label %18
18: ; preds = %16, %2
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %10
%21 = load i32, i32* %10
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i64 0, i64* %3
br label %74
24: ; preds = %18
%25 = load i32, i32* %10
%26 = icmp sgt i32 %25, 16348
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 (i8*, i8*, i32, ...) @my_err(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 299, i32 16348)
br label %29
29: ; preds = %27, %24
store i64 0, i64* %7
store i32 0, i32* %8
store i32 1, i32* %9
br label %30
30: ; preds = %64, %29
%31 = load i32, i32* %4
%32 = getelementptr inbounds [16348 x i8], [16348 x i8]* %6, i64 0, i64 0
%33 = call i32* @gzgets(i32 %31, i8* %32, i32 16348)
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %65
35: ; preds = %30
%36 = load i32, i32* %9
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %35
%39 = load i8*, i8** %5
%40 = getelementptr inbounds [16348 x i8], [16348 x i8]* %6, i64 0, i64 0
%41 = load i32, i32* %10
%42 = call i64 @strncmp(i8* %39, i8* %40, i32 %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 1, i32* %8
br label %45
45: ; preds = %44, %38
br label %46
46: ; preds = %45, %35
%47 = getelementptr inbounds [16348 x i8], [16348 x i8]* %6, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
store i32 %48, i32* %11
%49 = load i32, i32* %11
%50 = sub nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [16348 x i8], [16348 x i8]* %6, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 10
br i1 %55, label %56, label %63
56: ; preds = %46
%57 = load i32, i32* %8
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i64, i64* %7
%61 = add nsw i64 %60, 1
store i64 %61, i64* %7
store i32 0, i32* %8
br label %62
62: ; preds = %59, %56
store i32 1, i32* %9
br label %64
63: ; preds = %46
store i32 0, i32* %9
br label %64
64: ; preds = %63, %62
br label %30
65: ; preds = %30
%66 = load i32, i32* %4
%67 = load i32, i32* @SEEK_SET
%68 = call i64 @gzseek(i32 %66, i64 0, i32 %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %65
%71 = call i32 (i8*, i8*, i32, ...) @my_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 328)
br label %72
72: ; preds = %70, %65
%73 = load i64, i64* %7
store i64 %73, i64* %3
br label %74
74: ; preds = %72, %23
%75 = load i64, i64* %3
ret i64 %75
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [35 x i8] c"%s:%d: could not rewind filehandle\00"
@.str.1 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/util.c\00"
@.str.2 = [52 x i8] c"%s:%d: length of string to match must be<= %d bytes\00"
define i64 @util_gzcount_lines_match(i32 %0, i8* %1) {
%3 = alloca [16348 x i8]
%4 = getelementptr inbounds [16348 x i8], [16348 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @SEEK_SET
%6 = tail call i64 @gzseek(i32 %0, i64 0, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 (i8*, i8*, i32, ...) @my_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 289)
br label %10
10: ; preds = %8, %2
%11 = tail call i32 @strlen(i8* %1)
%12 = icmp eq i32 %11, 0
br i1 %12, label %52, label %13
13: ; preds = %10
%14 = icmp sgt i32 %11, 16348
br i1 %14, label %15, label %17
15: ; preds = %13
%16 = tail call i32 (i8*, i8*, i32, ...) @my_err(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 299, i32 16348)
br label %17
17: ; preds = %15, %13
%18 = call i32* @gzgets(i32 %0, i8* %4, i32 16348)
%19 = icmp eq i32* %18, null
br i1 %19, label %45, label %20
20: ; preds = %17, %29
%21 = phi i64 [ %42, %29 ], [ 0, %17 ]
%22 = phi i32 [ %39, %29 ], [ 1, %17 ]
%23 = phi i32 [ %38, %29 ], [ 0, %17 ]
%24 = icmp eq i32 %22, 0
br i1 %24, label %29, label %25
25: ; preds = %20
%26 = call i64 @strncmp(i8* %1, i8* %4, i32 %11)
%27 = icmp eq i64 %26, 0
%28 = select i1 %27, i32 1, i32 %23
br label %29
29: ; preds = %25, %20
%30 = phi i32 [ %23, %20 ], [ %28, %25 ]
%31 = call i32 @strlen(i8* %4)
%32 = add nsw i32 %31, -1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [16348 x i8], [16348 x i8]* %3, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 10
%37 = icmp ne i32 %30, 0
%38 = select i1 %36, i32 0, i32 %30
%39 = zext i1 %36 to i32
%40 = select i1 %36, i1 %37, i1 false
%41 = zext i1 %40 to i64
%42 = add nuw nsw i64 %21, %41
%43 = call i32* @gzgets(i32 %0, i8* %4, i32 16348)
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %20
45: ; preds = %29, %17
%46 = phi i64 [ 0, %17 ], [ %42, %29 ]
%47 = load i32, i32* @SEEK_SET
%48 = call i64 @gzseek(i32 %0, i64 0, i32 %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %45
%51 = call i32 (i8*, i8*, i32, ...) @my_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 328)
br label %52
52: ; preds = %45, %50, %10
%53 = phi i64 [ 0, %10 ], [ %46, %50 ], [ %46, %45 ]
ret i64 %53
}