#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__ EOF;
scalar_t__ carefulputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
void wr_fputs(char *s) {
  char c;
  while (*s) {
    c = *s++;
    if (c == '\n')
      if (carefulputc('\r', stdout) == EOF)
        goto err;
    ;
    if (carefulputc(c, stdout) == EOF)
      goto err;
    ;
  }
  return;
err:
  fprintf(stderr, "write: %s\n", strerror(errno));
  exit(1);
}


x86 assembly (clang, -O0):
<wr_fputs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d5 <wr_fputs+0x95>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    11a7 <wr_fputs+0x67>
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    $0xd,%edi
call   1030 <carefulputc@plt>
mov    0x2e54(%rip),%rcx
cmp    (%rcx),%rax
jne    11a2 <wr_fputs+0x62>
jmp    11db <wr_fputs+0x9b>
jmp    11a7 <wr_fputs+0x67>
mov    -0x9(%rbp),%al
mov    0x2e17(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1030 <carefulputc@plt>
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%rax
jne    11d0 <wr_fputs+0x90>
jmp    11db <wr_fputs+0x9b>
jmp    114c <wr_fputs+0xc>
add    $0x10,%rsp
pop    %rbp
ret
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xdfe(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<wr_fputs>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
mov    0x2e76(%rip),%r14
mov    0x2e8f(%rip),%r15
jmp    1174 <wr_fputs+0x34>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
mov    (%r14),%esi
movsbl %bl,%edi
call   1030 <carefulputc@plt>
cmp    (%r15),%rax
je     1194 <wr_fputs+0x54>
movzbl (%r12),%ebx
test   %bl,%bl
je     11c6 <wr_fputs+0x86>
cmp    $0xa,%bl
jne    1160 <wr_fputs+0x20>
mov    (%r14),%esi
mov    $0xd,%edi
call   1030 <carefulputc@plt>
cmp    (%r15),%rax
jne    1160 <wr_fputs+0x20>
mov    0x2e3d(%rip),%rax
mov    (%rax),%ebx
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe4e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdout = global i32 0
@EOF = global i64 0
@stderr = global i32 0
@.str = [11 x i8] c"write: %s\0A\00"
@errno = global i32 0
define void @wr_fputs(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
store i8* %0, i8** %2
br label %4
4: ; preds = %29, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %30
8: ; preds = %4
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %2
%11 = load i8, i8* %9
store i8 %11, i8* %3
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 10
br i1 %14, label %15, label %22
15: ; preds = %8
%16 = load i32, i32* @stdout
%17 = call i64 @carefulputc(i8 signext 13, i32 %16)
%18 = load i64, i64* @EOF
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %15
br label %31
21: ; preds = %15
br label %22
22: ; preds = %21, %8
%23 = load i8, i8* %3
%24 = load i32, i32* @stdout
%25 = call i64 @carefulputc(i8 signext %23, i32 %24)
%26 = load i64, i64* @EOF
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %22
br label %31
29: ; preds = %22
br label %4
30: ; preds = %4
ret void
31: ; preds = %28, %20
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@stdout = global i32 0
@EOF = global i64 0
@stderr = global i32 0
@.str = [11 x i8] c"write: %s\0A\00"
@errno = global i32 0
define void @wr_fputs(i8* nocapture %0) {
br label %2
2: ; preds = %14, %1
%3 = phi i8* [ %0, %1 ], [ %7, %14 ]
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %3, i64 1
%8 = icmp eq i8 %4, 10
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = load i32, i32* @stdout
%11 = tail call i64 @carefulputc(i8 signext 13, i32 %10)
%12 = load i64, i64* @EOF
%13 = icmp eq i64 %11, %12
br i1 %13, label %20, label %14
14: ; preds = %9, %6
%15 = load i32, i32* @stdout
%16 = tail call i64 @carefulputc(i8 signext %4, i32 %15)
%17 = load i64, i64* @EOF
%18 = icmp eq i64 %16, %17
br i1 %18, label %20, label %2
19: ; preds = %2
ret void
20: ; preds = %14, %9
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = tail call i8* @strerror(i32 %22)
%24 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = tail call i32 @exit(i32 1)
unreachable
}