#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 */
scalar_t__ errno;
int write(int, char *, int);
int ActualFileWrite(int handle, int bytes, char *buffer) {
  int retval;
  if (handle < 0)
    return (-1);
  if (bytes < 1)
    return (-1);
  if (buffer == NULL)
    return (-1);
  errno = 0;
  retval = write(handle, buffer, bytes);
  if ((retval < 0) || (errno != 0)) {
  }
  return (retval);
}


x86 assembly (clang, -O0):
<ActualFileWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1138 <ActualFileWrite+0x28>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <ActualFileWrite+0x9b>
cmpl   $0x1,-0xc(%rbp)
jge    114e <ActualFileWrite+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <ActualFileWrite+0x9b>
cmpq   $0x0,-0x18(%rbp)
jne    1165 <ActualFileWrite+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <ActualFileWrite+0x9b>
mov    0x2e74(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11a0 <ActualFileWrite+0x90>
mov    0x2e4a(%rip),%rax
cmpq   $0x0,(%rax)
je     11a5 <ActualFileWrite+0x95>
jmp    11a5 <ActualFileWrite+0x95>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ActualFileWrite>:
test   %edi,%edi
js     1137 <ActualFileWrite+0x27>
mov    %esi,%eax
test   %esi,%esi
jle    1137 <ActualFileWrite+0x27>
test   %rdx,%rdx
je     1137 <ActualFileWrite+0x27>
mov    0x2eba(%rip),%rcx
movq   $0x0,(%rcx)
mov    %rdx,%rsi
mov    %eax,%edx
jmp    1030 <write@plt>
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
@errno = global i64 0
define i32 @ActualFileWrite(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 -1, i32* %4
br label %33
12: ; preds = %3
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 -1, i32* %4
br label %33
16: ; preds = %12
%17 = load i8*, i8** %7
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 -1, i32* %4
br label %33
20: ; preds = %16
store i64 0, i64* @errno
%21 = load i32, i32* %5
%22 = load i8*, i8** %7
%23 = load i32, i32* %6
%24 = call i32 @write(i32 %21, i8* %22, i32 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %20
%28 = load i64, i64* @errno
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %27, %20
br label %31
31: ; preds = %30, %27
%32 = load i32, i32* %8
store i32 %32, i32* %4
br label %33
33: ; preds = %31, %19, %15, %11
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@errno = global i64 0
define i32 @ActualFileWrite(i32 %0, i32 %1, i8* %2) {
%4 = icmp slt i32 %0, 0
%5 = icmp slt i32 %1, 1
%6 = or i1 %4, %5
%7 = icmp eq i8* %2, null
%8 = or i1 %6, %7
br i1 %8, label %11, label %9
9: ; preds = %3
store i64 0, i64* @errno
%10 = tail call i32 @write(i32 %0, i8* %2, i32 %1)
br label %11
11: ; preds = %3, %9
%12 = phi i32 [ %10, %9 ], [ -1, %3 ]
ret i32 %12
}