#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 */
char *gui_chat_string_next_char(int /*<<< orphan*/ *, unsigned char *,
                                int /*<<< orphan*/);
int utf8_char_size_screen(char const *);
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, (unsigned char *)string, 0);
    if (string) {
      size_on_screen =
          (((unsigned char)string[0]) < 32) ? 1 : utf8_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    11e5 <gui_chat_strlen_screen+0xb5>
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
xor    %edx,%edx
call   1040 <gui_chat_string_next_char@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11e0 <gui_chat_strlen_screen+0xb0>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x20,%eax
jge    11ae <gui_chat_strlen_screen+0x7e>
mov    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ba <gui_chat_strlen_screen+0x8a>
mov    -0x8(%rbp),%rdi
call   1050 <utf8_char_size_screen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11d3 <gui_chat_strlen_screen+0xa3>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <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   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1190 <gui_chat_strlen_screen+0x60>
mov    %rdi,%rax
xor    %r14d,%r14d
jmp    1161 <gui_chat_strlen_screen+0x31>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14d
mov    %rbx,%rdi
call   1030 <utf8_next_char@plt>
test   %rax,%rax
je     1193 <gui_chat_strlen_screen+0x63>
cmpb   $0x0,(%rax)
je     1193 <gui_chat_strlen_screen+0x63>
xor    %edi,%edi
mov    %rax,%rsi
xor    %edx,%edx
call   1040 <gui_chat_string_next_char@plt>
test   %rax,%rax
je     1193 <gui_chat_strlen_screen+0x63>
mov    %rax,%rbx
cmpb   $0x1f,(%rax)
jbe    1150 <gui_chat_strlen_screen+0x20>
mov    %rbx,%rdi
call   1050 <utf8_char_size_screen@plt>
test   %eax,%eax
jle    1154 <gui_chat_strlen_screen+0x24>
add    %eax,%r14d
jmp    1154 <gui_chat_strlen_screen+0x24>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
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 = %42, %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 %43
16: ; preds = %14
%17 = load i8*, i8** %2
%18 = call i8* @gui_chat_string_next_char(i32* null, i8* %17, i32 0)
store i8* %18, i8** %2
%19 = load i8*, i8** %2
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %42
21: ; preds = %16
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = icmp slt i32 %25, 32
br i1 %26, label %27, label %28
27: ; preds = %21
br label %31
28: ; preds = %21
%29 = load i8*, i8** %2
%30 = call i32 @utf8_char_size_screen(i8* %29)
br label %31
31: ; preds = %28, %27
%32 = phi i32 [ 1, %27 ], [ %30, %28 ]
store i32 %32, i32* %4
%33 = load i32, i32* %4
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load i32, i32* %4
%37 = load i32, i32* %3
%38 = add nsw i32 %37, %36
store i32 %38, i32* %3
br label %39
39: ; preds = %35, %31
%40 = load i8*, i8** %2
%41 = call i8* @utf8_next_char(i8* %40)
store i8* %41, i8** %2
br label %42
42: ; preds = %39, %16
br label %5
43: ; preds = %14
%44 = load i32, i32* %3
ret i32 %44
}

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