#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;
int /*<<< orphan*/ STDERR_FILENO;
scalar_t__ errno;
size_t strlen(char const *);
int write(int /*<<< orphan*/, char const *, size_t);
void out(const char *buf) {
  size_t bytes_to_write = strlen(buf);
  while (bytes_to_write > 0) {
    ssize_t written = write(STDERR_FILENO, buf, bytes_to_write);
    if (written == -1) {
      if (errno == EINTR)
        continue;
      return;
    }
    buf += written;
    bytes_to_write -= written;
  }
}


x86 assembly (clang, -O0):
<out>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jbe    11b0 <out+0x90>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    118b <out+0x6b>
mov    0x2e72(%rip),%rax
mov    (%rax),%rax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%rax
jne    1186 <out+0x66>
jmp    1139 <out+0x19>
jmp    11b0 <out+0x90>
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
movslq -0x14(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1139 <out+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<out>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
test   %rax,%rax
je     117a <out+0x5a>
mov    %rax,%rbx
mov    0x2e98(%rip),%r15
mov    0x2e99(%rip),%r12
mov    0x2e82(%rip),%r13
jmp    115d <out+0x3d>
cltq
add    %rax,%r14
sub    %rax,%rbx
test   %rbx,%rbx
je     117a <out+0x5a>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1150 <out+0x30>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1158 <out+0x38>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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