// File: amadvance[P]tommyds/check.c
// Function: test_list
void test_list(void)
{
	struct object* LIST;
	struct object_vector* VECTOR;
	tommy_node* list;
	unsigned i;
	const unsigned size = TOMMY_SIZE;

	LIST = malloc(size * sizeof(struct object));
	VECTOR = malloc(size * sizeof(struct object_vector));

	for(i=0;i<size;++i) {
		VECTOR[i].value = LIST[i].value = 0;
	}

	tommy_list_init(&list);

	/* sort an empty list */
	tommy_list_sort(&list, compare);

	if (!tommy_list_empty(&list))
		/* LCOV_EXCL_START */
		abort();
		/* LCOV_EXCL_STOP */

	if (tommy_list_tail(&list) != 0)
		/* LCOV_EXCL_START */
		abort();
		/* LCOV_EXCL_STOP */

	if (tommy_list_head(&list) != 0)
		/* LCOV_EXCL_START */
		abort();
		/* LCOV_EXCL_STOP */

	for(i=0;i<size;++i) {
		VECTOR[i].value = LIST[i].value = rnd(size);
		tommy_list_insert_tail(&list, &LIST[i].node, &LIST[i]);
	}

	if (tommy_list_tail(&list) == 0)
		/* LCOV_EXCL_START */
		abort();
		/* LCOV_EXCL_STOP */

	if (tommy_list_head(&list) == 0)
		/* LCOV_EXCL_START */
		abort();
		/* LCOV_EXCL_STOP */

	START("sort random");
	tommy_list_sort(&list, compare);
	STOP();

	START("C qsort random");
	qsort(VECTOR, size, sizeof(VECTOR[0]), compare_vector);
	STOP();

	test_list_order(list);

	/* forward order with some (1%) random values */
	list = 0;
	for(i=0;i<size;++i) {
		VECTOR[i].value = LIST[i].value = i;
		if (rnd(100) == 0)
			VECTOR[i].value = LIST[i].value = rnd(size);
		tommy_list_insert_tail(&list, &LIST[i].node, &LIST[i]);
	}

	START("sort partially ordered");
	tommy_list_sort(&list, compare);
	STOP();

	START("C qsort partially ordered");
	qsort(VECTOR, size, sizeof(VECTOR[0]), compare_vector);
	STOP();

	test_list_order(list);

	/* forward order */
	list = 0;
	for(i=0;i<size;++i) {
		VECTOR[i].value = LIST[i].value = i;
		tommy_list_insert_tail(&list, &LIST[i].node, &LIST[i]);
	}

	START("sort forward");
	tommy_list_sort(&list, compare);
	STOP();

	START("C qsort forward");
	qsort(VECTOR, size, sizeof(VECTOR[0]), compare_vector);
	STOP();

	test_list_order(list);

	/* backward order */
	list = 0;
	for(i=0;i<size;++i) {
		VECTOR[i].value = LIST[i].value = size - 1 - i;
		tommy_list_insert_tail(&list, &LIST[i].node, &LIST[i]);
	}

	START("sort backward");
	tommy_list_sort(&list, compare);
	STOP();

	START("C qsort backward");
	qsort(VECTOR, size, sizeof(VECTOR[0]), compare_vector);
	STOP();

	test_list_order(list);

	/* use a small range of random value to insert a lot of duplicates */
	list = 0;
	for(i=0;i<size;++i) {
		VECTOR[i].value = LIST[i].value = rnd(size / 1000 + 2);
		tommy_list_insert_tail(&list, &LIST[i].node, &LIST[i]);
	}

	START("sort random duplicate");
	tommy_list_sort(&list, compare);
	STOP();

	START("C qsort random duplicate");
	qsort(VECTOR, size, sizeof(VECTOR[0]), compare_vector);
	STOP();

	test_list_order(list);

	free(LIST);
	free(VECTOR);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl $0xf4240, -0x20(%rbp)   # imm = 0xF4240
movl $0x3567e00, %edi        # imm = 0x3567E00
callq 0x10b0
movq %rax, -0x8(%rbp)
movl $0x1312d00, %edi        # imm = 0x1312D00
callq 0x10b0
movq %rax, -0x10(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0xf4240, -0x1c(%rbp)   # imm = 0xF4240
jae 0x1b8e
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %ecx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl $0x0, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1b52
leaq -0x18(%rbp), %rdi
callq 0x2050
leaq -0x18(%rbp), %rdi
leaq -0x9e2(%rip), %rsi      # 0x11c0
callq 0x6110
leaq -0x18(%rbp), %rdi
callq 0x2070
cmpl $0x0, %eax
jne 0x1bba
callq 0x1040
leaq -0x18(%rbp), %rdi
callq 0x20a0
cmpq $0x0, %rax
je 0x1bce
callq 0x1040
leaq -0x18(%rbp), %rdi
callq 0x20e0
cmpq $0x0, %rax
je 0x1be2
callq 0x1040
movl $0x0, -0x1c(%rbp)
cmpl $0xf4240, -0x1c(%rbp)   # imm = 0xF4240
jae 0x1c52
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x12a0
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %edx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %edx
imulq $0x14, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rsi
movl -0x1c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
movq -0x8(%rbp), %rdx
movl -0x1c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rdx
leaq -0x18(%rbp), %rdi
callq 0x2100
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1be9
leaq -0x18(%rbp), %rdi
callq 0x20a0
cmpq $0x0, %rax
jne 0x1c66
callq 0x1040
leaq -0x18(%rbp), %rdi
callq 0x20e0
cmpq $0x0, %rax
jne 0x1c7a
callq 0x1040
leaq 0x8507(%rip), %rdi      # 0xa188
callq 0x13e0
leaq -0x18(%rbp), %rdi
leaq -0xad1(%rip), %rsi      # 0x11c0
callq 0x6110
callq 0x1460
leaq 0x84e3(%rip), %rdi      # 0xa185
callq 0x13e0
movq -0x10(%rbp), %rdi
movl $0xf4240, %esi          # imm = 0xF4240
movl $0x14, %edx
leaq -0xa8c(%rip), %rcx      # 0x1230
callq 0x1050
callq 0x1460
movq -0x18(%rbp), %rdi
callq 0x1a90
movq $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0xf4240, -0x1c(%rbp)   # imm = 0xF4240
jae 0x1d80
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %edx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %edx
imulq $0x14, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl $0x64, %edi
callq 0x12a0
cmpl $0x0, %eax
jne 0x1d49
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x12a0
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %edx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %edx
imulq $0x14, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rsi
movl -0x1c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
movq -0x8(%rbp), %rdx
movl -0x1c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rdx
leaq -0x18(%rbp), %rdi
callq 0x2100
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1cde
leaq 0x8410(%rip), %rdi      # 0xa197
callq 0x13e0
leaq -0x18(%rbp), %rdi
leaq -0xbd7(%rip), %rsi      # 0x11c0
callq 0x6110
callq 0x1460
leaq 0x83ec(%rip), %rdi      # 0xa194
callq 0x13e0
movq -0x10(%rbp), %rdi
movl $0xf4240, %esi          # imm = 0xF4240
movl $0x14, %edx
leaq -0xb92(%rip), %rcx      # 0x1230
callq 0x1050
callq 0x1460
movq -0x18(%rbp), %rdi
callq 0x1a90
movq $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0xf4240, -0x1c(%rbp)   # imm = 0xF4240
jae 0x1e44
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %edx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %edx
imulq $0x14, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rsi
movl -0x1c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
movq -0x8(%rbp), %rdx
movl -0x1c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rdx
leaq -0x18(%rbp), %rdi
callq 0x2100
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1de4
leaq 0x8366(%rip), %rdi      # 0xa1b1
callq 0x13e0
leaq -0x18(%rbp), %rdi
leaq -0xc9b(%rip), %rsi      # 0x11c0
callq 0x6110
callq 0x1460
leaq 0x8342(%rip), %rdi      # 0xa1ae
callq 0x13e0
movq -0x10(%rbp), %rdi
movl $0xf4240, %esi          # imm = 0xF4240
movl $0x14, %edx
leaq -0xc56(%rip), %rcx      # 0x1230
callq 0x1050
callq 0x1460
movq -0x18(%rbp), %rdi
callq 0x1a90
movq $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0xf4240, -0x1c(%rbp)   # imm = 0xF4240
jae 0x1f0d
movl $0xf423f, %ecx          # imm = 0xF423F
subl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %edx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %edx
imulq $0x14, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rsi
movl -0x1c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
movq -0x8(%rbp), %rdx
movl -0x1c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rdx
leaq -0x18(%rbp), %rdi
callq 0x2100
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1ea8
leaq 0x82ad(%rip), %rdi      # 0xa1c1
callq 0x13e0
leaq -0x18(%rbp), %rdi
leaq -0xd64(%rip), %rsi      # 0x11c0
callq 0x6110
callq 0x1460
leaq 0x8289(%rip), %rdi      # 0xa1be
callq 0x13e0
movq -0x10(%rbp), %rdi
movl $0xf4240, %esi          # imm = 0xF4240
movl $0x14, %edx
leaq -0xd1f(%rip), %rcx      # 0x1230
callq 0x1050
callq 0x1460
movq -0x18(%rbp), %rdi
callq 0x1a90
movq $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0xf4240, -0x1c(%rbp)   # imm = 0xF4240
jae 0x1fda
movl $0x3ea, %edi            # imm = 0x3EA
callq 0x12a0
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %edx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %edx
imulq $0x14, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rsi
movl -0x1c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
movq -0x8(%rbp), %rdx
movl -0x1c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rdx
leaq -0x18(%rbp), %rdi
callq 0x2100
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1f71
leaq 0x81f1(%rip), %rdi      # 0xa1d2
callq 0x13e0
leaq -0x18(%rbp), %rdi
leaq -0xe31(%rip), %rsi      # 0x11c0
callq 0x6110
callq 0x1460
leaq 0x81cd(%rip), %rdi      # 0xa1cf
callq 0x13e0
movq -0x10(%rbp), %rdi
movl $0xf4240, %esi          # imm = 0xF4240
movl $0x14, %edx
leaq -0xdec(%rip), %rcx      # 0x1230
callq 0x1050
callq 0x1460
movq -0x18(%rbp), %rdi
callq 0x1a90
movq -0x8(%rbp), %rdi
callq 0x1030
movq -0x10(%rbp), %rdi
callq 0x1030
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)