#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 write(int, char *, size_t);
ssize_t writeFromb(int fd, char *buf, size_t count) {
  ssize_t res;
  if ((res = write(fd, buf, count)) < 1)
    while ((errno == EINTR) && (res < 1))
      res = write(fd, buf, count);
  return res;
}


x86 assembly (clang, -O0):
<writeFromb>:
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    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x1,%eax
jge    119a <writeFromb+0x8a>
jmp    1144 <writeFromb+0x34>
mov    0x2e95(%rip),%rax
mov    (%rax),%rcx
xor    %eax,%eax
mov    0x2e81(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x1d(%rbp)
jne    116d <writeFromb+0x5d>
cmpl   $0x1,-0x1c(%rbp)
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    117d <writeFromb+0x6d>
jmp    1195 <writeFromb+0x85>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
jmp    1144 <writeFromb+0x34>
jmp    119a <writeFromb+0x8a>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeFromb>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
call   1030 <write@plt>
test   %eax,%eax
jg     115a <writeFromb+0x4a>
mov    0x2eb0(%rip),%r15
mov    (%r15),%rcx
mov    0x2e9e(%rip),%r12
cmp    (%r12),%rcx
jne    115a <writeFromb+0x4a>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <write@plt>
test   %eax,%eax
jg     115a <writeFromb+0x4a>
mov    (%r12),%rcx
cmp    %rcx,(%r15)
je     1140 <writeFromb+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define i32 @writeFromb(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
%8 = load i32, i32* %4
%9 = load i8*, i8** %5
%10 = load i64, i64* %6
%11 = call i32 @write(i32 %8, i8* %9, i64 %10)
store i32 %11, i32* %7
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %29
13: ; preds = %3
br label %14
14: ; preds = %23, %13
%15 = load i64, i64* @errno
%16 = load i64, i64* @EINTR
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 1
br label %21
21: ; preds = %18, %14
%22 = phi i1 [ false, %14 ], [ %20, %18 ]
br i1 %22, label %23, label %28
23: ; preds = %21
%24 = load i32, i32* %4
%25 = load i8*, i8** %5
%26 = load i64, i64* %6
%27 = call i32 @write(i32 %24, i8* %25, i64 %26)
store i32 %27, i32* %7
br label %14
28: ; preds = %21
br label %29
29: ; preds = %28, %3
%30 = load i32, i32* %7
ret i32 %30
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @writeFromb(i32 %0, i8* nocapture %1, i64 %2) {
%4 = tail call i32 @write(i32 %0, i8* %1, i64 %2)
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %17
6: ; preds = %3
%7 = load i64, i64* @errno
%8 = load i64, i64* @EINTR
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %17
10: ; preds = %6, %10
%11 = tail call i32 @write(i32 %0, i8* %1, i64 %2)
%12 = load i64, i64* @errno
%13 = load i64, i64* @EINTR
%14 = icmp eq i64 %12, %13
%15 = icmp slt i32 %11, 1
%16 = and i1 %15, %14
br i1 %16, label %10, label %17
17: ; preds = %10, %6, %3
%18 = phi i32 [ %4, %3 ], [ %4, %6 ], [ %11, %10 ]
ret i32 %18
}