#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 /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ stderr;
int write(int, int /*<<< orphan*/ const *, int);
void dowrite(int fd, const uint8_t *buf, int len, const char *name) {
  int l = write(fd, buf, len);
  if (l == len)
    return;
  if (l < 0) {
    perror(name);
    exit(1);
  }
  fprintf(stderr, "%s: short write.\n", name);
  exit(1);
}


x86 assembly (clang, -O0):
<dowrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    117a <dowrite+0x3a>
add    $0x30,%rsp
pop    %rbp
ret
cmpl   $0x0,-0x24(%rbp)
jge    1197 <dowrite+0x57>
mov    -0x20(%rbp),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe55(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<dowrite>:
push   %rbp
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%ebp
call   1030 <write@plt>
cmp    %ebp,%eax
jne    1158 <dowrite+0x18>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
test   %eax,%eax
jns    116e <dowrite+0x2e>
mov    %rbx,%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"%s: short write.\0A\00"
define void @dowrite(i32 %0, i32* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%10 = load i32, i32* %5
%11 = load i32*, i32** %6
%12 = load i32, i32* %7
%13 = call i32 @write(i32 %10, i32* %11, i32 %12)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = load i32, i32* %7
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %4
ret void
18: ; preds = %4
%19 = load i32, i32* %9
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i8*, i8** %8
%23 = call i32 @perror(i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %8
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"%s: short write.\0A\00"
define void @dowrite(i32 %0, i32* nocapture %1, i32 %2, i8* %3) {
%5 = tail call i32 @write(i32 %0, i32* %1, i32 %2)
%6 = icmp eq i32 %5, %2
br i1 %6, label %7, label %8
7: ; preds = %4
ret void
8: ; preds = %4
%9 = icmp slt i32 %5, 0
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = tail call i32 @perror(i8* %3)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %3)
%16 = tail call i32 @exit(i32 1)
unreachable
}