#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 wybor_mk_wcwidth(int /*<<< orphan*/ const);
int wybor_mk_wcswidth(const wchar_t *pwcs, size_t n) {
  int w, width = 0;
  for (; n-- > 0; pwcs++)
    if ((w = wybor_mk_wcwidth(*pwcs)) < 0)
      return -1;
    else
      width += w;
  return width;
}


x86 assembly (clang, -O0):
<wybor_mk_wcswidth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
jbe    1182 <wybor_mk_wcswidth+0x72>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <wybor_mk_wcwidth@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1163 <wybor_mk_wcswidth+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <wybor_mk_wcswidth+0x78>
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1171 <wybor_mk_wcswidth+0x61>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    1127 <wybor_mk_wcswidth+0x17>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wybor_mk_wcswidth>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     114a <wybor_mk_wcswidth+0x3a>
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%edi
call   1030 <wybor_mk_wcwidth@plt>
test   %eax,%eax
js     114e <wybor_mk_wcswidth+0x3e>
add    %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <wybor_mk_wcswidth+0x20>
jmp    1153 <wybor_mk_wcswidth+0x43>
xor    %ebp,%ebp
jmp    1153 <wybor_mk_wcswidth+0x43>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @wybor_mk_wcswidth(i32* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i64 %1, i64* %5
store i32 0, i32* %7
br label %8
8: ; preds = %23, %2
%9 = load i64, i64* %5
%10 = add i64 %9, -1
store i64 %10, i64* %5
%11 = icmp ugt i64 %9, 0
br i1 %11, label %12, label %26
12: ; preds = %8
%13 = load i32*, i32** %4
%14 = load i32, i32* %13
%15 = call i32 @wybor_mk_wcwidth(i32 %14)
store i32 %15, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 -1, i32* %3
br label %28
18: ; preds = %12
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = add nsw i32 %20, %19
store i32 %21, i32* %7
br label %22
22: ; preds = %18
br label %23
23: ; preds = %22
%24 = load i32*, i32** %4
%25 = getelementptr inbounds i32, i32* %24, i32 1
store i32* %25, i32** %4
br label %8
26: ; preds = %8
%27 = load i32, i32* %7
store i32 %27, i32* %3
br label %28
28: ; preds = %26, %17
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @wybor_mk_wcswidth(i32* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %16, label %4
4: ; preds = %2, %12
%5 = phi i64 [ %8, %12 ], [ %1, %2 ]
%6 = phi i32 [ %13, %12 ], [ 0, %2 ]
%7 = phi i32* [ %14, %12 ], [ %0, %2 ]
%8 = add i64 %5, -1
%9 = load i32, i32* %7
%10 = tail call i32 @wybor_mk_wcwidth(i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %4
%13 = add nsw i32 %10, %6
%14 = getelementptr inbounds i32, i32* %7, i64 1
%15 = icmp eq i64 %8, 0
br i1 %15, label %16, label %4
16: ; preds = %4, %12, %2
%17 = phi i32 [ 0, %2 ], [ %13, %12 ], [ -1, %4 ]
ret i32 %17
}