#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 ssize_t;
typedef int /*<<< orphan*/ c;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ err(int, char *);
scalar_t__ errno;
int /*<<< orphan*/ errx(int, char *, int);
int write(int, char *, int);
void write_byte(int fd, char c) {
  ssize_t n;
  do {
    char c = 0;
    n = write(fd, &c, sizeof(c));
  } while (n == -1 && errno == EINTR);
  if (n == -1)
    err(1, "write");
  if (n != 1)
    errx(1, "write returned %ld", n);
}


x86 assembly (clang, -O0):
<write_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
movb   $0x0,-0xd(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0xc(%rbp)
mov    %al,-0xe(%rbp)
jne    1182 <write_byte+0x52>
mov    0x2e71(%rip),%rax
mov    (%rax),%rax
mov    0x2e5f(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
test   $0x1,%al
jne    1141 <write_byte+0x11>
cmpl   $0xffffffff,-0xc(%rbp)
jne    11a8 <write_byte+0x78>
mov    $0x1,%edi
lea    0xe5d(%rip),%rsi
call   1050 <err@plt>
cmpl   $0x1,-0xc(%rbp)
je     11c6 <write_byte+0x96>
mov    -0xc(%rbp),%edx
mov    $0x1,%edi
lea    0xe45(%rip),%rsi
call   1040 <errx@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_byte>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
lea    0xf(%rsp),%r14
mov    0x2e96(%rip),%r15
mov    0x2e87(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x0,0xf(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1184 <write_byte+0x54>
mov    (%r12),%rax
cmp    %rax,(%r15)
je     1160 <write_byte+0x30>
cmp    $0xffffffff,%ebx
je     119b <write_byte+0x6b>
cmp    $0x1,%ebx
jne    11ac <write_byte+0x7c>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe5e(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
lea    0xe53(%rip),%rsi
mov    $0x1,%edi
mov    %ebx,%edx
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <errx@plt>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [6 x i8] c"write\00"
@.str.1 = [19 x i8] c"write returned %ld\00"
define void @write_byte(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i8
store i32 %0, i32* %3
store i8 %1, i8* %4
br label %7
7: ; preds = %17, %2
store i8 0, i8* %6
%8 = load i32, i32* %3
%9 = call i32 @write(i32 %8, i8* %6, i32 1)
store i32 %9, i32* %5
br label %10
10: ; preds = %7
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
br label %17
17: ; preds = %13, %10
%18 = phi i1 [ false, %10 ], [ %16, %13 ]
br i1 %18, label %7, label %19
19: ; preds = %17
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
%25 = load i32, i32* %5
%26 = icmp ne i32 %25, 1
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* %5
%29 = call i32 @errx(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %24
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str = [6 x i8] c"write\00"
@.str.1 = [19 x i8] c"write returned %ld\00"
define void @write_byte(i32 %0, i8 signext %1) {
%3 = alloca i8
br label %4
4: ; preds = %4, %2
store i8 0, i8* %3
%5 = call i32 @write(i32 %0, i8* %3, i32 1)
%6 = icmp eq i32 %5, -1
%7 = load i64, i64* @errno
%8 = load i64, i64* @EINTR
%9 = icmp eq i64 %7, %8
%10 = select i1 %6, i1 %9, i1 false
br i1 %10, label %4, label %11
11: ; preds = %4
br i1 %6, label %12, label %14
12: ; preds = %11
%13 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %16
14: ; preds = %11
%15 = icmp eq i32 %5, 1
br i1 %15, label %18, label %16
16: ; preds = %12, %14
%17 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %18
18: ; preds = %16, %14
ret void
}