#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 */
int EOF;
int getchar();
int /*<<< orphan*/ printf(char *, char *, int);
int utf8parse(unsigned char);
int wcwidth(int);
int main() {
  char str[10];
  int i, c, u, w;
  for (;;) {
    i = 0;
    do {
      c = getchar();
      if (c == EOF)
        goto bye;
      str[i++] = c;
    } while ((u = utf8parse((unsigned char)c)) == -1);
    str[i] = 0;
    w = wcwidth(u);
    printf("%s : %d\n", str, w);
  }
bye:
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%eax
jne    1177 <main+0x37>
jmp    11d0 <main+0x90>
mov    -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x14(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
cltq
mov    %cl,-0xe(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
movzbl %al,%edi
call   1030 <utf8parse@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1156 <main+0x16>
movslq -0x14(%rbp),%rax
movb   $0x0,-0xe(%rbp,%rax,1)
mov    -0x1c(%rbp),%edi
call   1060 <wcwidth@plt>
mov    %eax,-0x20(%rbp)
lea    -0xe(%rbp),%rsi
mov    -0x20(%rbp),%edx
lea    0xe3a(%rip),%rdi
call   1040 <printf@plt>
jmp    114f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e96(%rip),%r12
lea    0xea7(%rip),%r14
lea    0xe(%rsp),%r15
xchg   %ax,%ax
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r12),%eax
je     11a1 <main+0x61>
mov    %al,0xe(%rsp,%rbx,1)
add    $0x1,%rbx
movzbl %al,%edi
call   1030 <utf8parse@plt>
cmp    $0xffffffff,%eax
je     1162 <main+0x22>
mov    %ebx,%ecx
movb   $0x0,0xe(%rsp,%rcx,1)
mov    %eax,%edi
call   1060 <wcwidth@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
jmp    1160 <main+0x20>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [9 x i8] c"%s : %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
br label %7
7: ; preds = %26, %0
store i32 0, i32* %3
br label %8
8: ; preds = %21, %7
%9 = call i32 (...) @getchar()
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %8
br label %35
14: ; preds = %8
%15 = load i32, i32* %4
%16 = trunc i32 %15 to i8
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
%19 = sext i32 %17 to i64
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %19
store i8 %16, i8* %20
br label %21
21: ; preds = %14
%22 = load i32, i32* %4
%23 = trunc i32 %22 to i8
%24 = call i32 @utf8parse(i8 zeroext %23)
store i32 %24, i32* %5
%25 = icmp eq i32 %24, -1
br i1 %25, label %8, label %26
26: ; preds = %21
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %28
store i8 0, i8* %29
%30 = load i32, i32* %5
%31 = call i32 @wcwidth(i32 %30)
store i32 %31, i32* %6
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%33 = load i32, i32* %6
%34 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %32, i32 %33)
br label %7
35: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [9 x i8] c"%s : %d\0A\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %14, %0
%4 = phi i64 [ 0, %0 ], [ %15, %14 ]
%5 = call i32 (...) @getchar()
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %21, label %8
8: ; preds = %3
%9 = trunc i32 %5 to i8
%10 = add nuw i64 %4, 1
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %4
store i8 %9, i8* %11
%12 = call i32 @utf8parse(i8 zeroext %9)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %8, %16
%15 = phi i64 [ %10, %8 ], [ 0, %16 ]
br label %3
16: ; preds = %8
%17 = and i64 %10, 4294967295
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 @wcwidth(i32 %12)
%20 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %19)
br label %14
21: ; preds = %3
ret i32 0
}