#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;
typedef int /*<<< orphan*/ mbstate_t;
typedef int /*<<< orphan*/ mbs;

/* Variables and functions */
int /*<<< orphan*/ MB_LEN_MAX;
scalar_t__ iswprint(int /*<<< orphan*/);
size_t mbrtowc(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/,
               int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
scalar_t__ printf(char *, char const *);
int /*<<< orphan*/ putchar(unsigned char);
scalar_t__ wcwidth(int /*<<< orphan*/);
int prn_normal(const char *s) {
  mbstate_t mbs;
  wchar_t wc;
  int i, n;
  size_t clen;
  memset(&mbs, 0, sizeof(mbs));
  n = 0;
  while ((clen = mbrtowc(&wc, s, MB_LEN_MAX, &mbs)) != 0) {
    if (clen == (size_t)-2) {
      n += printf("%s", s);
      break;
    }
    if (clen == (size_t)-1) {
      memset(&mbs, 0, sizeof(mbs));
      putchar((unsigned char)*s);
      s++;
      n++;
      continue;
    }
    for (i = 0; i < (int)clen; i++)
      putchar((unsigned char)s[i]);
    s += clen;
    if (iswprint(wc))
      n += wcwidth(wc);
  }
  return (n);
}


x86 assembly (clang, -O0):
<prn_normal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rdi
lea    -0xc(%rbp),%rcx
call   1040 <mbrtowc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1286 <prn_normal+0x126>
cmpq   $0xfffffffffffffffe,-0x20(%rbp)
jne    11d8 <prn_normal+0x78>
mov    -0x8(%rbp),%rsi
lea    0xe3f(%rip),%rdi
call   1050 <printf@plt>
mov    %rax,%rcx
movslq -0x18(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x18(%rbp)
jmp    1286 <prn_normal+0x126>
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    1219 <prn_normal+0xb9>
lea    -0xc(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1183 <prn_normal+0x23>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    %ecx,%eax
jge    124e <prn_normal+0xee>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1220 <prn_normal+0xc0>
mov    -0x20(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%edi
call   1080 <iswprint@plt>
cmp    $0x0,%rax
je     1281 <prn_normal+0x121>
mov    -0x10(%rbp),%edi
call   1070 <wcwidth@plt>
mov    %rax,%rcx
movslq -0x18(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x18(%rbp)
jmp    1183 <prn_normal+0x23>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prn_normal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0x14(%rsp),%r15
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    0x10(%rsp),%r12
jmp    11b1 <prn_normal+0x51>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %r13,%rbx
mov    0x10(%rsp),%edi
call   1080 <iswprint@plt>
test   %rax,%rax
jne    1204 <prn_normal+0xa4>
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rcx
call   1040 <mbrtowc@plt>
cmp    $0xfffffffffffffffe,%rax
je     124c <prn_normal+0xec>
mov    %rax,%r13
cmp    $0xffffffffffffffff,%rax
je     121b <prn_normal+0xbb>
test   %r13,%r13
je     1267 <prn_normal+0x107>
test   %r13d,%r13d
jle    11a0 <prn_normal+0x40>
mov    %r13d,%r14d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    11f0 <prn_normal+0x90>
jmp    11a0 <prn_normal+0x40>
mov    0x10(%rsp),%edi
call   1070 <wcwidth@plt>
mov    0x8(%rsp),%rcx
add    %eax,%ecx
mov    %rcx,0x8(%rsp)
jmp    11b1 <prn_normal+0x51>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
movzbl (%rbx),%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
mov    0x8(%rsp),%rax
mov    $0x1,%ecx
add    %ecx,%eax
mov    %rax,0x8(%rsp)
jmp    11b1 <prn_normal+0x51>
lea    0xdad(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x8(%rsp),%rcx
add    %eax,%ecx
mov    %rcx,%rax
jmp    126c <prn_normal+0x10c>
mov    0x8(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MB_LEN_MAX = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @prn_normal(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
store i8* %0, i8** %2
%8 = call i32 @memset(i32* %3, i32 0, i32 4)
store i32 0, i32* %6
br label %9
9: ; preds = %66, %27, %1
%10 = load i8*, i8** %2
%11 = load i32, i32* @MB_LEN_MAX
%12 = call i64 @mbrtowc(i32* %4, i8* %10, i32 %11, i32* %3)
store i64 %12, i64* %7
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %67
14: ; preds = %9
%15 = load i64, i64* %7
%16 = icmp eq i64 %15, -2
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i8*, i8** %2
%19 = call i64 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = add nsw i64 %21, %19
%23 = trunc i64 %22 to i32
store i32 %23, i32* %6
br label %67
24: ; preds = %14
%25 = load i64, i64* %7
%26 = icmp eq i64 %25, -1
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = call i32 @memset(i32* %3, i32 0, i32 4)
%29 = load i8*, i8** %2
%30 = load i8, i8* %29
%31 = call i32 @putchar(i8 zeroext %30)
%32 = load i8*, i8** %2
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %2
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %9
36: ; preds = %24
store i32 0, i32* %5
br label %37
37: ; preds = %49, %36
%38 = load i32, i32* %5
%39 = load i64, i64* %7
%40 = trunc i64 %39 to i32
%41 = icmp slt i32 %38, %40
br i1 %41, label %42, label %52
42: ; preds = %37
%43 = load i8*, i8** %2
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = call i32 @putchar(i8 zeroext %47)
br label %49
49: ; preds = %42
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
br label %37
52: ; preds = %37
%53 = load i64, i64* %7
%54 = load i8*, i8** %2
%55 = getelementptr inbounds i8, i8* %54, i64 %53
store i8* %55, i8** %2
%56 = load i32, i32* %4
%57 = call i64 @iswprint(i32 %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %66
59: ; preds = %52
%60 = load i32, i32* %4
%61 = call i64 @wcwidth(i32 %60)
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = add nsw i64 %63, %61
%65 = trunc i64 %64 to i32
store i32 %65, i32* %6
br label %66
66: ; preds = %59, %52
br label %9
67: ; preds = %17, %9
%68 = load i32, i32* %6
ret i32 %68
}

LLVM IR (-O2):
@MB_LEN_MAX = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @prn_normal(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = call i32 @memset(i32* %2, i32 0, i32 4)
br label %7
7: ; preds = %28, %1
%8 = phi i32 [ 0, %1 ], [ %31, %28 ]
%9 = phi i8* [ %0, %1 ], [ %30, %28 ]
br label %10
10: ; preds = %7, %39
%11 = phi i8* [ %40, %39 ], [ %9, %7 ]
%12 = load i32, i32* @MB_LEN_MAX
%13 = call i64 @mbrtowc(i32* %3, i8* %11, i32 %12, i32* %2)
switch i64 %13, label %14 [
i64 0, label %48
i64 -2, label %19
i64 -1, label %23
]
14: ; preds = %10
%15 = trunc i64 %13 to i32
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %39
17: ; preds = %14
%18 = and i64 %13, 4294967295
br label %32
19: ; preds = %10
%20 = call i64 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %11)
%21 = trunc i64 %20 to i32
%22 = add i32 %8, %21
br label %48
23: ; preds = %10
%24 = call i32 @memset(i32* %2, i32 0, i32 4)
%25 = load i8, i8* %11
%26 = call i32 @putchar(i8 zeroext %25)
%27 = getelementptr inbounds i8, i8* %11, i64 1
br label %28
28: ; preds = %23, %44
%29 = phi i32 [ %47, %44 ], [ 1, %23 ]
%30 = phi i8* [ %40, %44 ], [ %27, %23 ]
%31 = add i32 %8, %29
br label %7
32: ; preds = %17, %32
%33 = phi i64 [ 0, %17 ], [ %37, %32 ]
%34 = getelementptr inbounds i8, i8* %11, i64 %33
%35 = load i8, i8* %34
%36 = call i32 @putchar(i8 zeroext %35)
%37 = add nuw nsw i64 %33, 1
%38 = icmp eq i64 %37, %18
br i1 %38, label %39, label %32
39: ; preds = %32, %14
%40 = getelementptr inbounds i8, i8* %11, i64 %13
%41 = load i32, i32* %3
%42 = call i64 @iswprint(i32 %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %10, label %44
44: ; preds = %39
%45 = load i32, i32* %3
%46 = call i64 @wcwidth(i32 %45)
%47 = trunc i64 %46 to i32
br label %28
48: ; preds = %10, %19
%49 = phi i32 [ %22, %19 ], [ %8, %10 ]
ret i32 %49
}