// File: /workspace/github_c_makefile_star2_O2/cyb70289[P]tt/tests/sort.c
// Function: main
int main(void)
{
	int *data = malloc(sizeof(int) * LEN);
	int *data_save = malloc(sizeof(int) * LEN);

	printf("Generating %d integers...\n", LEN);
	struct timeval tv;
	for (int i = 0; i < LEN; i++) {
		gettimeofday(&tv, NULL);
		srand(tv.tv_usec);
		data[i] = rand();
		data[i] /= (RAND_MAX / LEN);
		data[i] -= (LEN / 2);
	}
	memcpy(data_save, data, sizeof(int) * LEN);
	printf("Done\n\n");

	struct tt_sort_input input = {
		.num	= {
			.size	= sizeof(int),
			.cmp	= cmp_int,
			.swap	= NULL,
		},
		.data	= data,
		.count	= LEN,
		.alg	= TT_SORT_MERGE,
	};

	memcpy(data, data_save, sizeof(int) * LEN);
	printf("Testing merge sort...\n");
	clock_t st = clock();
	tt_sort(&input);
	if (verify(data))
		printf("Done in %u ms\n", (uint)(clock() - st) / 1000);
	else
		printf("FAIL\n");
	printf("\n");

	memcpy(data, data_save, sizeof(int) * LEN);
	printf("Testing heap sort...\n");
	input.alg = TT_SORT_HEAP;
	st = clock();
	tt_sort(&input);
	if (verify(data))
		printf("Done in %u ms\n", (uint)(clock() - st) / 1000);
	else
		printf("FAIL\n");
	printf("\n");

	memcpy(data, data_save, sizeof(int) * LEN);
	printf("Testing quick sort(random)...\n");
	input.alg = TT_SORT_QUICK;
	st = clock();
	tt_sort(&input);
	if (verify(data))
		printf("Done in %u ms\n", (uint)(clock() - st) / 1000);
	else
		printf("FAIL\n");
	printf("\n");

	printf("Testing quick sort(sorted)...\n");
	input.alg = TT_SORT_QUICK;
	st = clock();
	tt_sort(&input);
	if (verify(data))
		printf("Done in %u ms\n", (uint)(clock() - st) / 1000);
	else
		printf("FAIL\n");
	printf("\n");

	printf("Testing quick sort(two value)...\n");
	for (int i = 0; i < LEN; i++)
		data[i] = (data[i] >= 0 ? 1 : -1);
	input.alg = TT_SORT_QUICK;
	st = clock();
	tt_sort(&input);
	if (verify(data))
		printf("Done in %u ms\n", (uint)(clock() - st) / 1000);
	else
		printf("FAIL\n");
	printf("\n");

	printf("Testing quick sort(equal)...\n");
	for (int i = 0; i < LEN; i++)
		data[i] = 1;
	input.alg = TT_SORT_QUICK;
	st = clock();
	tt_sort(&input);
	if (verify(data))
		printf("Done in %u ms\n", (uint)(clock() - st) / 1000);
	else
		printf("FAIL\n");
	printf("\n");

	memcpy(data, data_save, sizeof(int) * LEN);
	printf("Testing insert sort...\n");
	input.alg = TT_SORT_INSERT;
	st = clock();
	tt_sort(&input);
	if (verify(data))
		printf("Done in %u ms\n", (uint)(clock() - st) / 1000);
	else
		printf("FAIL\n");
	printf("\n");

	free(data);
	free(data_save);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movl $0x40000, %edi          # imm = 0x40000
callq 0x1140
movq %rax, %rbx
movl $0x40000, %edi          # imm = 0x40000
callq 0x1140
movq %rax, %r14
leaq 0x2d4b(%rip), %rdi      # 0x4004
xorl %r12d, %r12d
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
callq 0x10b0
leaq 0x30(%rsp), %r15
movl $0x7fff, %ebp           # imm = 0x7FFF
cmpq $0x10000, %r12          # imm = 0x10000
je 0x1304
movq %r15, %rdi
xorl %esi, %esi
callq 0x10d0
movl 0x38(%rsp), %edi
callq 0x10f0
callq 0x1180
cltd
idivl %ebp
addl $0xffff8000, %eax       # imm = 0xFFFF8000
movl %eax, (%rbx,%r12,4)
incq %r12
jmp 0x12d2
movl $0x40000, %edx          # imm = 0x40000
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1120
leaq 0x2d13(%rip), %rdi      # 0x402e
callq 0x1060
movq %rsp, %r12
movl $0x4, (%r12)
leaq 0x390(%rip), %rax       # 0x16c2
movq %rax, 0x8(%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r12)
movq %rbx, 0x20(%r12)
movabsq $0x100010000, %rax      # imm = 0x100010000
movq %rax, 0x28(%r12)
movl $0x40000, %edx          # imm = 0x40000
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1120
leaq 0x2cc9(%rip), %rdi      # 0x4034
callq 0x1060
callq 0x1090
movq %rax, %r15
movq %r12, %rdi
callq 0x1e50
movq %rbx, %rdi
callq 0x16c7
testb %al, %al
je 0x13af
callq 0x1090
subl %r15d, %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
leaq 0x2c7b(%rip), %rdi      # 0x401f
movl %eax, %esi
xorl %eax, %eax
callq 0x10b0
jmp 0x13bb
leaq 0x2d3a(%rip), %rdi      # 0x40f0
callq 0x1060
pushq $0xa
popq %rdi
callq 0x1040
movl $0x40000, %edx          # imm = 0x40000
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1120
leaq 0x2c70(%rip), %rdi      # 0x404a
callq 0x1060
movq %rsp, %r12
movl $0x2, 0x2c(%r12)
callq 0x1090
movq %rax, %r15
movq %r12, %rdi
callq 0x1e50
movq %rbx, %rdi
callq 0x16c7
testb %al, %al
je 0x142a
callq 0x1090
subl %r15d, %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
leaq 0x2c00(%rip), %rdi      # 0x401f
movl %eax, %esi
xorl %eax, %eax
callq 0x10b0
jmp 0x1436
leaq 0x2cbf(%rip), %rdi      # 0x40f0
callq 0x1060
pushq $0xa
popq %rdi
callq 0x1040
movl $0x40000, %edx          # imm = 0x40000
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1120
leaq 0x2c0a(%rip), %rdi      # 0x405f
callq 0x1060
movq %rsp, %r12
movl $0x3, 0x2c(%r12)
callq 0x1090
movq %rax, %r15
movq %r12, %rdi
callq 0x1e50
movq %rbx, %rdi
callq 0x16c7
testb %al, %al
je 0x14a5
callq 0x1090
subl %r15d, %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
leaq 0x2b85(%rip), %rdi      # 0x401f
movl %eax, %esi
xorl %eax, %eax
callq 0x10b0
jmp 0x14b1
leaq 0x2c44(%rip), %rdi      # 0x40f0
callq 0x1060
pushq $0xa
popq %rdi
callq 0x1040
leaq 0x2bbd(%rip), %rdi      # 0x407d
callq 0x1060
movq %rsp, %r12
movl $0x3, 0x2c(%r12)
callq 0x1090
movq %rax, %r15
movq %r12, %rdi
callq 0x1e50
movq %rbx, %rdi
callq 0x16c7
testb %al, %al
je 0x1510
callq 0x1090
subl %r15d, %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
leaq 0x2b1a(%rip), %rdi      # 0x401f
movl %eax, %esi
xorl %eax, %eax
callq 0x10b0
jmp 0x151c
leaq 0x2bd9(%rip), %rdi      # 0x40f0
callq 0x1060
pushq $0xa
popq %rdi
callq 0x1040
leaq 0x2b70(%rip), %rdi      # 0x409b
callq 0x1060
xorl %eax, %eax
cmpq $0x10000, %rax          # imm = 0x10000
je 0x154b
movl (%rbx,%rax,4), %ecx
sarl $0x1f, %ecx
orl $0x1, %ecx
movl %ecx, (%rbx,%rax,4)
incq %rax
jmp 0x1532
movq %rsp, %r12
movl $0x3, 0x2c(%r12)
callq 0x1090
movq %rax, %r15
movq %r12, %rdi
callq 0x1e50
movq %rbx, %rdi
callq 0x16c7
testb %al, %al
je 0x1596
callq 0x1090
subl %r15d, %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
leaq 0x2a94(%rip), %rdi      # 0x401f
movl %eax, %esi
xorl %eax, %eax
callq 0x10b0
jmp 0x15a2
leaq 0x2b53(%rip), %rdi      # 0x40f0
callq 0x1060
pushq $0xa
popq %rdi
callq 0x1040
leaq 0x2b0b(%rip), %rdi      # 0x40bc
callq 0x1060
xorl %eax, %eax
cmpq $0x10000, %rax          # imm = 0x10000
je 0x15cc
movl $0x1, (%rbx,%rax,4)
incq %rax
jmp 0x15b8
movq %rsp, %r12
movl $0x3, 0x2c(%r12)
callq 0x1090
movq %rax, %r15
movq %r12, %rdi
callq 0x1e50
movq %rbx, %rdi
callq 0x16c7
testb %al, %al
je 0x1617
callq 0x1090
subl %r15d, %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
leaq 0x2a13(%rip), %rdi      # 0x401f
movl %eax, %esi
xorl %eax, %eax
callq 0x10b0
jmp 0x1623
leaq 0x2ad2(%rip), %rdi      # 0x40f0
callq 0x1060
pushq $0xa
popq %rdi
callq 0x1040
movl $0x40000, %edx          # imm = 0x40000
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1120
leaq 0x2a97(%rip), %rdi      # 0x40d9
callq 0x1060
movq %rsp, %r12
andl $0x0, 0x2c(%r12)
callq 0x1090
movq %rax, %r15
movq %r12, %rdi
callq 0x1e50
movq %rbx, %rdi
callq 0x16c7
testb %al, %al
je 0x168f
callq 0x1090
subl %r15d, %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
leaq 0x299b(%rip), %rdi      # 0x401f
movl %eax, %esi
xorl %eax, %eax
callq 0x10b0
jmp 0x169b
leaq 0x2a5a(%rip), %rdi      # 0x40f0
callq 0x1060
pushq $0xa
popq %rdi
callq 0x1040
movq %rbx, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
xorl %eax, %eax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq