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

/* Variables and functions */
int ft_wctomb(char *, int /*<<< orphan*/);
size_t ft_wcslen(const wchar_t *wcs) {
  size_t converted_char;
  int current_char;
  char temp[4];
  converted_char = 0;
  while (*wcs) {
    if ((current_char = ft_wctomb(temp, *wcs++)) == -1)
      return ((size_t)-1);
    converted_char += current_char;
  }
  return (converted_char);
}


x86 assembly (clang, -O0):
<ft_wcslen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1179 <ft_wcslen+0x69>
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
mov    %eax,%esi
call   1030 <ft_wctomb@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1168 <ft_wcslen+0x58>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1181 <ft_wcslen+0x71>
movslq -0x1c(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1124 <ft_wcslen+0x14>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_wcslen>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    (%rdi),%rsi
test   %rsi,%rsi
je     1150 <ft_wcslen+0x40>
mov    %rdi,%rbx
add    $0x8,%rbx
xor    %r14d,%r14d
lea    0xc(%rsp),%r15
mov    %r15,%rdi
call   1030 <ft_wctomb@plt>
cmp    $0xffffffff,%eax
je     1155 <ft_wcslen+0x45>
cltq
add    %rax,%r14
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1130 <ft_wcslen+0x20>
jmp    115c <ft_wcslen+0x4c>
xor    %r14d,%r14d
jmp    115c <ft_wcslen+0x4c>
mov    $0xffffffffffffffff,%r14
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @ft_wcslen(i64* nocapture %0) {
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = load i64, i64* %0
%5 = icmp eq i64 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %1, %13
%7 = phi i64 [ %17, %13 ], [ %4, %1 ]
%8 = phi i64 [ %16, %13 ], [ 0, %1 ]
%9 = phi i64* [ %14, %13 ], [ %0, %1 ]
%10 = trunc i64 %7 to i32
%11 = call i32 @ft_wctomb(i8* %3, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %19, label %13
13: ; preds = %6
%14 = getelementptr inbounds i64, i64* %9, i64 1
%15 = sext i32 %11 to i64
%16 = add i64 %8, %15
%17 = load i64, i64* %14
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %6
19: ; preds = %6, %13, %1
%20 = phi i64 [ 0, %1 ], [ %16, %13 ], [ -1, %6 ]
ret i64 %20
}