#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*/ __MY_FREE(char *, char *, int);
scalar_t__ gzseek(int /*<<< orphan*/, long, int /*<<< orphan*/);
int /*<<< orphan*/ my_err(char *, char *, int);
char *strsep(char **, char *);
char *util_gzgets_line(int /*<<< orphan*/);
long impute_count_fields(gzFile fh) {
  char *line, *cur, *tok;
  char delim[] = " \t";
  long n;
  line = util_gzgets_line(fh);
  if (line == NULL) {
    my_err("%s:%d: no lines left in file, cannot count fields\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/"
           "impute.c",
           46);
  }
  cur = line;
  n = 0;
  while ((tok = strsep(&cur, delim)) != NULL) {
    n++;
  }
  __MY_FREE(line,
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/"
            "impute.c",
            55);
  (line) = (void *)NULL;
  if (gzseek(fh, 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/"
           "impute.c",
           59);
  }
  return n;
}


x86 assembly (clang, -O0):
<impute_count_fields>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    0xe9e(%rip),%ax
mov    %ax,-0x23(%rbp)
mov    0xe96(%rip),%al
mov    %al,-0x21(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <util_gzgets_line@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119e <impute_count_fields+0x4e>
lea    0xe76(%rip),%rdi
lea    0xea2(%rip),%rsi
mov    $0x2e,%edx
call   1060 <my_err@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
lea    -0x23(%rbp),%rsi
lea    -0x18(%rbp),%rdi
call   1040 <strsep@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11da <impute_count_fields+0x8a>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11ae <impute_count_fields+0x5e>
mov    -0x10(%rbp),%rdi
lea    0xe51(%rip),%rsi
mov    $0x37,%edx
call   1070 <__MY_FREE@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gzseek@plt>
cmp    $0x0,%rax
je     122e <impute_count_fields+0xde>
lea    0xea4(%rip),%rdi
lea    0xe12(%rip),%rsi
mov    $0x3b,%edx
call   1060 <my_err@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<impute_count_fields>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
movb   $0x0,0x6(%rsp)
movw   $0x920,0x4(%rsp)
call   1050 <util_gzgets_line@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1190 <impute_count_fields+0x40>
lea    0xe84(%rip),%rdi
lea    0xeb0(%rip),%rsi
mov    $0x2e,%edx
call   1060 <my_err@plt>
mov    %r15,0x8(%rsp)
mov    $0xffffffffffffffff,%rbx
lea    0x8(%rsp),%r12
lea    0x4(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbp,%rsi
call   1040 <strsep@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    11b0 <impute_count_fields+0x60>
lea    0xe6b(%rip),%rsi
mov    %r15,%rdi
mov    $0x37,%edx
call   1070 <__MY_FREE@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1030 <gzseek@plt>
test   %rax,%rax
je     1208 <impute_count_fields+0xb8>
lea    0xeca(%rip),%rdi
lea    0xe38(%rip),%rsi
mov    $0x3b,%edx
call   1060 <my_err@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.impute_count_fields.delim = [3 x i8] c" \09\00"
@.str = [51 x i8] c"%s:%d: no lines left in file, cannot count fields\0A\00"
@.str.1 = [139 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/impute.c\00"
@SEEK_SET = global i32 0
@.str.2 = [35 x i8] c"%s:%d: could not rewind filehandle\00"
define i64 @impute_count_fields(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [3 x i8]
%7 = alloca i64
store i32 %0, i32* %2
%8 = bitcast [3 x i8]* %6 to i8*
%9 = load i32, i32* %2
%10 = call i8* @util_gzgets_line(i32 %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @my_err(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 46)
br label %15
15: ; preds = %13, %1
%16 = load i8*, i8** %3
store i8* %16, i8** %4
store i64 0, i64* %7
br label %17
17: ; preds = %21, %15
%18 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%19 = call i8* @strsep(i8** %4, i8* %18)
store i8* %19, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i64, i64* %7
%23 = add nsw i64 %22, 1
store i64 %23, i64* %7
br label %17
24: ; preds = %17
%25 = load i8*, i8** %3
%26 = call i32 @__MY_FREE(i8* %25, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 55)
store i8* null, i8** %3
%27 = load i32, i32* %2
%28 = load i32, i32* @SEEK_SET
%29 = call i64 @gzseek(i32 %27, i64 0, i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 @my_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 59)
br label %33
33: ; preds = %31, %24
%34 = load i64, i64* %7
ret i64 %34
}

LLVM IR (-O2):
@__const.impute_count_fields.delim = [3 x i8] c" \09\00"
@.str = [51 x i8] c"%s:%d: no lines left in file, cannot count fields\0A\00"
@.str.1 = [139 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/impute.c\00"
@SEEK_SET = global i32 0
@.str.2 = [35 x i8] c"%s:%d: could not rewind filehandle\00"
define i64 @impute_count_fields(i32 %0) {
%2 = alloca i8*
%3 = alloca [3 x i8]
%4 = bitcast i8** %2 to i8*
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%6 = tail call i8* @util_gzgets_line(i32 %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @my_err(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 46)
br label %10
10: ; preds = %8, %1
store i8* %6, i8** %2
br label %11
11: ; preds = %11, %10
%12 = phi i64 [ 0, %10 ], [ %15, %11 ]
%13 = call i8* @strsep(i8** %2, i8* %5)
%14 = icmp eq i8* %13, null
%15 = add nuw nsw i64 %12, 1
br i1 %14, label %16, label %11
16: ; preds = %11
%17 = call i32 @__MY_FREE(i8* %6, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 55)
%18 = load i32, i32* @SEEK_SET
%19 = call i64 @gzseek(i32 %0, i64 0, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = call i32 @my_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 59)
br label %23
23: ; preds = %21, %16
ret i64 %12
}