#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 int /*<<< orphan*/ wchar_t;

/* Variables and functions */
int /*<<< orphan*/ free(int /*<<< orphan*/ *const);
int /*<<< orphan*/ *to_wide(char const *);
size_t utf8_nstrlen(char const *);
size_t vifm_wcswidth(int /*<<< orphan*/ *const, size_t);
size_t get_width_on_screen(const char str[]) {
  size_t length = (size_t)-1;
  wchar_t *const wide = to_wide(str);
  if (wide != NULL) {
    length = vifm_wcswidth(wide, (size_t)-1);
    free(wide);
  }
  if (length == (size_t)-1) {
    length = utf8_nstrlen(str);
  }
  return length;
}


x86 assembly (clang, -O0):
<get_width_on_screen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0xffffffffffffffff,-0x10(%rbp)
ff
mov    -0x8(%rbp),%rdi
call   1050 <to_wide@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1189 <get_width_on_screen+0x49>
mov    -0x18(%rbp),%rdi
mov    $0xffffffffffffffff,%rsi
call   1030 <vifm_wcswidth@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
cmpq   $0xffffffffffffffff,-0x10(%rbp)
jne    11a1 <get_width_on_screen+0x61>
mov    -0x8(%rbp),%rdi
call   1060 <utf8_nstrlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_width_on_screen>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1050 <to_wide@plt>
test   %rax,%rax
je     117e <get_width_on_screen+0x3e>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xffffffffffffffff,%rsi
call   1030 <vifm_wcswidth@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <free@plt>
cmp    $0xffffffffffffffff,%r15
je     117e <get_width_on_screen+0x3e>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <utf8_nstrlen@plt>

LLVM IR (-O0):
define i64 @get_width_on_screen(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32*
store i8* %0, i8** %2
store i64 -1, i64* %3
%5 = load i8*, i8** %2
%6 = call i32* @to_wide(i8* %5)
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load i32*, i32** %4
%11 = call i64 @vifm_wcswidth(i32* %10, i64 -1)
store i64 %11, i64* %3
%12 = load i32*, i32** %4
%13 = call i32 @free(i32* %12)
br label %14
14: ; preds = %9, %1
%15 = load i64, i64* %3
%16 = icmp eq i64 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i8*, i8** %2
%19 = call i64 @utf8_nstrlen(i8* %18)
store i64 %19, i64* %3
br label %20
20: ; preds = %17, %14
%21 = load i64, i64* %3
ret i64 %21
}

LLVM IR (-O2):
define i64 @get_width_on_screen(i8* %0) {
%2 = tail call i32* @to_wide(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = tail call i64 @vifm_wcswidth(i32* %2, i64 -1)
%6 = tail call i32 @free(i32* %2)
%7 = icmp eq i64 %5, -1
br i1 %7, label %8, label %10
8: ; preds = %1, %4
%9 = tail call i64 @utf8_nstrlen(i8* %0)
br label %10
10: ; preds = %8, %4
%11 = phi i64 [ %9, %8 ], [ %5, %4 ]
ret i64 %11
}