void string_test() {
  char *sarr[4] = {"ten", "twenty", "thirty", "forty"};
  printf("\n----%s----\n", __func__);
  create_dlink();
  dlink_insert(0, sarr[0]);
  dlink_insert(0, sarr[1]);
  dlink_insert(0, sarr[2]);
  printf("dlink_is_empty()=%d\n", dlink_is_empty());
  printf("dlink_size()=%d\n", dlink_size());
  int i;
  char *p;
  int sz = dlink_size();
  for (i = 0; i < sz; i++) {
    p = (char *)dlink_get(i);
    printf("dlink_get(%d)=%s\n", i, p);
  }
  destroy_dlink();
}


x86 assembly (clang, -O0):
<string_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2c81(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c7e(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2c7b(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2c78(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xe6d(%rip),%rdi
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <create_dlink@plt>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
mov    $0x0,%al
call   1070 <dlink_insert@plt>
mov    -0x18(%rbp),%rsi
xor    %edi,%edi
mov    $0x0,%al
call   1070 <dlink_insert@plt>
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
mov    $0x0,%al
call   1070 <dlink_insert@plt>
mov    $0x0,%al
call   1080 <dlink_is_empty@plt>
mov    %eax,%esi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <dlink_size@plt>
mov    %eax,%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <dlink_size@plt>
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1265 <string_test+0xf5>
mov    -0x24(%rbp),%edi
mov    $0x0,%al
call   1050 <dlink_get@plt>
cltq
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1226 <string_test+0xb6>
mov    $0x0,%al
call   1090 <destroy_dlink@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_test>:
push   %rbp
push   %r14
push   %rbx
lea    0xe97(%rip),%rdi
lea    0xe9d(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <create_dlink@plt>
lea    0xe69(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1070 <dlink_insert@plt>
lea    0xe5d(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1070 <dlink_insert@plt>
lea    0xe54(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1070 <dlink_insert@plt>
xor    %eax,%eax
call   1080 <dlink_is_empty@plt>
lea    0xe5d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <dlink_size@plt>
lea    0xe5b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <dlink_size@plt>
test   %eax,%eax
jle    122f <string_test+0xbf>
mov    %eax,%ebx
lea    0xe4f(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
xor    %eax,%eax
call   1050 <dlink_get@plt>
movslq %eax,%rdx
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1210 <string_test+0xa0>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1090 <destroy_dlink@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"ten\00"
@.str.1 = [7 x i8] c"twenty\00"
@.str.2 = [7 x i8] c"thirty\00"
@.str.3 = [6 x i8] c"forty\00"
@__const.string_test.sarr = [4 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0)]
@.str.4 = [13 x i8] c"\0A----%s----\0A\00"
@__func__.string_test = [12 x i8] c"string_test\00"
@.str.5 = [21 x i8] c"dlink_is_empty()=%d\0A\00"
@.str.6 = [17 x i8] c"dlink_size()=%d\0A\00"
@.str.7 = [18 x i8] c"dlink_get(%d)=%s\0A\00"
define void @string_test() {
%1 = alloca [4 x i8*]
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = bitcast [4 x i8*]* %1 to i8*
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.string_test, i64 0, i64 0))
%7 = call i32 (...) @create_dlink()
%8 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 0
%9 = load i8*, i8** %8
%10 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @dlink_insert to i32 (i32, i8*, ...)*)(i32 0, i8* %9)
%11 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 1
%12 = load i8*, i8** %11
%13 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @dlink_insert to i32 (i32, i8*, ...)*)(i32 0, i8* %12)
%14 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 2
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @dlink_insert to i32 (i32, i8*, ...)*)(i32 0, i8* %15)
%17 = call i32 (...) @dlink_is_empty()
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %17)
%19 = call i32 (...) @dlink_size()
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %19)
%21 = call i32 (...) @dlink_size()
store i32 %21, i32* %4
store i32 0, i32* %2
br label %22
22: ; preds = %34, %0
%23 = load i32, i32* %2
%24 = load i32, i32* %4
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %37
26: ; preds = %22
%27 = load i32, i32* %2
%28 = call i32 (i32, ...) bitcast (i32 (...)* @dlink_get to i32 (i32, ...)*)(i32 %27)
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %3
%31 = load i32, i32* %2
%32 = load i8*, i8** %3
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %31, i8* %32)
br label %34
34: ; preds = %26
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 1
store i32 %36, i32* %2
br label %22
37: ; preds = %22
%38 = call i32 (...) @destroy_dlink()
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"ten\00"
@.str.1 = [7 x i8] c"twenty\00"
@.str.2 = [7 x i8] c"thirty\00"
@.str.4 = [13 x i8] c"\0A----%s----\0A\00"
@__func__.string_test = [12 x i8] c"string_test\00"
@.str.5 = [21 x i8] c"dlink_is_empty()=%d\0A\00"
@.str.6 = [17 x i8] c"dlink_size()=%d\0A\00"
@.str.7 = [18 x i8] c"dlink_get(%d)=%s\0A\00"
define void @string_test() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.string_test, i64 0, i64 0))
%2 = tail call i32 (...) @create_dlink()
%3 = tail call i32 (i32, i8*, ...) bitcast (i32 (...)* @dlink_insert to i32 (i32, i8*, ...)*)(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (i32, i8*, ...) bitcast (i32 (...)* @dlink_insert to i32 (i32, i8*, ...)*)(i32 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 (i32, i8*, ...) bitcast (i32 (...)* @dlink_insert to i32 (i32, i8*, ...)*)(i32 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 (...) @dlink_is_empty()
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %6)
%8 = tail call i32 (...) @dlink_size()
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %8)
%10 = tail call i32 (...) @dlink_size()
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %0, %12
%13 = phi i32 [ %18, %12 ], [ 0, %0 ]
%14 = tail call i32 (i32, ...) bitcast (i32 (...)* @dlink_get to i32 (i32, ...)*)(i32 %13)
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %13, i8* %16)
%18 = add nuw nsw i32 %13, 1
%19 = icmp eq i32 %18, %10
br i1 %19, label %20, label %12
20: ; preds = %12, %0
%21 = tail call i32 (...) @destroy_dlink()
ret void
}