#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*/ Utf8ToGb2312(unsigned char *, int, unsigned short *);
int /*<<< orphan*/ printf(char *, unsigned char, unsigned char, unsigned char,
                          unsigned short);
int strlen(unsigned char *);
int main() {
  int i, n;
  unsigned char str[] = "世界你好";
  int num = strlen(str);
  n = num / 3;
  unsigned short int gbArray[n];
  Utf8ToGb2312(str, num, gbArray);
  for (i = 0; i < n; i++) {
    printf("%c%c%c：0x%X\n", str[3 * i], str[3 * i + 1], str[3 * i + 2],
           gbArray[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movabs $0xbda5e5a0bde48c,%rax
mov    %rax,-0x1b(%rbp)
movabs $0xbde48c95e796b8e4,%rax
8c e4 bd
mov    %rax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
imul   $0x55555556,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(%rax,%rax,1),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x40(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x38(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <Utf8ToGb2312@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121e <main+0xee>
mov    -0x40(%rbp),%rax
imul   $0x3,-0x8(%rbp),%ecx
movslq %ecx,%rcx
mov    -0x20(%rbp,%rcx,1),%sil
imul   $0x3,-0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    -0x20(%rbp,%rcx,1),%dl
imul   $0x3,-0x8(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    -0x20(%rbp,%rcx,1),%cl
movslq -0x8(%rbp),%r8
lea    0xe11(%rip),%rdi
movzbl %sil,%esi
movzbl %dl,%edx
movzbl %cl,%ecx
movzwl (%rax,%r8,2),%r8d
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b9 <main+0x89>
movl   $0x0,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movabs $0xbda5e5a0bde48c,%rax
mov    %rax,-0x33(%rbp)
movabs $0xbde48c95e796b8e4,%rax
8c e4 bd
mov    %rax,-0x38(%rbp)
lea    -0x38(%rbp),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rsp,-0x40(%rbp)
movslq %eax,%r15
imul   $0x55555556,%r15,%r12
mov    %r12,%rax
shr    $0x3f,%rax
shr    $0x20,%r12
add    %eax,%r12d
lea    (%r12,%r12,1),%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r13,%rdx
call   1050 <Utf8ToGb2312@plt>
cmp    $0x3,%r15d
jl     11e6 <main+0xb6>
lea    -0x36(%rbp),%rbx
xor    %r15d,%r15d
lea    0xe51(%rip),%r14
nopl   0x0(%rax)
movzbl -0x2(%rbx),%esi
movzbl -0x1(%rbx),%edx
movzbl (%rbx),%ecx
movzwl 0x0(%r13,%r15,2),%r8d
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%r15
add    $0x3,%rbx
cmp    %r15,%r12
jne    11c0 <main+0x90>
mov    -0x40(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.str = [13 x i8] c"\E4\B8\96\E7\95\8C\E4\BD\A0\E5\A5\BD\00"
@.str = [15 x i8] c"%c%c%c\EF\BC\9A0x%X\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [13 x i8]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %1
%8 = bitcast [13 x i8]* %4 to i8*
%9 = getelementptr inbounds [13 x i8], [13 x i8]* %4, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = sdiv i32 %11, 3
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = alloca i16, i64 %14
store i64 %14, i64* %7
%17 = getelementptr inbounds [13 x i8], [13 x i8]* %4, i64 0, i64 0
%18 = load i32, i32* %5
%19 = call i32 @Utf8ToGb2312(i8* %17, i32 %18, i16* %16)
store i32 0, i32* %2
br label %20
20: ; preds = %47, %0
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %50
24: ; preds = %20
%25 = load i32, i32* %2
%26 = mul nsw i32 3, %25
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [13 x i8], [13 x i8]* %4, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = load i32, i32* %2
%31 = mul nsw i32 3, %30
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [13 x i8], [13 x i8]* %4, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = load i32, i32* %2
%37 = mul nsw i32 3, %36
%38 = add nsw i32 %37, 2
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [13 x i8], [13 x i8]* %4, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = load i32, i32* %2
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i16, i16* %16, i64 %43
%45 = load i16, i16* %44
%46 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8 zeroext %29, i8 zeroext %35, i8 zeroext %41, i16 zeroext %45)
br label %47
47: ; preds = %24
%48 = load i32, i32* %2
%49 = add nsw i32 %48, 1
store i32 %49, i32* %2
br label %20
50: ; preds = %20
store i32 0, i32* %1
%51 = load i8*, i8** %6
%52 = load i32, i32* %1
ret i32 %52
}

LLVM IR (-O2):
@__const.main.str = [13 x i8] c"\E4\B8\96\E7\95\8C\E4\BD\A0\E5\A5\BD\00"
@.str = [15 x i8] c"%c%c%c\EF\BC\9A0x%X\0A\00"
define i32 @main() {
%1 = alloca [13 x i8]
%2 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 0
%3 = call i32 @strlen(i8* %2)
%4 = sdiv i32 %3, 3
%5 = zext i32 %4 to i64
%6 = call i8* @llvm.stacksave()
%7 = alloca i16, i64 %5
%8 = call i32 @Utf8ToGb2312(i8* %2, i32 %3, i16* %7)
%9 = icmp sgt i32 %3, 2
br i1 %9, label %10, label %26
10: ; preds = %0, %10
%11 = phi i64 [ %24, %10 ], [ 0, %0 ]
%12 = mul nuw nsw i64 %11, 3
%13 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = add nuw nsw i64 %12, 1
%16 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = add nuw nsw i64 %12, 2
%19 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = getelementptr inbounds i16, i16* %7, i64 %11
%22 = load i16, i16* %21
%23 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8 zeroext %14, i8 zeroext %17, i8 zeroext %20, i16 zeroext %22)
%24 = add nuw nsw i64 %11, 1
%25 = icmp eq i64 %24, %5
br i1 %25, label %26, label %10
26: ; preds = %10, %0
ret i32 0
}