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

/* Variables and functions */
int /*<<< orphan*/ _wputc(int /*<<< orphan*/ *, char const, int);
void _wputstr(WINDOW *win, const char *str, int wrap, int n) {
  for (; *str && n--; str++) {
    _wputc(win, *str, wrap);
  }
}


x86 assembly (clang, -O0):
<_wputstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     114f <_wputstr+0x3f>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    115f <_wputstr+0x4f>
jmp    1185 <_wputstr+0x75>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x14(%rbp),%edx
movsbl %al,%esi
call   1030 <_wputc@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1126 <_wputstr+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_wputstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    (%rsi),%al
test   %al,%al
je     1162 <_wputstr+0x52>
test   %ecx,%ecx
je     1162 <_wputstr+0x52>
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%r15
mov    %ecx,%ebp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %al,%esi
mov    %r15,%rdi
mov    %r14d,%edx
call   1030 <_wputc@plt>
movzbl (%r12,%rbx,1),%eax
test   %al,%al
je     1162 <_wputstr+0x52>
lea    0x1(%rbx),%rcx
cmp    %ebx,%ebp
mov    %rcx,%rbx
jne    1140 <_wputstr+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @_wputstr(i32* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
br label %9
9: ; preds = %26, %4
%10 = load i8*, i8** %6
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* %8
%16 = add nsw i32 %15, -1
store i32 %16, i32* %8
%17 = icmp ne i32 %15, 0
br label %18
18: ; preds = %14, %9
%19 = phi i1 [ false, %9 ], [ %17, %14 ]
br i1 %19, label %20, label %29
20: ; preds = %18
%21 = load i32*, i32** %5
%22 = load i8*, i8** %6
%23 = load i8, i8* %22
%24 = load i32, i32* %7
%25 = call i32 @_wputc(i32* %21, i8 signext %23, i32 %24)
br label %26
26: ; preds = %20
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %6
br label %9
29: ; preds = %18
ret void
}

LLVM IR (-O2):
define void @_wputstr(i32* %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 0
%7 = icmp eq i32 %3, 0
%8 = or i1 %6, %7
br i1 %8, label %20, label %9
9: ; preds = %4, %9
%10 = phi i8 [ %16, %9 ], [ %5, %4 ]
%11 = phi i32 [ %13, %9 ], [ %3, %4 ]
%12 = phi i8* [ %15, %9 ], [ %1, %4 ]
%13 = add nsw i32 %11, -1
%14 = tail call i32 @_wputc(i32* %0, i8 signext %10, i32 %2)
%15 = getelementptr inbounds i8, i8* %12, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
%18 = icmp eq i32 %13, 0
%19 = select i1 %17, i1 true, i1 %18
br i1 %19, label %20, label %9
20: ; preds = %9, %4
ret void
}