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

/* Variables and functions */
int gui_chat_char_size_screen(char const *);
char *gui_chat_string_next_char(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                unsigned char *, int /*<<< orphan*/,
                                int /*<<< orphan*/, int /*<<< orphan*/);
char *utf8_next_char(char const *);
int gui_chat_strlen_screen(const char *string) {
  int length, size_on_screen;
  length = 0;
  while (string && string[0]) {
    string =
        gui_chat_string_next_char(NULL, NULL, (unsigned char *)string, 0, 0, 0);
    if (string) {
      size_on_screen = gui_chat_char_size_screen(string);
      if (size_on_screen > 0)
        length += size_on_screen;
      string = utf8_next_char(string);
    }
  }
  return length;
}


x86 assembly (clang, -O0):
<gui_chat_strlen_screen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x11(%rbp)
je     1163 <gui_chat_strlen_screen+0x33>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1173 <gui_chat_strlen_screen+0x43>
jmp    11cc <gui_chat_strlen_screen+0x9c>
mov    -0x8(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%esi
xor    %r9d,%r9d
mov    %rsi,%rdi
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1050 <gui_chat_string_next_char@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11c7 <gui_chat_strlen_screen+0x97>
mov    -0x8(%rbp),%rdi
call   1030 <gui_chat_char_size_screen@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11ba <gui_chat_strlen_screen+0x8a>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <utf8_next_char@plt>
mov    %rax,-0x8(%rbp)
jmp    1143 <gui_chat_strlen_screen+0x13>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gui_chat_strlen_screen>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     1190 <gui_chat_strlen_screen+0x60>
mov    %rdi,%rax
xor    %r14d,%r14d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,(%rax)
je     1192 <gui_chat_strlen_screen+0x62>
xor    %edi,%edi
xor    %esi,%esi
mov    %rax,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1050 <gui_chat_string_next_char@plt>
test   %rax,%rax
je     1192 <gui_chat_strlen_screen+0x62>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <gui_chat_char_size_screen@plt>
test   %eax,%eax
cmovs  %r14d,%eax
add    %eax,%ebp
mov    %rbx,%rdi
call   1040 <utf8_next_char@plt>
test   %rax,%rax
jne    1150 <gui_chat_strlen_screen+0x20>
jmp    1192 <gui_chat_strlen_screen+0x62>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @gui_chat_strlen_screen(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %18, label %3
3: ; preds = %1, %11
%4 = phi i8* [ %16, %11 ], [ %0, %1 ]
%5 = phi i32 [ %15, %11 ], [ 0, %1 ]
%6 = load i8, i8* %4
%7 = icmp eq i8 %6, 0
br i1 %7, label %18, label %8
8: ; preds = %3
%9 = tail call i8* @gui_chat_string_next_char(i32* null, i32* null, i8* %4, i32 0, i32 0, i32 0)
%10 = icmp eq i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %8
%12 = tail call i32 @gui_chat_char_size_screen(i8* %9)
%13 = icmp sgt i32 %12, 0
%14 = select i1 %13, i32 %12, i32 0
%15 = add nuw nsw i32 %14, %5
%16 = tail call i8* @utf8_next_char(i8* %9)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %3
18: ; preds = %8, %3, %11, %1
%19 = phi i32 [ 0, %1 ], [ %5, %8 ], [ %15, %11 ], [ %5, %3 ]
ret i32 %19
}