#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 /*<<< orphan*/ stderr;
int write(int, void *, size_t);
ssize_t dlib_so_write(int fd, void *buf, size_t size) {
  int ret = 0;
  int cnt = 0;
  int i = 0;
  while (i < size) {
    cnt++;
    ret = write(fd, buf, size - i);
    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",
                280, getpid(), "ERR");
        fprintf(stderr, "%d: wrtie: msg=(%s)", errno, dlib_syserr());
        fprintf(stderr, "\n");
      } while (0);
      ;
      return errno;
    } else if (ret == 0) {
      break;
    }
    i += ret;
  }
  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",
            289, getpid(), "DBG");
    fprintf(stderr, "write time: cnt=%d", cnt);
    fprintf(stderr, "\n");
  } while (0);
  ;
  return i;
}


x86 assembly (clang, -O0):
<dlib_so_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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    1297 <dlib_so_write+0x157>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
movslq -0x24(%rbp),%rax
sub    %rax,%rdx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1275 <dlib_so_write+0x135>
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%eax
je     11d3 <dlib_so_write+0x93>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    0x2df5(%rip),%rcx
cmp    (%rcx),%eax
jne    11d8 <dlib_so_write+0x98>
jmp    1168 <dlib_so_write+0x28>
jmp    11dd <dlib_so_write+0x9d>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%r8d
lea    0xe03(%rip),%rsi
lea    0xe0a(%rip),%rdx
mov    $0x118,%ecx
lea    0xe86(%rip),%r9
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <dlib_syserr@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%edx
mov    %rax,%rcx
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    130d <dlib_so_write+0x1cd>
cmpl   $0x0,-0x1c(%rbp)
jne    1284 <dlib_so_write+0x144>
jmp    1297 <dlib_so_write+0x157>
jmp    1289 <dlib_so_write+0x149>
mov    -0x1c(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1168 <dlib_so_write+0x28>
jmp    129c <dlib_so_write+0x15c>
mov    0x2d3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%r8d
lea    0xd44(%rip),%rsi
lea    0xd4b(%rip),%rdx
mov    $0x121,%ecx
lea    0xde1(%rip),%r9
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
lea    0xdae(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dlib_so_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r13
mov    %rsi,%r15
mov    %edi,%r12d
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,0xc(%rsp)
movslq %eax,%r14
mov    %r13,%rbx
sub    %r14,%rbx
mov    %rcx,0x10(%rsp)
lea    0x1(%rcx),%ebp
cmp    %r13,%r14
jae    11c0 <dlib_so_write+0x80>
mov    %r12d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11b0 <dlib_so_write+0x70>
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
add    $0x1,%ebp
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%eax
je     1170 <dlib_so_write+0x30>
mov    0x2e1a(%rip),%rcx
cmp    (%rcx),%eax
je     1170 <dlib_so_write+0x30>
jmp    1228 <dlib_so_write+0xe8>
nopl   0x0(%rax)
test   %eax,%eax
je     11c7 <dlib_so_write+0x87>
mov    0xc(%rsp),%ecx
add    %eax,%ecx
mov    %ecx,%eax
mov    %ebp,%ecx
jmp    115b <dlib_so_write+0x1b>
mov    0x10(%rsp),%rax
mov    %eax,%ebp
mov    0x2e12(%rip),%r14
mov    (%r14),%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe21(%rip),%rsi
lea    0xe28(%rip),%rdx
lea    0xec3(%rip),%r9
mov    %ebx,%edi
mov    $0x121,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%edi
lea    0xeac(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%edi
lea    0xe93(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0xc(%rsp),%eax
jmp    129c <dlib_so_write+0x15c>
mov    0x2db1(%rip),%r14
mov    (%r14),%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xdc0(%rip),%rsi
lea    0xdc7(%rip),%rdx
lea    0xe48(%rip),%r9
mov    %ebx,%edi
mov    $0x118,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%ebx
mov    0x2d6f(%rip),%r15
mov    (%r15),%ebp
xor    %eax,%eax
call   1050 <dlib_syserr@plt>
lea    0xe20(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%edi
lea    0xe1c(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r15),%eax
add    $0x18,%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 = [20 x i8] c"%d: wrtie: msg=(%s)\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [4 x i8] c"DBG\00"
@.str.6 = [19 x i8] c"write time: cnt=%d\00"
define i32 @dlib_so_write(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 = %55, %36, %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 %59
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 i64, i64* %7
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = sub i64 %21, %23
%25 = call i32 @write(i32 %19, i8* %20, i64 %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %50
28: ; preds = %16
%29 = load i32, i32* @errno
%30 = load i32, i32* @EINTR
%31 = icmp eq i32 %29, %30
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = load i32, i32* @errno
%34 = load i32, i32* @EAGAIN
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %32, %28
br label %11
37: ; preds = %32
br label %38
38: ; preds = %37
%39 = load i32, i32* @stderr
%40 = call i32 (...) @getpid()
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %39, 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 280, i32 %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = call i8* (...) @dlib_syserr()
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %43, i8* %44)
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %38
%49 = load i32, i32* @errno
store i32 %49, i32* %4
br label %71
50: ; preds = %16
%51 = load i32, i32* %8
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %50
br label %59
54: ; preds = %50
br label %55
55: ; preds = %54
%56 = load i32, i32* %8
%57 = load i32, i32* %10
%58 = add nsw i32 %57, %56
store i32 %58, i32* %10
br label %11
59: ; preds = %53, %11
br label %60
60: ; preds = %59
%61 = load i32, i32* @stderr
%62 = call i32 (...) @getpid()
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %61, 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 289, i32 %62, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%64 = load i32, i32* @stderr
%65 = load i32, i32* %9
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %65)
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %69
69: ; preds = %60
%70 = load i32, i32* %10
store i32 %70, i32* %4
br label %71
71: ; preds = %69, %48
%72 = load i32, i32* %4
ret i32 %72
}

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