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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ my_err(char *, char *, int, long);
long strlen(char *);
void util_fwrite_line_subset(FILE *input_fh, FILE *output_fh, long n_lines,
                             unsigned char *line_flags) {
  long i, len;
  char buf[16348];
  i = 0;
  while (fgets(buf, 16348, input_fh) != NULL) {
    len = strlen(buf);
    if (buf[len - 1] != '\n') {
      my_err("%s:%d: line %ld is too long\n",
             "/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",
             113, i + 1);
    }
    if (i >= n_lines) {
      my_err("%s:%d: line has more lines than expected (%ld)",
             "/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",
             118, n_lines);
    }
    if (line_flags[i]) {
      fprintf(output_fh, "%s", buf);
    }
    i += 1;
  }
}


x86 assembly (clang, -O0):
<util_fwrite_line_subset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4010,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x4010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x3fdc,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     122f <util_fwrite_line_subset+0xef>
lea    -0x4010(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    $0x1,%rax
movsbl -0x4010(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     11cb <util_fwrite_line_subset+0x8b>
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
lea    0xe46(%rip),%rdi
lea    0xe5c(%rip),%rsi
mov    $0x71,%edx
call   1060 <my_err@plt>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jl     11f5 <util_fwrite_line_subset+0xb5>
mov    -0x18(%rbp),%rcx
lea    0xec2(%rip),%rdi
lea    0xe32(%rip),%rsi
mov    $0x76,%edx
call   1060 <my_err@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     121e <util_fwrite_line_subset+0xde>
mov    -0x10(%rbp),%rdi
lea    -0x4010(%rbp),%rdx
lea    0xebc(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1163 <util_fwrite_line_subset+0x23>
add    $0x4010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_fwrite_line_subset>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3fe8,%rsp
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3fdc,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1217 <util_fwrite_line_subset+0xd7>
xor    %ebp,%ebp
jmp    1199 <util_fwrite_line_subset+0x59>
nopl   (%rax)
add    $0x1,%rbp
mov    %rbx,%rdi
mov    $0x3fdc,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1217 <util_fwrite_line_subset+0xd7>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11c0 <util_fwrite_line_subset+0x80>
cmp    %r13,%rbp
jge    11e1 <util_fwrite_line_subset+0xa1>
cmpb   $0x0,(%r14,%rbp,1)
jne    1207 <util_fwrite_line_subset+0xc7>
jmp    1180 <util_fwrite_line_subset+0x40>
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%rbp),%rcx
lea    0xe35(%rip),%rdi
lea    0xe4b(%rip),%rsi
mov    $0x71,%edx
call   1060 <my_err@plt>
cmp    %r13,%rbp
jl     11ad <util_fwrite_line_subset+0x6d>
lea    0xebe(%rip),%rdi
lea    0xe2e(%rip),%rsi
mov    $0x76,%edx
mov    %r13,%rcx
call   1060 <my_err@plt>
cmpb   $0x0,(%r14,%rbp,1)
je     1180 <util_fwrite_line_subset+0x40>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <fputs@plt>
jmp    1180 <util_fwrite_line_subset+0x40>
add    $0x3fe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"%s:%d: line %ld is too long\0A\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 = [47 x i8] c"%s:%d: line has more lines than expected (%ld)\00"
@.str.3 = [3 x i8] c"%s\00"
define void @util_fwrite_line_subset(i32* %0, i32* %1, i64 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca [16348 x i8]
store i32* %0, i32** %5
store i32* %1, i32** %6
store i64 %2, i64* %7
store i8* %3, i8** %8
store i64 0, i64* %9
br label %12
12: ; preds = %47, %4
%13 = getelementptr inbounds [16348 x i8], [16348 x i8]* %11, i64 0, i64 0
%14 = load i32*, i32** %5
%15 = call i32* @fgets(i8* %13, i32 16348, i32* %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %50
17: ; preds = %12
%18 = getelementptr inbounds [16348 x i8], [16348 x i8]* %11, i64 0, i64 0
%19 = call i64 @strlen(i8* %18)
store i64 %19, i64* %10
%20 = load i64, i64* %10
%21 = sub nsw i64 %20, 1
%22 = getelementptr inbounds [16348 x i8], [16348 x i8]* %11, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 10
br i1 %25, label %26, label %30
26: ; preds = %17
%27 = load i64, i64* %9
%28 = add nsw i64 %27, 1
%29 = call i32 @my_err(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 113, i64 %28)
br label %30
30: ; preds = %26, %17
%31 = load i64, i64* %9
%32 = load i64, i64* %7
%33 = icmp sge i64 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i64, i64* %7
%36 = call i32 @my_err(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 118, i64 %35)
br label %37
37: ; preds = %34, %30
%38 = load i8*, i8** %8
%39 = load i64, i64* %9
%40 = getelementptr inbounds i8, i8* %38, i64 %39
%41 = load i8, i8* %40
%42 = icmp ne i8 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %37
%44 = load i32*, i32** %6
%45 = getelementptr inbounds [16348 x i8], [16348 x i8]* %11, i64 0, i64 0
%46 = call i32 @fprintf(i32* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %43, %37
%48 = load i64, i64* %9
%49 = add nsw i64 %48, 1
store i64 %49, i64* %9
br label %12
50: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"%s:%d: line %ld is too long\0A\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 = [47 x i8] c"%s:%d: line has more lines than expected (%ld)\00"
define void @util_fwrite_line_subset(i32* nocapture %0, i32* nocapture %1, i64 %2, i8* nocapture %3) {
%5 = alloca [16348 x i8]
%6 = getelementptr inbounds [16348 x i8], [16348 x i8]* %5, i64 0, i64 0
%7 = call i32* @fgets(i8* %6, i32 16348, i32* %0)
%8 = icmp eq i32* %7, null
br i1 %8, label %33, label %9
9: ; preds = %4, %29
%10 = phi i64 [ %30, %29 ], [ 0, %4 ]
%11 = call i64 @strlen(i8* %6)
%12 = add nsw i64 %11, -1
%13 = getelementptr inbounds [16348 x i8], [16348 x i8]* %5, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 10
br i1 %15, label %19, label %16
16: ; preds = %9
%17 = add nuw nsw i64 %10, 1
%18 = call i32 @my_err(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 113, i64 %17)
br label %19
19: ; preds = %16, %9
%20 = icmp slt i64 %10, %2
br i1 %20, label %23, label %21
21: ; preds = %19
%22 = call i32 @my_err(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 118, i64 %2)
br label %23
23: ; preds = %21, %19
%24 = getelementptr inbounds i8, i8* %3, i64 %10
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = call i32 @fputs(i8* %6, i32* %1)
br label %29
29: ; preds = %27, %23
%30 = add nuw nsw i64 %10, 1
%31 = call i32* @fgets(i8* %6, i32 16348, i32* %0)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %9
33: ; preds = %29, %4
ret void
}