#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int fputs2(char *s, FILE *iop) {
  int c;
  while (c = *s++)
    putc(c, iop);
  return ferror(iop) ? EOF : 0;
}


x86 assembly (clang, -O0):
<fputs2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     115f <fputs2+0x3f>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <putc@plt>
jmp    1130 <fputs2+0x10>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1183 <fputs2+0x63>
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    118d <fputs2+0x6d>
xor    %eax,%eax
mov    %eax,-0x18(%rbp)
jmp    118d <fputs2+0x6d>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fputs2>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    (%rdi),%al
test   %al,%al
je     1156 <fputs2+0x36>
mov    %rdi,%rbx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %al,%edi
mov    %r14,%rsi
call   1040 <putc@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1140 <fputs2+0x20>
mov    %r14,%rdi
call   1030 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1171 <fputs2+0x51>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @fputs2(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
br label %6
6: ; preds = %12, %2
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i32 1
store i8* %8, i8** %3
%9 = load i8, i8* %7
%10 = sext i8 %9 to i32
store i32 %10, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = load i32, i32* %5
%14 = load i32*, i32** %4
%15 = call i32 @putc(i32 %13, i32* %14)
br label %6
16: ; preds = %6
%17 = load i32*, i32** %4
%18 = call i64 @ferror(i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i32, i32* @EOF
br label %23
22: ; preds = %16
br label %23
23: ; preds = %22, %20
%24 = phi i32 [ %21, %20 ], [ 0, %22 ]
ret i32 %24
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @fputs2(i8* nocapture %0, i32* nocapture %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %13, label %5
5: ; preds = %2, %5
%6 = phi i8 [ %11, %5 ], [ %3, %2 ]
%7 = phi i8* [ %9, %5 ], [ %0, %2 ]
%8 = sext i8 %6 to i32
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = tail call i32 @putc(i32 %8, i32* %1)
%11 = load i8, i8* %9
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %5
13: ; preds = %5, %2
%14 = tail call i64 @ferror(i32* %1)
%15 = icmp eq i64 %14, 0
%16 = load i32, i32* @EOF
%17 = select i1 %15, i32 0, i32 %16
ret i32 %17
}