#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 char wchar_t;

/* Variables and functions */
int /*<<< orphan*/ ft_putwchr_utf8(char const);
void ft_putnwstr_utf8(const wchar_t *s, size_t n) {
  size_t i;
  if (s) {
    i = 0;
    while (s[i] != '\0' && i < n) {
      ft_putwchr_utf8(s[i]);
      i++;
    }
  }
}


x86 assembly (clang, -O0):
<ft_putnwstr_utf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1192 <ft_putnwstr_utf8+0x82>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     115b <ft_putnwstr_utf8+0x4b>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
setb   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    116b <ft_putnwstr_utf8+0x5b>
jmp    118d <ft_putnwstr_utf8+0x7d>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <ft_putwchr_utf8@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1133 <ft_putnwstr_utf8+0x23>
jmp    1192 <ft_putnwstr_utf8+0x82>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putnwstr_utf8>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     114d <ft_putnwstr_utf8+0x3d>
mov    %rdi,%r15
mov    (%rdi),%al
test   %al,%al
je     114d <ft_putnwstr_utf8+0x3d>
mov    %rsi,%r14
test   %rsi,%rsi
je     114d <ft_putnwstr_utf8+0x3d>
mov    $0x1,%ebx
movsbl %al,%edi
call   1030 <ft_putwchr_utf8@plt>
movzbl (%r15,%rbx,1),%eax
test   %al,%al
je     114d <ft_putnwstr_utf8+0x3d>
lea    0x1(%rbx),%rcx
cmp    %r14,%rbx
mov    %rcx,%rbx
jb     1130 <ft_putnwstr_utf8+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @ft_putnwstr_utf8(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %19, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp ne i8 %5, 0
%7 = icmp ne i64 %1, 0
%8 = and i1 %6, %7
br i1 %8, label %9, label %19
9: ; preds = %4, %9
%10 = phi i8 [ %15, %9 ], [ %5, %4 ]
%11 = phi i64 [ %13, %9 ], [ 0, %4 ]
%12 = tail call i32 @ft_putwchr_utf8(i8 signext %10)
%13 = add nuw i64 %11, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
%17 = icmp ult i64 %13, %1
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %9, label %19
19: ; preds = %9, %4, %2
ret void
}