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

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ err(int, char *);
scalar_t__ errno;
int write(int, char *, int);
void write_pipe(int pipe[2]) {
  char c = 0;
  int ret;
  do {
    ret = write(pipe[1], &c, sizeof(c));
  } while (ret == -1 && errno == EINTR);
  if (ret == -1)
    err(1, "write");
}


x86 assembly (clang, -O0):
<write_pipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jne    1171 <write_pipe+0x51>
mov    0x2e82(%rip),%rax
mov    (%rax),%rax
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1130 <write_pipe+0x10>
cmpl   $0xffffffff,-0x10(%rbp)
jne    1197 <write_pipe+0x77>
mov    $0x1,%edi
lea    0xe6e(%rip),%rsi
call   1040 <err@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_pipe>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
movb   $0x0,0x7(%rsp)
lea    0x7(%rsp),%r14
mov    0x2ea4(%rip),%r15
mov    0x2e95(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x4(%rbx),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    116e <write_pipe+0x4e>
mov    (%r12),%rcx
cmp    %rcx,(%r15)
je     1150 <write_pipe+0x30>
cmp    $0xffffffff,%eax
je     117f <write_pipe+0x5f>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe7a(%rip),%rsi
mov    $0x1,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <err@plt>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [6 x i8] c"write\00"
define void @write_pipe(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32
store i32* %0, i32** %2
store i8 0, i8* %3
br label %5
5: ; preds = %17, %1
%6 = load i32*, i32** %2
%7 = getelementptr inbounds i32, i32* %6, i64 1
%8 = load i32, i32* %7
%9 = call i32 @write(i32 %8, i8* %3, i32 1)
store i32 %9, i32* %4
br label %10
10: ; preds = %5
%11 = load i32, i32* %4
%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 %5, label %19
19: ; preds = %17
%20 = load i32, i32* %4
%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
ret void
}

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