// File: /workspace/github_c_makefile_star2_O3/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl $0x40000, %edi          # imm = 0x40000
callq 0x1140
movq %rax, %rbx
movl $0x40000, %edi          # imm = 0x40000
callq 0x1140
movq %rax, %r14
leaq 0x2bc8(%rip), %rdi      # 0x4020
xorl %r12d, %r12d
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
callq 0x10b0
leaq 0x38(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x10d0
movl 0x40(%rsp), %edi
callq 0x10f0
callq 0x1180
cltq
imulq $-0x7ffefffd, %rax, %rcx # imm = 0x80010003
shrq $0x20, %rcx
addl %ecx, %eax
movl %eax, %ecx
sarl $0xe, %ecx
shrl $0x1f, %eax
addl %ecx, %eax
addl $0xffff8000, %eax       # imm = 0xFFFF8000
movl %eax, (%rbx,%r12,4)
incq %r12
cmpq $0x10000, %r12          # imm = 0x10000
jne 0x146c
movl $0x40000, %edx          # imm = 0x40000
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1120
leaq 0x2b81(%rip), %rdi      # 0x404a
callq 0x1060
leaq 0x8(%rsp), %r12
movl $0x4, (%r12)
leaq 0x432(%rip), %rax       # 0x1914
movq %rax, 0x8(%r12)
pxor %xmm0, %xmm0
movdqu %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 0x2b33(%rip), %rdi      # 0x4050
callq 0x1060
callq 0x1090
movq %rax, %r15
movq %r12, %rdi
callq 0x2020
movl $0x1, %eax
cmpq $0x10000, %rax          # imm = 0x10000
je 0x155d
movl -0x4(%rbx,%rax,4), %ecx
leaq 0x1(%rax), %rdx
cmpl (%rbx,%rax,4), %ecx
movq %rdx, %rax
jle 0x1537
leaq 0x2bb6(%rip), %rdi      # 0x410c
callq 0x1060
jmp 0x157e
callq 0x1090
subl %r15d, %eax
imulq $0x10624dd3, %rax, %rsi # imm = 0x10624DD3
shrq $0x26, %rsi
leaq 0x2ac4(%rip), %rdi      # 0x403b
xorl %eax, %eax
callq 0x10b0
movl $0xa, %edi
callq 0x1040
movl $0x40000, %edx          # imm = 0x40000
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1120
leaq 0x2ac7(%rip), %rdi      # 0x4066
callq 0x1060
leaq 0x8(%rsp), %r12
movl $0x2, 0x2c(%r12)
callq 0x1090
movq %rax, %r15
movq %r12, %rdi
callq 0x2020
movl $0x1, %eax
cmpq $0x10000, %rax          # imm = 0x10000
je 0x15ed
movl -0x4(%rbx,%rax,4), %ecx
leaq 0x1(%rax), %rdx
cmpl (%rbx,%rax,4), %ecx
movq %rdx, %rax
jle 0x15c7
leaq 0x2b26(%rip), %rdi      # 0x410c
callq 0x1060
jmp 0x160e
callq 0x1090
subl %r15d, %eax
imulq $0x10624dd3, %rax, %rsi # imm = 0x10624DD3
shrq $0x26, %rsi
leaq 0x2a34(%rip), %rdi      # 0x403b
xorl %eax, %eax
callq 0x10b0
movl $0xa, %edi
callq 0x1040
movl $0x40000, %edx          # imm = 0x40000
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1120
leaq 0x2a4c(%rip), %rdi      # 0x407b
callq 0x1060
leaq 0x8(%rsp), %r12
movl $0x3, 0x2c(%r12)
callq 0x1090
movq %rax, %r15
movq %r12, %rdi
callq 0x2020
movl $0x1, %eax
cmpq $0x10000, %rax          # imm = 0x10000
je 0x167d
movl -0x4(%rbx,%rax,4), %ecx
leaq 0x1(%rax), %rdx
cmpl (%rbx,%rax,4), %ecx
movq %rdx, %rax
jle 0x1657
leaq 0x2a96(%rip), %rdi      # 0x410c
callq 0x1060
jmp 0x169e
callq 0x1090
subl %r15d, %eax
imulq $0x10624dd3, %rax, %rsi # imm = 0x10624DD3
shrq $0x26, %rsi
leaq 0x29a4(%rip), %rdi      # 0x403b
xorl %eax, %eax
callq 0x10b0
movl $0xa, %edi
callq 0x1040
leaq 0x29ea(%rip), %rdi      # 0x4099
callq 0x1060
leaq 0x8(%rsp), %r12
movl $0x3, 0x2c(%r12)
callq 0x1090
movq %rax, %r15
movq %r12, %rdi
callq 0x2020
movl $0x1, %eax
cmpq $0x10000, %rax          # imm = 0x10000
je 0x16fd
movl -0x4(%rbx,%rax,4), %ecx
leaq 0x1(%rax), %rdx
cmpl (%rbx,%rax,4), %ecx
movq %rdx, %rax
jle 0x16d7
leaq 0x2a16(%rip), %rdi      # 0x410c
callq 0x1060
jmp 0x171e
callq 0x1090
subl %r15d, %eax
imulq $0x10624dd3, %rax, %rsi # imm = 0x10624DD3
shrq $0x26, %rsi
leaq 0x2924(%rip), %rdi      # 0x403b
xorl %eax, %eax
callq 0x10b0
movl $0xa, %edi
callq 0x1040
leaq 0x2988(%rip), %rdi      # 0x40b7
callq 0x1060
xorl %eax, %eax
movdqu (%rbx,%rax,4), %xmm0
psrad $0x1f, %xmm0
por 0x28c8(%rip), %xmm0     # 0x4010
movdqu %xmm0, (%rbx,%rax,4)
addq $0x4, %rax
cmpq $0x10000, %rax          # imm = 0x10000
jne 0x1736
leaq 0x8(%rsp), %r12
movl $0x3, 0x2c(%r12)
callq 0x1090
movq %rax, %r15
movq %r12, %rdi
callq 0x2020
movl $0x1, %eax
cmpq $0x10000, %rax          # imm = 0x10000
je 0x17a2
movl -0x4(%rbx,%rax,4), %ecx
leaq 0x1(%rax), %rdx
cmpl (%rbx,%rax,4), %ecx
movq %rdx, %rax
jle 0x177c
leaq 0x2971(%rip), %rdi      # 0x410c
callq 0x1060
jmp 0x17c3
callq 0x1090
subl %r15d, %eax
imulq $0x10624dd3, %rax, %rsi # imm = 0x10624DD3
shrq $0x26, %rsi
leaq 0x287f(%rip), %rdi      # 0x403b
xorl %eax, %eax
callq 0x10b0
movl $0xa, %edi
callq 0x1040
leaq 0x2904(%rip), %rdi      # 0x40d8
callq 0x1060
xorl %eax, %eax
movaps 0x282e(%rip), %xmm0     # 0x4010
movups %xmm0, (%rbx,%rax,4)
addq $0x4, %rax
cmpq $0x10000, %rax          # imm = 0x10000
jne 0x17e2
leaq 0x8(%rsp), %r12
movl $0x3, 0x2c(%r12)
callq 0x1090
movq %rax, %r15
movq %r12, %rdi
callq 0x2020
movl $0x1, %eax
cmpq $0x10000, %rax          # imm = 0x10000
je 0x183b
movl -0x4(%rbx,%rax,4), %ecx
leaq 0x1(%rax), %rdx
cmpl (%rbx,%rax,4), %ecx
movq %rdx, %rax
jle 0x1815
leaq 0x28d8(%rip), %rdi      # 0x410c
callq 0x1060
jmp 0x185c
callq 0x1090
subl %r15d, %eax
imulq $0x10624dd3, %rax, %rsi # imm = 0x10624DD3
shrq $0x26, %rsi
leaq 0x27e6(%rip), %rdi      # 0x403b
xorl %eax, %eax
callq 0x10b0
movl $0xa, %edi
callq 0x1040
movl $0x40000, %edx          # imm = 0x40000
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1120
leaq 0x2878(%rip), %rdi      # 0x40f5
callq 0x1060
leaq 0x8(%rsp), %r12
movl $0x0, 0x2c(%r12)
callq 0x1090
movq %rax, %r15
movq %r12, %rdi
callq 0x2020
movl $0x1, %eax
cmpq $0x10000, %rax          # imm = 0x10000
je 0x18cb
movl -0x4(%rbx,%rax,4), %ecx
leaq 0x1(%rax), %rdx
cmpl (%rbx,%rax,4), %ecx
movq %rdx, %rax
jle 0x18a5
leaq 0x2848(%rip), %rdi      # 0x410c
callq 0x1060
jmp 0x18ec
callq 0x1090
subl %r15d, %eax
imulq $0x10624dd3, %rax, %rsi # imm = 0x10624DD3
shrq $0x26, %rsi
leaq 0x2756(%rip), %rdi      # 0x403b
xorl %eax, %eax
callq 0x10b0
movl $0xa, %edi
callq 0x1040
movq %rbx, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq