#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 EAGAIN;
int EINTR;
char *dlib_syserr();
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getpid();
int read(int, void *, size_t);
int /*<<< orphan*/ stderr;
ssize_t dlib_so_read(int fd, void *buf, size_t size) {
  int ret = 0;
  int cnt = 0;
  while (1) {
    cnt++;
    ret = read(fd, buf, size);
    if (ret == -1) {
      if (errno == EINTR || errno == EAGAIN) {
        continue;
      }
      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",
                232, getpid(), "ERR");
        fprintf(stderr, "%d: read: msg=(%s)", errno, dlib_syserr());
        fprintf(stderr, "\n");
      } while (0);
      ;
      return errno;
    }
    break;
  }
  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",
            238, getpid(), "DBG");
    fprintf(stderr, "read time: cnt=%d", cnt);
    fprintf(stderr, "\n");
  } while (0);
  ;
  return ret;
}


x86 assembly (clang, -O0):
<dlib_so_read>:
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)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1259 <dlib_so_read+0x119>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%eax
je     11b7 <dlib_so_read+0x77>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%eax
jne    11bc <dlib_so_read+0x7c>
jmp    1161 <dlib_so_read+0x21>
jmp    11c1 <dlib_so_read+0x81>
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%r8d
lea    0xe1f(%rip),%rsi
lea    0xe26(%rip),%rdx
mov    $0xe8,%ecx
lea    0xea2(%rip),%r9
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1040 <dlib_syserr@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%edx
mov    %rax,%rcx
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d4 <dlib_so_read+0x194>
jmp    125e <dlib_so_read+0x11e>
jmp    1263 <dlib_so_read+0x123>
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%r8d
lea    0xd7d(%rip),%rsi
lea    0xd84(%rip),%rdx
mov    $0xee,%ecx
lea    0xe19(%rip),%r9
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1060 <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_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%r12d
mov    $0x1,%ebx
mov    0x2e70(%rip),%r13
mov    %r12d,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
jne    120a <dlib_so_read+0xca>
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
add    $0x1,%ebx
cmp    0x0(%r13),%eax
je     1160 <dlib_so_read+0x20>
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%eax
je     1160 <dlib_so_read+0x20>
mov    0x2e45(%rip),%r14
mov    (%r14),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe54(%rip),%rsi
lea    0xe5b(%rip),%rdx
lea    0xedc(%rip),%r9
mov    %ebx,%edi
mov    $0xe8,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%ebx
mov    0x2e03(%rip),%r15
mov    (%r15),%ebp
xor    %eax,%eax
call   1040 <dlib_syserr@plt>
lea    0xeb4(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%edi
lea    0xeaf(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r15),%ebp
jmp    1268 <dlib_so_read+0x128>
mov    %eax,%ebp
mov    0x2dcd(%rip),%r15
mov    (%r15),%r14d
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xddc(%rip),%rsi
lea    0xde3(%rip),%rdx
lea    0xe7d(%rip),%r9
mov    %r14d,%edi
mov    $0xee,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r15),%edi
lea    0xe65(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r15),%edi
lea    0xe4c(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@EINTR = global i32 0
@EAGAIN = global i32 0
@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: read: msg=(%s)\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [4 x i8] c"DBG\00"
@.str.6 = [18 x i8] c"read time: cnt=%d\00"
define i32 @dlib_so_read(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = 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
br label %10
10: ; preds = %3, %27
%11 = load i32, i32* %9
%12 = add nsw i32 %11, 1
store i32 %12, i32* %9
%13 = load i32, i32* %5
%14 = load i8*, i8** %6
%15 = load i64, i64* %7
%16 = call i32 @read(i32 %13, i8* %14, i64 %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %41
19: ; preds = %10
%20 = load i32, i32* @errno
%21 = load i32, i32* @EINTR
%22 = icmp eq i32 %20, %21
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = load i32, i32* @errno
%25 = load i32, i32* @EAGAIN
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23, %19
br label %10
28: ; preds = %23
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 232, 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* @errno
%35 = call i8* (...) @dlib_syserr()
%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, i8* %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
%40 = load i32, i32* @errno
store i32 %40, i32* %4
br label %54
41: ; preds = %10
br label %42
42: ; preds = %41
br label %43
43: ; preds = %42
%44 = load i32, i32* @stderr
%45 = call i32 (...) @getpid()
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, 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 238, i32 %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%47 = load i32, i32* @stderr
%48 = load i32, i32* %9
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %48)
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %52
52: ; preds = %43
%53 = load i32, i32* %8
store i32 %53, i32* %4
br label %54
54: ; preds = %52, %39
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
@errno = global i32 0
@EINTR = global i32 0
@EAGAIN = global i32 0
@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: read: msg=(%s)\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [4 x i8] c"DBG\00"
@.str.6 = [18 x i8] c"read time: cnt=%d\00"
define i32 @dlib_so_read(i32 %0, i8* nocapture %1, i64 %2) {
br label %4
4: ; preds = %9, %3
%5 = phi i32 [ 0, %3 ], [ %6, %9 ]
%6 = add nuw nsw i32 %5, 1
%7 = tail call i32 @read(i32 %0, i8* %1, i64 %2)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %27
9: ; preds = %4
%10 = load i32, i32* @errno
%11 = load i32, i32* @EINTR
%12 = icmp eq i32 %10, %11
%13 = load i32, i32* @EAGAIN
%14 = icmp eq i32 %10, %13
%15 = select i1 %12, i1 true, i1 %14
br i1 %15, label %4, label %16
16: ; preds = %9
%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 232, i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = tail call i8* (...) @dlib_syserr()
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %21, i8* %22)
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%26 = load i32, i32* @errno
br label %35
27: ; preds = %4
%28 = load i32, i32* @stderr
%29 = tail call i32 (...) @getpid()
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, 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 238, i32 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %6)
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %27, %16
%36 = phi i32 [ %26, %16 ], [ %7, %27 ]
ret i32 %36
}