#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*/ tosError_setContext(int /*<<< orphan*/, int /*<<< orphan*/);
int write(int, char const *, int);
int tosFile_write1(int fd, const void *pBuffer, int start, int n) {
  int result;
  tosError_setContext(0, 0);
  ;
  result = write(fd, ((const char *)pBuffer) + start, n);
  if (result != n && result >= 0) {
    return -1;
  }
  return result;
}


x86 assembly (clang, -O0):
<tosFile_write1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
xor    %esi,%esi
mov    %esi,%edi
call   1040 <tosError_setContext@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1179 <tosFile_write1+0x59>
cmpl   $0x0,-0x1c(%rbp)
jl     1179 <tosFile_write1+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    117f <tosFile_write1+0x5f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tosFile_write1>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %edi,%r15d
xor    %edi,%edi
xor    %esi,%esi
call   1040 <tosError_setContext@plt>
movslq %r14d,%rax
add    %rax,%rbp
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
test   %eax,%eax
mov    $0xffffffff,%ecx
cmovs  %eax,%ecx
cmp    %ebx,%eax
cmovne %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @tosFile_write1(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = call i32 @tosError_setContext(i32 0, i32 0)
%12 = load i32, i32* %6
%13 = load i8*, i8** %7
%14 = load i32, i32* %8
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i32, i32* %9
%18 = call i32 @write(i32 %12, i8* %16, i32 %17)
store i32 %18, i32* %10
%19 = load i32, i32* %10
%20 = load i32, i32* %9
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %4
%23 = load i32, i32* %10
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 -1, i32* %5
br label %28
26: ; preds = %22, %4
%27 = load i32, i32* %10
store i32 %27, i32* %5
br label %28
28: ; preds = %26, %25
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
define i32 @tosFile_write1(i32 %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32 @tosError_setContext(i32 0, i32 0)
%6 = sext i32 %2 to i64
%7 = getelementptr inbounds i8, i8* %1, i64 %6
%8 = tail call i32 @write(i32 %0, i8* %7, i32 %3)
%9 = icmp ne i32 %8, %3
%10 = icmp sgt i32 %8, -1
%11 = and i1 %9, %10
%12 = select i1 %11, i32 -1, i32 %8
ret i32 %12
}