#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;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ terminal_error(char *);
int write(int, void const **, size_t);
ssize_t Write(int fd, const void *buf, size_t count) {
  ssize_t retval;
retry:
  retval = write(fd, &buf, count);
  if (retval == -1) {
    if (errno == EINTR)
      goto retry;
    terminal_error("write");
  }
  return retval;
}


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    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rdx
lea    -0x10(%rbp),%rsi
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    117b <Write+0x5b>
mov    0x2e89(%rip),%rax
mov    (%rax),%rax
mov    0x2e77(%rip),%rcx
cmp    (%rcx),%rax
jne    116f <Write+0x4f>
jmp    1133 <Write+0x13>
lea    0xe8a(%rip),%rdi
call   1040 <terminal_error@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %edi,%ebp
mov    %rsi,(%rsp)
mov    %rsp,%r14
mov    0x2ea2(%rip),%r12
mov    0x2e93(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <write@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    117a <Write+0x5a>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1150 <Write+0x30>
lea    0xe8b(%rip),%rdi
call   1040 <terminal_error@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [6 x i8] c"write\00"
define i32 @Write(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
br label %8
8: ; preds = %18, %3
%9 = load i32, i32* %4
%10 = load i64, i64* %6
%11 = call i32 @write(i32 %9, i8** %5, i64 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %21
14: ; preds = %8
%15 = load i64, i64* @errno
%16 = load i64, i64* @EINTR
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14
br label %8
19: ; preds = %14
%20 = call i32 @terminal_error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %8
%22 = load i32, i32* %7
ret i32 %22
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str = [6 x i8] c"write\00"
define i32 @Write(i32 %0, i8* %1, i64 %2) {
%4 = alloca i8*
store i8* %1, i8** %4
br label %5
5: ; preds = %8, %3
%6 = call i32 @write(i32 %0, i8** %4, i64 %2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %14
8: ; preds = %5
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
br i1 %11, label %5, label %12
12: ; preds = %8
%13 = tail call i32 @terminal_error(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %5, %12
ret i32 %6
}