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

/* Variables and functions */
int EINTR;
int /*<<< orphan*/ STDOUT_FILENO;
int errno;
scalar_t__ write(int /*<<< orphan*/, char const *, size_t);
void wrout(const char *p) {
  const char *q;
  int saved_errno;
  if (!p)
    return;
  q = p;
  while (*q)
    q++;
  if (q == p)
    return;
  saved_errno = errno;
  while (p < q) {
    ssize_t n = write(STDOUT_FILENO, p, (size_t)(q - p));
    if (n > 0)
      p += n;
    else if (n != (ssize_t)-1 || errno != EINTR)
      break;
  }
  errno = saved_errno;
}


x86 assembly (clang, -O0):
<wrout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    112c <wrout+0x1c>
jmp    11fa <wrout+0xea>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1152 <wrout+0x42>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <wrout+0x24>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    1165 <wrout+0x55>
jmp    11fa <wrout+0xea>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11ee <wrout+0xde>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rax
sub    %rax,%rdx
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jle    11bc <wrout+0xac>
mov    -0x20(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e9 <wrout+0xd9>
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    11df <wrout+0xcf>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    0x2df9(%rip),%rcx
cmp    (%rcx),%eax
je     11e4 <wrout+0xd4>
jmp    11ee <wrout+0xde>
jmp    11e9 <wrout+0xd9>
jmp    1171 <wrout+0x61>
mov    -0x14(%rbp),%ecx
mov    0x2de0(%rip),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wrout>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a0 <wrout+0x90>
mov    %rdi,%rbx
mov    $0x1,%eax
xor    %ecx,%ecx
xchg   %ax,%ax
add    $0xffffffffffffffff,%rax
cmpb   $0x0,(%rbx,%rcx,1)
lea    0x1(%rcx),%rcx
jne    1130 <wrout+0x20>
test   %rax,%rax
je     11a0 <wrout+0x90>
mov    %rbx,%r14
sub    %rax,%r14
mov    0x2e88(%rip),%r15
mov    (%r15),%r12d
cmp    %rbx,%r14
jbe    119d <wrout+0x8d>
mov    0x2e91(%rip),%rbp
mov    0x2e6a(%rip),%r13
jmp    1178 <wrout+0x68>
nopl   0x0(%rax,%rax,1)
add    %rax,%rbx
cmp    %r14,%rbx
jae    119d <wrout+0x8d>
mov    0x0(%rbp),%edi
mov    %r14,%rdx
sub    %rbx,%rdx
mov    %rbx,%rsi
call   1030 <write@plt>
test   %rax,%rax
jg     1170 <wrout+0x60>
cmp    $0xffffffffffffffff,%rax
jne    119d <wrout+0x8d>
mov    (%r15),%eax
cmp    0x0(%r13),%eax
je     1173 <wrout+0x63>
mov    %r12d,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@STDOUT_FILENO = global i32 0
@EINTR = global i32 0
define void @wrout(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
br label %56
9: ; preds = %1
%10 = load i8*, i8** %2
store i8* %10, i8** %3
br label %11
11: ; preds = %15, %9
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %3
br label %11
18: ; preds = %11
%19 = load i8*, i8** %3
%20 = load i8*, i8** %2
%21 = icmp eq i8* %19, %20
br i1 %21, label %22, label %23
22: ; preds = %18
br label %56
23: ; preds = %18
%24 = load i32, i32* @errno
store i32 %24, i32* %4
br label %25
25: ; preds = %53, %23
%26 = load i8*, i8** %2
%27 = load i8*, i8** %3
%28 = icmp ult i8* %26, %27
br i1 %28, label %29, label %54
29: ; preds = %25
%30 = load i32, i32* @STDOUT_FILENO
%31 = load i8*, i8** %2
%32 = load i8*, i8** %3
%33 = load i8*, i8** %2
%34 = ptrtoint i8* %32 to i64
%35 = ptrtoint i8* %33 to i64
%36 = sub i64 %34, %35
%37 = call i64 @write(i32 %30, i8* %31, i64 %36)
store i64 %37, i64* %5
%38 = load i64, i64* %5
%39 = icmp sgt i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %29
%41 = load i64, i64* %5
%42 = load i8*, i8** %2
%43 = getelementptr inbounds i8, i8* %42, i64 %41
store i8* %43, i8** %2
br label %53
44: ; preds = %29
%45 = load i64, i64* %5
%46 = icmp ne i64 %45, -1
br i1 %46, label %51, label %47
47: ; preds = %44
%48 = load i32, i32* @errno
%49 = load i32, i32* @EINTR
%50 = icmp ne i32 %48, %49
br i1 %50, label %51, label %52
51: ; preds = %47, %44
br label %54
52: ; preds = %47
br label %53
53: ; preds = %52, %40
br label %25
54: ; preds = %51, %25
%55 = load i32, i32* %4
store i32 %55, i32* @errno
br label %56
56: ; preds = %54, %22, %8
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@STDOUT_FILENO = global i32 0
@EINTR = global i32 0
define void @wrout(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %34, label %3
3: ; preds = %1, %3
%4 = phi i8* [ %7, %3 ], [ %0, %1 ]
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
%7 = getelementptr inbounds i8, i8* %4, i64 1
br i1 %6, label %8, label %3
8: ; preds = %3
%9 = icmp eq i8* %4, %0
br i1 %9, label %34, label %10
10: ; preds = %8
%11 = load i32, i32* @errno
%12 = icmp ugt i8* %4, %0
br i1 %12, label %13, label %33
13: ; preds = %10
%14 = ptrtoint i8* %4 to i64
br label %15
15: ; preds = %13, %30
%16 = phi i8* [ %0, %13 ], [ %31, %30 ]
%17 = load i32, i32* @STDOUT_FILENO
%18 = ptrtoint i8* %16 to i64
%19 = sub i64 %14, %18
%20 = tail call i64 @write(i32 %17, i8* %16, i64 %19)
%21 = icmp sgt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = getelementptr inbounds i8, i8* %16, i64 %20
br label %30
24: ; preds = %15
%25 = icmp eq i64 %20, -1
br i1 %25, label %26, label %33
26: ; preds = %24
%27 = load i32, i32* @errno
%28 = load i32, i32* @EINTR
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %22, %26
%31 = phi i8* [ %23, %22 ], [ %16, %26 ]
%32 = icmp ult i8* %31, %4
br i1 %32, label %15, label %33
33: ; preds = %30, %26, %24, %10
store i32 %11, i32* @errno
br label %34
34: ; preds = %8, %1, %33
ret void
}