#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*/ close_tty();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printconsole(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int write(int, char *, int);
void writebyte(int fd, char byte) {
  int ret = write(fd, &byte, 1);
  if (ret < 0) {
    printconsole("ERROR: Failed to write to fd=%d: %s\n", fd, strerror(errno));
    close_tty();
    exit(14);
  }
}


x86 assembly (clang, -O0):
<writebyte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11b5 <writebyte+0x65>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xe61(%rip),%rdi
call   1040 <printconsole@plt>
mov    $0x0,%al
call   1050 <close_tty@plt>
mov    $0xe,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writebyte>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %sil,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
test   %eax,%eax
js     1175 <writebyte+0x25>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe76(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printconsole@plt>
xor    %eax,%eax
call   1050 <close_tty@plt>
mov    $0xe,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"ERROR: Failed to write to fd=%d: %s\0A\00"
@errno = global i32 0
define void @writebyte(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
store i32 %0, i32* %3
store i8 %1, i8* %4
%6 = load i32, i32* %3
%7 = call i32 @write(i32 %6, i8* %4, i32 1)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* %3
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = call i32 @printconsole(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %13)
%15 = call i32 (...) @close_tty()
%16 = call i32 @exit(i32 14)
unreachable
17: ; preds = %2
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"ERROR: Failed to write to fd=%d: %s\0A\00"
@errno = global i32 0
define void @writebyte(i32 %0, i8 signext %1) {
%3 = alloca i8
store i8 %1, i8* %3
%4 = call i32 @write(i32 %0, i8* %3, i32 1)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 @printconsole(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %8)
%10 = tail call i32 (...) @close_tty()
%11 = tail call i32 @exit(i32 14)
unreachable
12: ; preds = %2
ret void
}