#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 /*<<< orphan*/ init_str(char *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ utf8char_at(char *, char *, int);
int utf8strlen(char *);
int main() {
  char *src = "abc愛うeoお";
  char dest[8];
  for (int i = 0; i < utf8strlen(src); i++) {
    init_str(dest, 8);
    utf8char_at(dest, src, i);
    printf("%d", (int)dest);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <utf8strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11bb <main+0x7b>
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
call   1050 <init_str@plt>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <utf8char_at@plt>
lea    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xe67(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1161 <main+0x21>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%rdi
call   1060 <utf8strlen@plt>
test   %eax,%eax
jle    11a3 <main+0x63>
mov    %rsp,%rbx
xor    %ebp,%ebp
lea    0xe9d(%rip),%r14
lea    0xea5(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x8,%esi
call   1050 <init_str@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <utf8char_at@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
add    $0x1,%ebp
mov    %r14,%rdi
call   1060 <utf8strlen@plt>
cmp    %eax,%ebp
jl     1170 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"abc\E6\84\9B\E3\81\86eo\E3\81\8A\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [8 x i8]
%4 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %2
store i32 0, i32* %4
br label %5
5: ; preds = %20, %0
%6 = load i32, i32* %4
%7 = load i8*, i8** %2
%8 = call i32 @utf8strlen(i8* %7)
%9 = icmp slt i32 %6, %8
br i1 %9, label %10, label %23
10: ; preds = %5
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%12 = call i32 @init_str(i8* %11, i32 8)
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%14 = load i8*, i8** %2
%15 = load i32, i32* %4
%16 = call i32 @utf8char_at(i8* %13, i8* %14, i32 %15)
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%18 = ptrtoint i8* %17 to i32
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %10
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %5
23: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"abc\E6\84\9B\E3\81\86eo\E3\81\8A\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca [8 x i8]
%2 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%3 = call i32 @utf8strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = ptrtoint [8 x i8]* %1 to i64
%7 = trunc i64 %6 to i32
br label %9
8: ; preds = %9, %0
ret i32 0
9: ; preds = %5, %9
%10 = phi i32 [ 0, %5 ], [ %14, %9 ]
%11 = call i32 @init_str(i8* %2, i32 8)
%12 = call i32 @utf8char_at(i8* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %10)
%13 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%14 = add nuw nsw i32 %10, 1
%15 = call i32 @utf8strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%16 = icmp slt i32 %14, %15
br i1 %16, label %9, label %8
}