#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);
scalar_t__ ft_wchrsize_utf8(char const);
void ft_putnbwstr_utf8(const wchar_t *s, size_t byte_nbr) {
  size_t i;
  if (s) {
    i = 0;
    while (*s != '\0' && i < byte_nbr) {
      i += ft_wchrsize_utf8(*s);
      if (i <= byte_nbr)
        ft_putwchr_utf8(*s);
      s++;
    }
  }
}


x86 assembly (clang, -O0):
<ft_putnbwstr_utf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ba <ft_putnbwstr_utf8+0x9a>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1166 <ft_putnbwstr_utf8+0x46>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
setb   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1176 <ft_putnbwstr_utf8+0x56>
jmp    11b5 <ft_putnbwstr_utf8+0x95>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <ft_wchrsize_utf8@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     11a4 <ft_putnbwstr_utf8+0x84>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <ft_putwchr_utf8@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1143 <ft_putnbwstr_utf8+0x23>
jmp    11ba <ft_putnbwstr_utf8+0x9a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putnbwstr_utf8>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1181 <ft_putnbwstr_utf8+0x61>
mov    %rdi,%r15
mov    (%rdi),%al
test   %al,%al
je     1181 <ft_putnbwstr_utf8+0x61>
mov    %rsi,%r14
test   %rsi,%rsi
je     1181 <ft_putnbwstr_utf8+0x61>
add    $0x1,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%r12
movsbl %al,%edi
call   1040 <ft_wchrsize_utf8@plt>
mov    %rax,%rbx
add    %r12,%rbx
cmp    %r14,%rbx
ja     1170 <ft_putnbwstr_utf8+0x50>
movsbl -0x1(%r15),%edi
call   1030 <ft_putwchr_utf8@plt>
movzbl (%r15),%eax
test   %al,%al
je     1181 <ft_putnbwstr_utf8+0x61>
add    $0x1,%r15
cmp    %r14,%rbx
jb     1150 <ft_putnbwstr_utf8+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @ft_putnbwstr_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 %37
8: ; preds = %2
store i64 0, i64* %5
br label %9
9: ; preds = %33, %8
%10 = load i8*, i8** %3
%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 i64, i64* %5
%16 = load i64, i64* %4
%17 = icmp ult i64 %15, %16
br label %18
18: ; preds = %14, %9
%19 = phi i1 [ false, %9 ], [ %17, %14 ]
br i1 %19, label %20, label %36
20: ; preds = %18
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = call i64 @ft_wchrsize_utf8(i8 signext %22)
%24 = load i64, i64* %5
%25 = add i64 %24, %23
store i64 %25, i64* %5
%26 = load i64, i64* %5
%27 = load i64, i64* %4
%28 = icmp ule i64 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %20
%30 = load i8*, i8** %3
%31 = load i8, i8* %30
%32 = call i32 @ft_putwchr_utf8(i8 signext %31)
br label %33
33: ; preds = %29, %20
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %3
br label %9
36: ; preds = %18
br label %37
37: ; preds = %36, %2
ret void
}

LLVM IR (-O2):
define void @ft_putnbwstr_utf8(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %25, 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 %25
9: ; preds = %4, %19
%10 = phi i8 [ %21, %19 ], [ %5, %4 ]
%11 = phi i64 [ %14, %19 ], [ 0, %4 ]
%12 = phi i8* [ %20, %19 ], [ %0, %4 ]
%13 = tail call i64 @ft_wchrsize_utf8(i8 signext %10)
%14 = add i64 %13, %11
%15 = icmp ugt i64 %14, %1
br i1 %15, label %19, label %16
16: ; preds = %9
%17 = load i8, i8* %12
%18 = tail call i32 @ft_putwchr_utf8(i8 signext %17)
br label %19
19: ; preds = %16, %9
%20 = getelementptr inbounds i8, i8* %12, i64 1
%21 = load i8, i8* %20
%22 = icmp ne i8 %21, 0
%23 = icmp ult i64 %14, %1
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %9, label %25
25: ; preds = %19, %4, %2
ret void
}