#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*/ assert(int);
int /*<<< orphan*/ fcitx_utf8_strncpy(char *, char const *, int);
scalar_t__ memcmp(char *, char const *, int);
int main() {
  char buf[9];
  const char string[] =
      "\xe4\xbd\xa0\xe5\xa5\xbd\xe6\xb5\x8b\xe8\xaf\x95\xe5\xb8\x8c\xe6";
  const char result[] = {'\xe4', '\xbd', '\xa0', '\xe5', '\xa5',
                         '\xbd', '\0',   '\0',   '\0'};
  fcitx_utf8_strncpy(buf, string, 9 - 1);
  buf[9 - 1] = 0;
  assert(memcmp(buf, result, 9) == 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb5(%rip),%al
mov    %al,-0x10(%rbp)
mov    0xeac(%rip),%rax
mov    %rax,-0x29(%rbp)
mov    0xeaa(%rip),%al
mov    %al,-0x21(%rbp)
lea    -0xd(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1030 <fcitx_utf8_strncpy@plt>
movb   $0x0,-0x5(%rbp)
lea    -0xd(%rbp),%rdi
lea    -0x29(%rbp),%rsi
mov    $0x9,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
movaps 0xec4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movb   $0x0,0x30(%rsp)
movabs $0xbda5e5a0bde4,%rax
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp)
lea    0x17(%rsp),%rbx
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1030 <fcitx_utf8_strncpy@plt>
movb   $0x0,0x1f(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x9,%edx
call   1040 <memcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.string = [17 x i8] c"\E4\BD\A0\E5\A5\BD\E6\B5\8B\E8\AF\95\E5\B8\8C\E6\00"
@__const.main.result = [9 x i8] c"\E4\BD\A0\E5\A5\BD\00\00\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [9 x i8]
%3 = alloca [17 x i8]
%4 = alloca [9 x i8]
store i32 0, i32* %1
%5 = bitcast [17 x i8]* %3 to i8*
%6 = bitcast [9 x i8]* %4 to i8*
%7 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%9 = call i32 @fcitx_utf8_strncpy(i8* %7, i8* %8, i32 8)
%10 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 8
store i8 0, i8* %10
%11 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%12 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%13 = call i64 @memcmp(i8* %11, i8* %12, i32 9)
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
ret i32 0
}

LLVM IR (-O2):
@__const.main.string = [17 x i8] c"\E4\BD\A0\E5\A5\BD\E6\B5\8B\E8\AF\95\E5\B8\8C\E6\00"
@__const.main.result = [9 x i8] c"\E4\BD\A0\E5\A5\BD\00\00\00"
define i32 @main() {
%1 = alloca [9 x i8]
%2 = alloca [17 x i8]
%3 = alloca [9 x i8]
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%7 = call i32 @fcitx_utf8_strncpy(i8* %4, i8* %5, i32 8)
%8 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 8
store i8 0, i8* %8
%9 = call i64 @memcmp(i8* %4, i8* %6, i32 9)
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
ret i32 0
}