void int_test() {
  int iarr[4] = {10, 20, 30, 40};
  printf("\n----%s----\n", __FUNCTION__);
  create_dlink();
  dlink_insert(0, &iarr[0]);
  dlink_insert(0, &iarr[1]);
  dlink_insert(0, &iarr[2]);
  printf("dlink_is_empty() = %d\n", dlink_is_empty());
  printf("dlink_size() = %d\n", dlink_size());
  int i;
  int *p;
  int sz = dlink_size();
  for (i = 0; i < sz; i++) {
    p = (int *)dlink_get(i);
    printf("dlink_get(%d) = %d\n", i, *p);
  }
  destroy_dlink();
}


x86 assembly (clang, -O0):
<int_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xe81(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xe7e(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xe7b(%rip),%rdi
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <create_dlink@plt>
lea    -0x10(%rbp),%rsi
xor    %edi,%edi
mov    $0x0,%al
call   1070 <dlink_insert@plt>
lea    -0x10(%rbp),%rsi
add    $0x4,%rsi
xor    %edi,%edi
mov    $0x0,%al
call   1070 <dlink_insert@plt>
lea    -0x10(%rbp),%rsi
add    $0x8,%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    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <dlink_size@plt>
mov    %eax,%esi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <dlink_size@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1259 <int_test+0xe9>
mov    -0x14(%rbp),%edi
mov    $0x0,%al
call   1050 <dlink_get@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1218 <int_test+0xa8>
mov    $0x0,%al
call   1090 <destroy_dlink@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_test>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movaps 0xe81(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe86(%rip),%rdi
lea    0xe8c(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <create_dlink@plt>
mov    %rsp,%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1070 <dlink_insert@plt>
lea    0x4(%rsp),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1070 <dlink_insert@plt>
lea    0x8(%rsp),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1070 <dlink_insert@plt>
xor    %eax,%eax
call   1080 <dlink_is_empty@plt>
lea    0xe51(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <dlink_size@plt>
lea    0xe51(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <dlink_size@plt>
test   %eax,%eax
jle    1230 <int_test+0xc0>
mov    %eax,%ebx
lea    0xe47(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
xor    %eax,%eax
call   1050 <dlink_get@plt>
cltq
mov    (%rax),%edx
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1210 <int_test+0xa0>
xor    %eax,%eax
call   1090 <destroy_dlink@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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