#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 ssize_t;

/* Variables and functions */
int dlib_so_read(int, char *, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getpid();
int /*<<< orphan*/ stderr;
ssize_t dlib_so_readline(int fd, char *buf, size_t size) {
  int ret = 0;
  int cnt = 0;
  int i = 0;
  while (i < size) {
    cnt++;
    ret = dlib_so_read(fd, buf + i, size);
    if (ret < 0) {
      do {
        fprintf(stderr, "%s:%d:%d:%s: ",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/Dwylkz/dlib/refs/heads/"
                "master/src/dlib_comm.c",
                251, getpid(), "ERR");
        fprintf(stderr, "%d: so_read: fd=%d", ret, fd);
        fprintf(stderr, "\n");
      } while (0);
      ;
      return -1;
    }
    if (ret == 0)
      break;
    i += ret;
    if (buf[i - 1] == '\n') {
      i--;
      break;
    }
  }
  buf[i] = '\0';
  do {
    fprintf(stderr, "%s:%d:%d:%s: ",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/Dwylkz/dlib/refs/heads/master/src/"
            "dlib_comm.c",
            264, getpid(), "DBG");
    fprintf(stderr, "readline time: cnt=%d", cnt);
    fprintf(stderr, "\n");
  } while (0);
  ;
  return ret;
}


x86 assembly (clang, -O0):
<dlib_so_readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1257 <dlib_so_readline+0x127>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
call   1040 <dlib_so_read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1212 <dlib_so_readline+0xe2>
jmp    1198 <dlib_so_readline+0x68>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%r8d
lea    0xe48(%rip),%rsi
lea    0xe4f(%rip),%rdx
mov    $0xfb,%ecx
lea    0xecb(%rip),%r9
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xeb2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d4 <dlib_so_readline+0x1a4>
cmpl   $0x0,-0x1c(%rbp)
jne    1221 <dlib_so_readline+0xf1>
jmp    1257 <dlib_so_readline+0x127>
mov    -0x1c(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1252 <dlib_so_readline+0x122>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1257 <dlib_so_readline+0x127>
jmp    1158 <dlib_so_readline+0x28>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%r8d
lea    0xd7d(%rip),%rsi
lea    0xd84(%rip),%rdx
mov    $0x108,%ecx
lea    0xe19(%rip),%r9
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dlib_so_readline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
test   %rdx,%rdx
je     1191 <dlib_so_readline+0x61>
mov    %rdx,%r12
mov    %edi,%r14d
xor    %esi,%esi
mov    $0x1,%eax
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%ebx
add    %r15,%rsi
mov    %r14d,%edi
mov    %r12,%rdx
call   1040 <dlib_so_read@plt>
mov    %eax,%r13d
test   %eax,%eax
js     119a <dlib_so_readline+0x6a>
je     11f0 <dlib_so_readline+0xc0>
add    %r13d,%ebp
movslq %ebp,%rsi
cmpb   $0xa,-0x1(%r15,%rsi,1)
je     11f5 <dlib_so_readline+0xc5>
lea    0x1(%rbx),%eax
cmp    %r12,%rsi
jb     1160 <dlib_so_readline+0x30>
jmp    11fb <dlib_so_readline+0xcb>
xor    %r13d,%r13d
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    11fb <dlib_so_readline+0xcb>
mov    0x2e3f(%rip),%rbp
mov    0x0(%rbp),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe4e(%rip),%rsi
lea    0xe55(%rip),%rdx
lea    0xed6(%rip),%r9
mov    %ebx,%edi
mov    $0xfb,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xebf(%rip),%rsi
mov    %r13d,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%r13d
jmp    124f <dlib_so_readline+0x11f>
xor    %r13d,%r13d
jmp    11fb <dlib_so_readline+0xcb>
add    $0xffffffffffffffff,%rsi
mov    %esi,%ebp
movslq %ebp,%rax
movb   $0x0,(%r15,%rax,1)
mov    0x2dd6(%rip),%rbp
mov    0x0(%rbp),%r14d
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xde4(%rip),%rsi
lea    0xdeb(%rip),%rdx
lea    0xe85(%rip),%r9
mov    %r14d,%edi
mov    $0x108,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe6d(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [14 x i8] c"%s:%d:%d:%s: \00"
@.str.1 = [136 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Dwylkz/dlib/refs/heads/master/src/dlib_comm.c\00"
@.str.2 = [4 x i8] c"ERR\00"
@.str.3 = [19 x i8] c"%d: so_read: fd=%d\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [4 x i8] c"DBG\00"
@.str.6 = [22 x i8] c"readline time: cnt=%d\00"
define i32 @dlib_so_readline(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %11
11: ; preds = %59, %3
%12 = load i32, i32* %10
%13 = sext i32 %12 to i64
%14 = load i64, i64* %7
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %60
16: ; preds = %11
%17 = load i32, i32* %9
%18 = add nsw i32 %17, 1
store i32 %18, i32* %9
%19 = load i32, i32* %5
%20 = load i8*, i8** %6
%21 = load i32, i32* %10
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i64, i64* %7
%25 = call i32 @dlib_so_read(i32 %19, i8* %23, i64 %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %40
28: ; preds = %16
br label %29
29: ; preds = %28
%30 = load i32, i32* @stderr
%31 = call i32 (...) @getpid()
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.1, i64 0, i64 0), i32 251, i32 %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* @stderr
%34 = load i32, i32* %8
%35 = load i32, i32* %5
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %35)
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %39
39: ; preds = %29
store i32 -1, i32* %4
br label %76
40: ; preds = %16
%41 = load i32, i32* %8
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %40
br label %60
44: ; preds = %40
%45 = load i32, i32* %8
%46 = load i32, i32* %10
%47 = add nsw i32 %46, %45
store i32 %47, i32* %10
%48 = load i8*, i8** %6
%49 = load i32, i32* %10
%50 = sub nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, 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 %59
56: ; preds = %44
%57 = load i32, i32* %10
%58 = add nsw i32 %57, -1
store i32 %58, i32* %10
br label %60
59: ; preds = %44
br label %11
60: ; preds = %56, %43, %11
%61 = load i8*, i8** %6
%62 = load i32, i32* %10
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
store i8 0, i8* %64
br label %65
65: ; preds = %60
%66 = load i32, i32* @stderr
%67 = call i32 (...) @getpid()
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.1, i64 0, i64 0), i32 264, i32 %67, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%69 = load i32, i32* @stderr
%70 = load i32, i32* %9
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %70)
%72 = load i32, i32* @stderr
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %74
74: ; preds = %65
%75 = load i32, i32* %8
store i32 %75, i32* %4
br label %76
76: ; preds = %74, %39
%77 = load i32, i32* %4
ret i32 %77
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"%s:%d:%d:%s: \00"
@.str.1 = [136 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Dwylkz/dlib/refs/heads/master/src/dlib_comm.c\00"
@.str.2 = [4 x i8] c"ERR\00"
@.str.3 = [19 x i8] c"%d: so_read: fd=%d\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [4 x i8] c"DBG\00"
@.str.6 = [22 x i8] c"readline time: cnt=%d\00"
define i32 @dlib_so_readline(i32 %0, i8* %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %31, label %8
5: ; preds = %24
%6 = sext i32 %25 to i64
%7 = icmp ult i64 %6, %2
br i1 %7, label %8, label %31
8: ; preds = %3, %5
%9 = phi i64 [ %6, %5 ], [ 0, %3 ]
%10 = phi i32 [ %25, %5 ], [ 0, %3 ]
%11 = phi i32 [ %12, %5 ], [ 0, %3 ]
%12 = add nuw nsw i32 %11, 1
%13 = getelementptr inbounds i8, i8* %1, i64 %9
%14 = tail call i32 @dlib_so_read(i32 %0, i8* %13, i64 %2)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %8
%17 = load i32, i32* @stderr
%18 = tail call i32 (...) @getpid()
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.1, i64 0, i64 0), i32 251, i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %14, i32 %0)
br label %42
22: ; preds = %8
%23 = icmp eq i32 %14, 0
br i1 %23, label %31, label %24
24: ; preds = %22
%25 = add nsw i32 %14, %10
%26 = add nsw i32 %25, -1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %1, i64 %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 10
br i1 %30, label %31, label %5
31: ; preds = %5, %22, %24, %3
%32 = phi i32 [ 0, %3 ], [ %14, %24 ], [ 0, %22 ], [ %14, %5 ]
%33 = phi i32 [ 0, %3 ], [ %12, %24 ], [ %12, %22 ], [ %12, %5 ]
%34 = phi i32 [ 0, %3 ], [ %26, %24 ], [ %10, %22 ], [ %25, %5 ]
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %1, i64 %35
store i8 0, i8* %36
%37 = load i32, i32* @stderr
%38 = tail call i32 (...) @getpid()
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.1, i64 0, i64 0), i32 264, i32 %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%40 = load i32, i32* @stderr
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %33)
br label %42
42: ; preds = %31, %16
%43 = phi i32 [ -1, %16 ], [ %32, %31 ]
%44 = load i32, i32* @stderr
%45 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret i32 %43
}