#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 */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int write(int, char *, int);
void wrBytes(int fd, char *p, int cnt) {
  int n;
  do
    if ((n = write(fd, p, cnt)) >= 0)
      p += n, cnt -= n;
    else if (errno != EINTR)
      exit(1);
  while (cnt);
}


x86 assembly (clang, -O0):
<wrBytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jl     116e <wrBytes+0x4e>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1197 <wrBytes+0x77>
mov    0x2e6b(%rip),%rax
mov    (%rax),%rax
mov    0x2e59(%rip),%rcx
cmp    (%rcx),%rax
je     1192 <wrBytes+0x72>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    1197 <wrBytes+0x77>
jmp    119c <wrBytes+0x7c>
cmpl   $0x0,-0x14(%rbp)
jne    1132 <wrBytes+0x12>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wrBytes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2eaa(%rip),%r15
mov    0x2e9b(%rip),%r12
jmp    114b <wrBytes+0x2b>
nop
mov    %eax,%ecx
add    %rcx,%r14
sub    %eax,%ebx
test   %ebx,%ebx
je     116e <wrBytes+0x4e>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    1140 <wrBytes+0x20>
mov    (%r15),%rax
cmp    (%r12),%rax
je     1147 <wrBytes+0x27>
mov    $0x1,%edi
call   1040 <exit@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define void @wrBytes(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %30, %3
%9 = load i32, i32* %4
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = call i32 @write(i32 %9, i8* %10, i32 %11)
store i32 %12, i32* %7
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %8
%15 = load i32, i32* %7
%16 = load i8*, i8** %5
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds i8, i8* %16, i64 %17
store i8* %18, i8** %5
%19 = load i32, i32* %7
%20 = load i32, i32* %6
%21 = sub nsw i32 %20, %19
store i32 %21, i32* %6
br label %29
22: ; preds = %8
%23 = load i64, i64* @errno
%24 = load i64, i64* @EINTR
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %22
br label %29
29: ; preds = %28, %14
br label %30
30: ; preds = %29
%31 = load i32, i32* %6
%32 = icmp ne i32 %31, 0
br i1 %32, label %8, label %33
33: ; preds = %30
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define void @wrBytes(i32 %0, i8* nocapture %1, i32 %2) {
br label %4
4: ; preds = %19, %3
%5 = phi i32 [ %2, %3 ], [ %20, %19 ]
%6 = phi i8* [ %1, %3 ], [ %21, %19 ]
%7 = tail call i32 @write(i32 %0, i8* %6, i32 %5)
%8 = icmp sgt i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = zext i32 %7 to i64
%11 = getelementptr inbounds i8, i8* %6, i64 %10
%12 = sub nsw i32 %5, %7
br label %19
13: ; preds = %4
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %9, %13
%20 = phi i32 [ %12, %9 ], [ %5, %13 ]
%21 = phi i8* [ %11, %9 ], [ %6, %13 ]
%22 = icmp eq i32 %20, 0
br i1 %22, label %23, label %4
23: ; preds = %19
ret void
}