#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*/ printf(char *, ...);
int strlen(char *);
int main() {
  char *a = "你好";
  printf("%s\n", a);
  for (int i = 0; i < strlen(a); i++) {
    printf("c: %c d: %d x: %x\n", a[i], (unsigned char)a[i],
           (unsigned char)a[i]);
  }
  a = "汉字";
  printf("%s\n", a);
  for (int i = 0; i < strlen(a); i++) {
    printf("c: %c d: %d x: %x\n", a[i], (unsigned char)a[i],
           (unsigned char)a[i]);
  }
  char data_utf8[] = {0xE6, 0xB1, 0x89, 0xE5, 0xAD, 0x97};
  printf("%s\n", data_utf8);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11af <main+0x8f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1153 <main+0x33>
lea    0xe68(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jge    122f <main+0x10f>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11d3 <main+0xb3>
mov    0xdf0(%rip),%eax
mov    %eax,-0x1e(%rbp)
mov    0xdea(%rip),%ax
mov    %ax,-0x1a(%rbp)
lea    -0x1e(%rbp),%rsi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec0(%rip),%r15
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1187 <main+0x57>
lea    0xeac(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
movzbl (%rbx,%r15,1),%ecx
movsbl %cl,%esi
mov    %r14,%rdi
mov    %ecx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1160 <main+0x30>
lea    0xe8c(%rip),%r15
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11d7 <main+0xa7>
lea    0xe5e(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%r15,1),%ecx
movsbl %cl,%esi
mov    %r14,%rdi
mov    %ecx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11b0 <main+0x80>
movw   $0x97ad,0xc(%rsp)
movl   $0xe589b1e6,0x8(%rsp)
e5
lea    0x8(%rsp),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"\E4\BD\A0\E5\A5\BD\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [19 x i8] c"c: %c d: %d x: %x\0A\00"
@.str.3 = [7 x i8] c"\E6\B1\89\E5\AD\97\00"
@__const.main.data_utf8 = [6 x i8] c"\E6\B1\89\E5\AD\97"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [6 x i8]
store i32 0, i32* %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %2
%6 = load i8*, i8** %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %6)
store i32 0, i32* %3
br label %8
8: ; preds = %33, %0
%9 = load i32, i32* %3
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %36
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = load i8*, i8** %2
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = load i8*, i8** %2
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %25, i32 %31)
br label %33
33: ; preds = %13
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %8
36: ; preds = %8
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %2
%37 = load i8*, i8** %2
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %37)
store i32 0, i32* %4
br label %39
39: ; preds = %64, %36
%40 = load i32, i32* %4
%41 = load i8*, i8** %2
%42 = call i32 @strlen(i8* %41)
%43 = icmp slt i32 %40, %42
br i1 %43, label %44, label %67
44: ; preds = %39
%45 = load i8*, i8** %2
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = load i8*, i8** %2
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = load i8*, i8** %2
%58 = load i32, i32* %4
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %50, i32 %56, i32 %62)
br label %64
64: ; preds = %44
%65 = load i32, i32* %4
%66 = add nsw i32 %65, 1
store i32 %66, i32* %4
br label %39
67: ; preds = %39
%68 = bitcast [6 x i8]* %5 to i8*
%69 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %69)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"\E4\BD\A0\E5\A5\BD\00"
@.str.2 = [19 x i8] c"c: %c d: %d x: %x\0A\00"
@.str.3 = [7 x i8] c"\E6\B1\89\E5\AD\97\00"
@__const.main.data_utf8 = [6 x i8] c"\E6\B1\89\E5\AD\97"
define i32 @main() {
%1 = alloca [6 x i8]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = icmp sgt i32 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %9, %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%8 = icmp sgt i32 %7, 0
br i1 %8, label %23, label %20
9: ; preds = %0, %9
%10 = phi i64 [ %16, %9 ], [ 0, %0 ]
%11 = getelementptr inbounds [7 x i8], [7 x i8]* @.str, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = zext i8 %12 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14, i32 %14)
%16 = add nuw nsw i64 %10, 1
%17 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %9, label %5
20: ; preds = %23, %5
%21 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%22 = call i32 @puts(i8* %21)
ret i32 0
23: ; preds = %5, %23
%24 = phi i64 [ %30, %23 ], [ 0, %5 ]
%25 = getelementptr inbounds [7 x i8], [7 x i8]* @.str.3, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = zext i8 %26 to i32
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %28, i32 %28)
%30 = add nuw nsw i64 %24, 1
%31 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %30, %32
br i1 %33, label %23, label %20
}