#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, unsigned char *, int);
int LZSSBufferWrite(int fd, unsigned char *Buffer, int *BufferCount,
                    unsigned char value) {
  Buffer[*BufferCount] = value;
  *BufferCount += 1;
  if (*BufferCount == 0x1000) {
    if (write(fd, Buffer, 0x1000) != 0x1000) {
      fprintf(stderr, "Error writing to output file: %s", strerror(errno));
      return 1;
    }
    *BufferCount = 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<LZSSBufferWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cl,%al
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x1000,(%rax)
jne    11d2 <LZSSBufferWrite+0xa2>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x1000,%edx
call   1030 <write@plt>
cmp    $0x1000,%eax
je     11c8 <LZSSBufferWrite+0x98>
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe49(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d9 <LZSSBufferWrite+0xa9>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LZSSBufferWrite>:
push   %rbp
push   %rbx
push   %rax
movslq (%rdx),%rax
mov    %cl,(%rsi,%rax,1)
mov    (%rdx),%eax
add    $0x1,%eax
mov    %eax,(%rdx)
xor    %ebp,%ebp
cmp    $0x1000,%eax
jne    1192 <LZSSBufferWrite+0x62>
mov    %rdx,%rbx
mov    $0x1000,%edx
call   1030 <write@plt>
cmp    $0x1000,%eax
jne    1165 <LZSSBufferWrite+0x35>
movl   $0x0,(%rbx)
jmp    1192 <LZSSBufferWrite+0x62>
mov    0x2e74(%rip),%rax
mov    (%rax),%ebx
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe7d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Error writing to output file: %s\00"
@errno = global i32 0
define i32 @LZSSBufferWrite(i32 %0, i8* %1, i32* %2, i8 zeroext %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i8 %3, i8* %9
%10 = load i8, i8* %9
%11 = load i8*, i8** %7
%12 = load i32*, i32** %8
%13 = load i32, i32* %12
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
store i8 %10, i8* %15
%16 = load i32*, i32** %8
%17 = load i32, i32* %16
%18 = add nsw i32 %17, 1
store i32 %18, i32* %16
%19 = load i32*, i32** %8
%20 = load i32, i32* %19
%21 = icmp eq i32 %20, 4096
br i1 %21, label %22, label %34
22: ; preds = %4
%23 = load i32, i32* %6
%24 = load i8*, i8** %7
%25 = call i32 @write(i32 %23, i8* %24, i32 4096)
%26 = icmp ne i32 %25, 4096
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %30)
store i32 1, i32* %5
br label %35
32: ; preds = %22
%33 = load i32*, i32** %8
store i32 0, i32* %33
br label %34
34: ; preds = %32, %4
store i32 0, i32* %5
br label %35
35: ; preds = %34, %27
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Error writing to output file: %s\00"
@errno = global i32 0
define i32 @LZSSBufferWrite(i32 %0, i8* nocapture %1, i32* nocapture %2, i8 zeroext %3) {
%5 = load i32, i32* %2
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %1, i64 %6
store i8 %3, i8* %7
%8 = load i32, i32* %2
%9 = add nsw i32 %8, 1
store i32 %9, i32* %2
%10 = icmp eq i32 %9, 4096
br i1 %10, label %11, label %20
11: ; preds = %4
%12 = tail call i32 @write(i32 %0, i8* %1, i32 4096)
%13 = icmp eq i32 %12, 4096
br i1 %13, label %19, label %14
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %20
19: ; preds = %11
store i32 0, i32* %2
br label %20
20: ; preds = %4, %19, %14
%21 = phi i32 [ 1, %14 ], [ 0, %19 ], [ 0, %4 ]
ret i32 %21
}