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

/* Variables and functions */
int /*<<< orphan*/ log_write_err(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ write(int, char *, int);
int read_write_loop_finish(int fd, char *buf, int count, int data_size) {
  if (count > 0) {
    if (write(fd, buf, count) < 0) {
      log_write_err(fd);
      return -1;
    }
  }
  if (data_size < 0) {
    perror("Error: Could not read from parent stdin");
  }
  return data_size;
}


x86 assembly (clang, -O0):
<read_write_loop_finish>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1181 <read_write_loop_finish+0x51>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    117c <read_write_loop_finish+0x4c>
mov    -0x8(%rbp),%edi
call   1040 <log_write_err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119d <read_write_loop_finish+0x6d>
jmp    1181 <read_write_loop_finish+0x51>
cmpl   $0x0,-0x18(%rbp)
jge    1197 <read_write_loop_finish+0x67>
lea    0xe6e(%rip),%rdi
call   1050 <perror@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_write_loop_finish>:
push   %rbp
push   %rbx
push   %rax
mov    %ecx,%ebx
test   %edx,%edx
jle    1145 <read_write_loop_finish+0x15>
mov    %edi,%ebp
call   1030 <write@plt>
test   %rax,%rax
js     1157 <read_write_loop_finish+0x27>
test   %ebx,%ebx
jns    1163 <read_write_loop_finish+0x33>
lea    0xeb0(%rip),%rdi
call   1050 <perror@plt>
jmp    1163 <read_write_loop_finish+0x33>
mov    %ebp,%edi
call   1040 <log_write_err@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Error: Could not read from parent stdin\00"
define i32 @read_write_loop_finish(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%10 = load i32, i32* %8
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %4
%13 = load i32, i32* %6
%14 = load i8*, i8** %7
%15 = load i32, i32* %8
%16 = call i64 @write(i32 %13, i8* %14, i32 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i32, i32* %6
%20 = call i32 @log_write_err(i32 %19)
store i32 -1, i32* %5
br label %29
21: ; preds = %12
br label %22
22: ; preds = %21, %4
%23 = load i32, i32* %9
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = load i32, i32* %9
store i32 %28, i32* %5
br label %29
29: ; preds = %27, %18
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
@.str = [40 x i8] c"Error: Could not read from parent stdin\00"
define i32 @read_write_loop_finish(i32 %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %11
6: ; preds = %4
%7 = tail call i64 @write(i32 %0, i8* %1, i32 %2)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @log_write_err(i32 %0)
br label %15
11: ; preds = %6, %4
%12 = icmp slt i32 %3, 0
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %11, %13, %9
%16 = phi i32 [ -1, %9 ], [ %3, %13 ], [ %3, %11 ]
ret i32 %16
}