#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 scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int);
scalar_t__ write(int, char const *, int);
void xwrite(int fd, const char *buffer, size_t len) {
  const char *point, *end;
  ssize_t res;
  point = buffer;
  end = point + len;
  while (point < end) {
    res = write(fd, point, end - point);
    if (res < 0) {
      exit(1);
    }
    assert(res != 0);
    point += res;
  }
}


x86 assembly (clang, -O0):
<xwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11ba <xwrite+0x8a>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <write@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    1197 <xwrite+0x67>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpq   $0x0,-0x30(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x30(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1157 <xwrite+0x27>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xwrite>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdx,%rdx
jle    117b <xwrite+0x4b>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
add    %rsi,%r14
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edx
sub    %ebx,%edx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
test   %rax,%rax
js     1186 <xwrite+0x56>
mov    %rax,%rbp
setne  %al
movzbl %al,%edi
call   1040 <assert@plt>
add    %rbp,%rbx
cmp    %r14,%rbx
jb     1150 <xwrite+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
define void @xwrite(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = load i8*, i8** %5
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = load i64, i64* %6
%13 = getelementptr inbounds i8, i8* %11, i64 %12
store i8* %13, i8** %8
br label %14
14: ; preds = %32, %3
%15 = load i8*, i8** %7
%16 = load i8*, i8** %8
%17 = icmp ult i8* %15, %16
br i1 %17, label %18, label %40
18: ; preds = %14
%19 = load i32, i32* %4
%20 = load i8*, i8** %7
%21 = load i8*, i8** %8
%22 = load i8*, i8** %7
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
%27 = call i64 @write(i32 %19, i8* %20, i32 %26)
store i64 %27, i64* %9
%28 = load i64, i64* %9
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %18
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %18
%33 = load i64, i64* %9
%34 = icmp ne i64 %33, 0
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = load i64, i64* %9
%38 = load i8*, i8** %7
%39 = getelementptr inbounds i8, i8* %38, i64 %37
store i8* %39, i8** %7
br label %14
40: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @xwrite(i32 %0, i8* %1, i64 %2) {
%4 = getelementptr inbounds i8, i8* %1, i64 %2
%5 = icmp sgt i64 %2, 0
br i1 %5, label %6, label %23
6: ; preds = %3
%7 = ptrtoint i8* %4 to i64
br label %8
8: ; preds = %6, %17
%9 = phi i8* [ %1, %6 ], [ %21, %17 ]
%10 = ptrtoint i8* %9 to i64
%11 = sub i64 %7, %10
%12 = trunc i64 %11 to i32
%13 = tail call i64 @write(i32 %0, i8* %9, i32 %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %8
%18 = icmp ne i64 %13, 0
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = getelementptr inbounds i8, i8* %9, i64 %13
%22 = icmp ult i8* %21, %4
br i1 %22, label %8, label %23
23: ; preds = %17, %3
ret void
}