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


x86 assembly (clang, -O0):
<haskeline_mk_wcswidth_cjk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmpq   $0x0,(%rcx)
mov    %al,-0x21(%rbp)
je     1153 <haskeline_mk_wcswidth_cjk+0x43>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
seta   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1163 <haskeline_mk_wcswidth_cjk+0x53>
jmp    11a6 <haskeline_mk_wcswidth_cjk+0x96>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <haskeline_mk_wcwidth_cjk@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1187 <haskeline_mk_wcswidth_cjk+0x77>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <haskeline_mk_wcswidth_cjk+0x9c>
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1195 <haskeline_mk_wcswidth_cjk+0x85>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1127 <haskeline_mk_wcswidth_cjk+0x17>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<haskeline_mk_wcswidth_cjk>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1150 <haskeline_mk_wcswidth_cjk+0x40>
mov    %rsi,%r14
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
cmp    %rbx,%r14
je     1159 <haskeline_mk_wcswidth_cjk+0x49>
call   1030 <haskeline_mk_wcwidth_cjk@plt>
test   %eax,%eax
js     1154 <haskeline_mk_wcswidth_cjk+0x44>
add    %eax,%ebp
mov    0x8(%r15,%rbx,8),%rdi
add    $0x1,%rbx
test   %rdi,%rdi
jne    1130 <haskeline_mk_wcswidth_cjk+0x20>
jmp    1159 <haskeline_mk_wcswidth_cjk+0x49>
xor    %ebp,%ebp
jmp    1159 <haskeline_mk_wcswidth_cjk+0x49>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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