#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*/ complain(char *, char const *);
int /*<<< orphan*/ complainx(char *, char const *);
int /*<<< orphan*/ exit(int);
int write(int, void const *, size_t);
void dowrite(const char *path, int fd, const void *buf, size_t len) {
  int result;
  result = write(fd, buf, len);
  if (result < 0) {
    complain("%s: write", path);
    exit(1);
  }
  if ((size_t)result != len) {
    complainx("%s: write: short count", path);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<dowrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    118e <dowrite+0x4e>
mov    -0x8(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1060 <complain@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movslq -0x24(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     11b6 <dowrite+0x76>
mov    -0x8(%rbp),%rsi
lea    0xe63(%rip),%rdi
call   1030 <complainx@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dowrite>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdi,%r14
mov    %esi,%edi
mov    %rdx,%rsi
mov    %rcx,%rdx
call   1040 <write@plt>
test   %eax,%eax
js     116a <dowrite+0x2a>
mov    %eax,%eax
cmp    %rbx,%rax
jne    1183 <dowrite+0x43>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe8f(%rip),%rdi
mov    %r14,%rsi
call   1060 <complain@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
lea    0xe80(%rip),%rdi
mov    %r14,%rsi
call   1030 <complainx@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

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