#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 */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ error_at_line(int /*<<< orphan*/, scalar_t__, char *, int,
                                 char *, int);
int write(int, void const *, size_t);
int io_write_fixed_length(int fd, const void *buf, size_t count) {
  ssize_t bytes;
  while (count > 0) {
    bytes = write(fd, buf, count);
    if (bytes == 0) {
      error_at_line(0, 0,
                    "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/ncultra/Pegasus-2.5/"
                    "refs/heads/master/src/Pegasus/ProviderManager2/CMPIR/io.c",
                    137,
                    "EOF before writing complete "
                    "chunk of data to fd: %d",
                    fd);
      return -1;
    } else if (bytes == -1) {
      if (errno != EINTR && errno != EAGAIN) {
        error_at_line(
            0, errno,
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/ncultra/Pegasus-2.5/refs/heads/master/"
            "src/Pegasus/ProviderManager2/CMPIR/io.c",
            145,
            "could not write all the "
            "requested data to fd: %d",
            fd);
        return -1;
      }
    } else {
      count -= bytes;
      buf += bytes;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<io_write_fixed_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    122a <io_write_fixed_length+0x10a>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1189 <io_write_fixed_length+0x69>
mov    -0x8(%rbp),%r9d
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    0xe94(%rip),%rdx
mov    $0x89,%ecx
lea    0xf30(%rip),%r8
call   1030 <error_at_line@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <io_write_fixed_length+0x111>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1200 <io_write_fixed_length+0xe0>
mov    0x2e46(%rip),%rax
mov    (%rax),%rax
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
je     11fb <io_write_fixed_length+0xdb>
mov    0x2e2c(%rip),%rax
mov    (%rax),%rax
mov    0x2e0a(%rip),%rcx
cmp    (%rcx),%rax
je     11fb <io_write_fixed_length+0xdb>
mov    0x2e12(%rip),%rax
mov    (%rax),%rsi
mov    -0x8(%rbp),%r9d
xor    %edi,%edi
lea    0xe22(%rip),%rdx
mov    $0x91,%ecx
lea    0xef2(%rip),%r8
call   1030 <error_at_line@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <io_write_fixed_length+0x111>
jmp    1220 <io_write_fixed_length+0x100>
movslq -0x1c(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1225 <io_write_fixed_length+0x105>
jmp    1133 <io_write_fixed_length+0x13>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<io_write_fixed_length>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rdx,%rdx
je     11c6 <io_write_fixed_length+0xa6>
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %edi,%r15d
mov    0x2e99(%rip),%r12
mov    0x2e8a(%rip),%r13
jmp    1161 <io_write_fixed_length+0x41>
test   %eax,%eax
je     11a1 <io_write_fixed_length+0x81>
cltq
sub    %rax,%rbp
add    %rax,%rbx
test   %rbp,%rbp
je     11c6 <io_write_fixed_length+0xa6>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1150 <io_write_fixed_length+0x30>
mov    (%r12),%rsi
cmp    0x0(%r13),%rsi
je     115c <io_write_fixed_length+0x3c>
mov    0x2e43(%rip),%rax
cmp    (%rax),%rsi
je     115c <io_write_fixed_length+0x3c>
lea    0xe6f(%rip),%rdx
lea    0xf44(%rip),%r8
xor    %edi,%edi
mov    $0x91,%ecx
jmp    11b8 <io_write_fixed_length+0x98>
lea    0xe58(%rip),%rdx
lea    0xef9(%rip),%r8
xor    %edi,%edi
xor    %esi,%esi
mov    $0x89,%ecx
mov    %r15d,%r9d
call   1030 <error_at_line@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [168 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ncultra/Pegasus-2.5/refs/heads/master/src/Pegasus/ProviderManager2/CMPIR/io.c\00"
@.str.1 = [52 x i8] c"EOF before writing complete chunk of data to fd: %d\00"
@errno = global i64 0
@EINTR = global i64 0
@EAGAIN = global i64 0
@.str.2 = [49 x i8] c"could not write all the requested data to fd: %d\00"
define i32 @io_write_fixed_length(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
br label %9
9: ; preds = %48, %3
%10 = load i64, i64* %7
%11 = icmp ugt i64 %10, 0
br i1 %11, label %12, label %49
12: ; preds = %9
%13 = load i32, i32* %5
%14 = load i8*, i8** %6
%15 = load i64, i64* %7
%16 = call i32 @write(i32 %13, i8* %14, i64 %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i32, i32* %5
%21 = call i32 @error_at_line(i32 0, i64 0, i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str, i64 0, i64 0), i32 137, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %20)
store i32 -1, i32* %4
br label %50
22: ; preds = %12
%23 = load i32, i32* %8
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %38
25: ; preds = %22
%26 = load i64, i64* @errno
%27 = load i64, i64* @EINTR
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %37
29: ; preds = %25
%30 = load i64, i64* @errno
%31 = load i64, i64* @EAGAIN
%32 = icmp ne i64 %30, %31
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i64, i64* @errno
%35 = load i32, i32* %5
%36 = call i32 @error_at_line(i32 0, i64 %34, i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str, i64 0, i64 0), i32 145, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 %35)
store i32 -1, i32* %4
br label %50
37: ; preds = %29, %25
br label %47
38: ; preds = %22
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = load i64, i64* %7
%42 = sub i64 %41, %40
store i64 %42, i64* %7
%43 = load i32, i32* %8
%44 = load i8*, i8** %6
%45 = sext i32 %43 to i64
%46 = getelementptr i8, i8* %44, i64 %45
store i8* %46, i8** %6
br label %47
47: ; preds = %38, %37
br label %48
48: ; preds = %47
br label %9
49: ; preds = %9
store i32 0, i32* %4
br label %50
50: ; preds = %49, %33, %19
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@.str = [168 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ncultra/Pegasus-2.5/refs/heads/master/src/Pegasus/ProviderManager2/CMPIR/io.c\00"
@.str.1 = [52 x i8] c"EOF before writing complete chunk of data to fd: %d\00"
@errno = global i64 0
@EINTR = global i64 0
@EAGAIN = global i64 0
@.str.2 = [49 x i8] c"could not write all the requested data to fd: %d\00"
define i32 @io_write_fixed_length(i32 %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %28, label %5
5: ; preds = %3, %24
%6 = phi i64 [ %26, %24 ], [ %2, %3 ]
%7 = phi i8* [ %25, %24 ], [ %1, %3 ]
%8 = tail call i32 @write(i32 %0, i8* %7, i64 %6)
switch i32 %8, label %20 [
i32 0, label %9
i32 -1, label %11
]
9: ; preds = %5
%10 = tail call i32 @error_at_line(i32 0, i64 0, i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str, i64 0, i64 0), i32 137, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %28
11: ; preds = %5
%12 = load i64, i64* @errno
%13 = load i64, i64* @EINTR
%14 = icmp eq i64 %12, %13
%15 = load i64, i64* @EAGAIN
%16 = icmp eq i64 %12, %15
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %24, label %18
18: ; preds = %11
%19 = tail call i32 @error_at_line(i32 0, i64 %12, i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str, i64 0, i64 0), i32 145, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %28
20: ; preds = %5
%21 = sext i32 %8 to i64
%22 = sub i64 %6, %21
%23 = getelementptr i8, i8* %7, i64 %21
br label %24
24: ; preds = %20, %11
%25 = phi i8* [ %7, %11 ], [ %23, %20 ]
%26 = phi i64 [ %6, %11 ], [ %22, %20 ]
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %5
28: ; preds = %24, %3, %18, %9
%29 = phi i32 [ -1, %9 ], [ -1, %18 ], [ 0, %3 ], [ 0, %24 ]
ret i32 %29
}