#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*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, size_t, int);
int write(int, void *, size_t);
int Write(int fd, void *buf, size_t bytes, int lineNo) {
  int err;
  err = write(fd, buf, bytes);
  if (err < bytes) {
    printf("Write Error at line %i! Wanted to write %i bytes, but wrote only "
           "%i bytes.\n",
           lineNo, bytes, err);
    perror("Write did not complete. Error. Bye:");
    exit(1);
  }
  return err;
}


x86 assembly (clang, -O0):
<Write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a3 <Write+0x63>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
lea    0xe78(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb8(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Write>:
push   %rbp
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%rbx
call   1030 <write@plt>
movslq %eax,%rcx
cmp    %rbx,%rcx
jb     115c <Write+0x1c>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe9d(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1040 <printf@plt>
lea    0xed6(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [76 x i8] c"Write Error at line %i! Wanted to write %i bytes, but wrote only %i bytes.\0A\00"
@.str.1 = [36 x i8] c"Write did not complete. Error. Bye:\00"
define i32 @Write(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 %3, i32* %8
%10 = load i32, i32* %5
%11 = load i8*, i8** %6
%12 = load i64, i64* %7
%13 = call i32 @write(i32 %10, i8* %11, i64 %12)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = sext i32 %14 to i64
%16 = load i64, i64* %7
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %25
18: ; preds = %4
%19 = load i32, i32* %8
%20 = load i64, i64* %7
%21 = load i32, i32* %9
%22 = call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i32 %19, i64 %20, i32 %21)
%23 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %4
%26 = load i32, i32* %9
ret i32 %26
}

LLVM IR (-O2):
@.str = [76 x i8] c"Write Error at line %i! Wanted to write %i bytes, but wrote only %i bytes.\0A\00"
@.str.1 = [36 x i8] c"Write did not complete. Error. Bye:\00"
define i32 @Write(i32 %0, i8* nocapture %1, i64 %2, i32 %3) {
%5 = tail call i32 @write(i32 %0, i8* %1, i64 %2)
%6 = sext i32 %5 to i64
%7 = icmp ult i64 %6, %2
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = tail call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i32 %3, i64 %2, i32 %5)
%10 = tail call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %4
ret i32 %5
}