void test_string() {
  printf("%s start.\n", __func__);
  char *arr = {"one", "two", "three", "four"};
  create();
  insert(0, &arr[0]);
  insert_first(&arr[1]);
  insert_last(&arr[2]);
  insert(1, &arr[3]);
  printf("string is_empty=%d\n", is_empty());
  printf("string size=%d\n", size());
  int i;
  char *p;
  int len = size();
  for (i = 0; i < len; i++) {
    p = (char *)get(i);
    printf("string get(%d)=%s\n", i, p);
  }
  destory();
  printf("%s finish.\n", __func__);
}


x86 assembly (clang, -O0):
<test_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe61(%rip),%rdi
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe63(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1070 <create@plt>
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
mov    $0x0,%al
call   1090 <insert@plt>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    $0x0,%al
call   10b0 <insert_first@plt>
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
mov    $0x0,%al
call   1040 <insert_last@plt>
mov    -0x8(%rbp),%rsi
add    $0x3,%rsi
mov    $0x1,%edi
mov    $0x0,%al
call   1090 <insert@plt>
mov    $0x0,%al
call   1060 <is_empty@plt>
mov    %eax,%esi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <size@plt>
mov    %eax,%esi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <size@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    127c <test_string+0xec>
mov    -0xc(%rbp),%edi
mov    $0x0,%al
call   1080 <get@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    123d <test_string+0xad>
mov    $0x0,%al
call   10a0 <destory@plt>
lea    0xdc8(%rip),%rdi
lea    0xd7a(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_string>:
push   %rbp
push   %r14
push   %rbx
lea    0xe65(%rip),%rdi
lea    0xe69(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <create@plt>
lea    0xe60(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1090 <insert@plt>
lea    0xe51(%rip),%rdi
xor    %eax,%eax
call   10b0 <insert_first@plt>
lea    0xe44(%rip),%rdi
xor    %eax,%eax
call   1040 <insert_last@plt>
lea    0xe37(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1090 <insert@plt>
xor    %eax,%eax
call   1060 <is_empty@plt>
lea    0xe1e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <size@plt>
lea    0xe1b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <size@plt>
test   %eax,%eax
jle    125f <test_string+0xcf>
mov    %eax,%ebx
lea    0xe0e(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
xor    %eax,%eax
call   1080 <get@plt>
movslq %eax,%rdx
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1240 <test_string+0xb0>
xor    %eax,%eax
call   10a0 <destory@plt>
lea    0xde5(%rip),%rdi
lea    0xd97(%rip),%rsi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"%s start.\0A\00"
@__func__.test_string = [12 x i8] c"test_string\00"
@.str.1 = [4 x i8] c"one\00"
@.str.2 = [20 x i8] c"string is_empty=%d\0A\00"
@.str.3 = [16 x i8] c"string size=%d\0A\00"
@.str.4 = [19 x i8] c"string get(%d)=%s\0A\00"
@.str.5 = [12 x i8] c"%s finish.\0A\00"
define void @test_string() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.test_string, i64 0, i64 0))
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %1
%6 = call i32 (...) @create()
%7 = load i8*, i8** %1
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @insert to i32 (i32, i8*, ...)*)(i32 0, i8* %8)
%10 = load i8*, i8** %1
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = call i32 (i8*, ...) bitcast (i32 (...)* @insert_first to i32 (i8*, ...)*)(i8* %11)
%13 = load i8*, i8** %1
%14 = getelementptr inbounds i8, i8* %13, i64 2
%15 = call i32 (i8*, ...) bitcast (i32 (...)* @insert_last to i32 (i8*, ...)*)(i8* %14)
%16 = load i8*, i8** %1
%17 = getelementptr inbounds i8, i8* %16, i64 3
%18 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @insert to i32 (i32, i8*, ...)*)(i32 1, i8* %17)
%19 = call i32 (...) @is_empty()
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = call i32 (...) @size()
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = call i32 (...) @size()
store i32 %23, i32* %4
store i32 0, i32* %2
br label %24
24: ; preds = %36, %0
%25 = load i32, i32* %2
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %39
28: ; preds = %24
%29 = load i32, i32* %2
%30 = call i32 (i32, ...) bitcast (i32 (...)* @get to i32 (i32, ...)*)(i32 %29)
%31 = sext i32 %30 to i64
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %3
%33 = load i32, i32* %2
%34 = load i8*, i8** %3
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %33, i8* %34)
br label %36
36: ; preds = %28
%37 = load i32, i32* %2
%38 = add nsw i32 %37, 1
store i32 %38, i32* %2
br label %24
39: ; preds = %24
%40 = call i32 (...) @destory()
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.test_string, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s start.\0A\00"
@__func__.test_string = [12 x i8] c"test_string\00"
@.str.1 = [4 x i8] c"one\00"
@.str.2 = [20 x i8] c"string is_empty=%d\0A\00"
@.str.3 = [16 x i8] c"string size=%d\0A\00"
@.str.4 = [19 x i8] c"string get(%d)=%s\0A\00"
@.str.5 = [12 x i8] c"%s finish.\0A\00"
define void @test_string() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.test_string, i64 0, i64 0))
%2 = tail call i32 (...) @create()
%3 = tail call i32 (i32, i8*, ...) bitcast (i32 (...)* @insert to i32 (i32, i8*, ...)*)(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) bitcast (i32 (...)* @insert_first to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 1))
%5 = tail call i32 (i8*, ...) bitcast (i32 (...)* @insert_last to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 2))
%6 = tail call i32 (i32, i8*, ...) bitcast (i32 (...)* @insert to i32 (i32, i8*, ...)*)(i32 1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 3))
%7 = tail call i32 (...) @is_empty()
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = tail call i32 (...) @size()
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = tail call i32 (...) @size()
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %0, %13
%14 = phi i32 [ %19, %13 ], [ 0, %0 ]
%15 = tail call i32 (i32, ...) bitcast (i32 (...)* @get to i32 (i32, ...)*)(i32 %14)
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i8*
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %14, i8* %17)
%19 = add nuw nsw i32 %14, 1
%20 = icmp eq i32 %19, %11
br i1 %20, label %21, label %13
21: ; preds = %13, %0
%22 = tail call i32 (...) @destory()
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.test_string, i64 0, i64 0))
ret void
}