// File: /workspace/github_c_makefile_star2_O0/stv0g[P]c11-queues/mpmc_test.c
// Function: main
int main()
{
	struct mpmc_queue queue;
	thrd_t threads[thread_count];
	int ret;
	
	mpmc_queue_init(&queue, queue_size, &memtype_heap);

	for (int i = 0; i != thread_count; ++i)
		thrd_create(&threads[i], thread_func, &queue);

	sleep(1);
	
	long long starttime, endtime;
	struct timespec start, end;

	if(clock_gettime(CLOCK_REALTIME, &start))
		return -1;

	g_start = 1;

	for (int i = 0; i != thread_count; ++i)
		thrd_join(threads[i], NULL);

	if(clock_gettime(CLOCK_REALTIME, &end))
		return -1;
	
	starttime = start.tv_sec*1000000000LL + start.tv_nsec;
	endtime = end.tv_sec*1000000000LL + end.tv_nsec;
	printf("cycles/op = %lld\n", (endtime - starttime) / (batch_size * iter_count * 2 * thread_count));
	
	size_t used = mpmc_queue_available(&queue);
	if (used > 0)
		printf("%zu slots in use? There is something wrong with the test\n", used);
	
	ret = mpmc_queue_destroy(&queue);
	if (ret)
		printf("Failed to destroy queue: %d", ret);
	
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movl $0x0, -0x4(%rbp)
movq %rsp, %rax
movq %rax, -0x138(%rbp)
leaq -0x130(%rbp), %rdi
movl $0x100000, %esi         # imm = 0x100000
leaq 0x29f1(%rip), %rdx      # 0x3d80
callq 0x1600
movl $0x0, -0x140(%rbp)
movslq -0x140(%rbp), %rax
cmpq $0x4, %rax
je 0x13e4
movslq -0x140(%rbp), %rax
leaq -0x1a0(%rbp), %rdi
shlq $0x3, %rax
addq %rax, %rdi
leaq -0x1b7(%rip), %rsi      # 0x1210
leaq -0x130(%rbp), %rdx
callq 0x1570
movl -0x140(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x140(%rbp)
jmp 0x139e
movl $0x1, %edi
callq 0x10e0
xorl %edi, %edi
leaq -0x160(%rbp), %rsi
callq 0x1040
cmpl $0x0, %eax
je 0x1417
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x174(%rbp)
jmp 0x1557
movl $0x1, 0x2c73(%rip)      # 0x4094
movl $0x0, -0x178(%rbp)
movslq -0x178(%rbp), %rax
cmpq $0x4, %rax
je 0x1461
movslq -0x178(%rbp), %rax
movq -0x1a0(%rbp,%rax,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x15b0
movl -0x178(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x178(%rbp)
jmp 0x142b
xorl %edi, %edi
leaq -0x170(%rbp), %rsi
callq 0x1040
cmpl $0x0, %eax
je 0x148a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x174(%rbp)
jmp 0x1557
imulq $0x3b9aca00, -0x160(%rbp), %rax # imm = 0x3B9ACA00
addq -0x158(%rbp), %rax
movq %rax, -0x148(%rbp)
imulq $0x3b9aca00, -0x170(%rbp), %rax # imm = 0x3B9ACA00
addq -0x168(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rax
subq -0x148(%rbp), %rax
movl $0x9896800, %ecx        # imm = 0x9896800
xorl %edx, %edx
divq %rcx
movq %rax, %rsi
leaq 0xb4a(%rip), %rdi       # 0x2028
movb $0x0, %al
callq 0x1060
leaq -0x130(%rbp), %rdi
callq 0x1750
movq %rax, -0x180(%rbp)
cmpq $0x0, -0x180(%rbp)
jbe 0x1517
movq -0x180(%rbp), %rsi
leaq 0xb2a(%rip), %rdi       # 0x203a
movb $0x0, %al
callq 0x1060
leaq -0x130(%rbp), %rdi
callq 0x1710
movl %eax, -0x13c(%rbp)
cmpl $0x0, -0x13c(%rbp)
je 0x1546
movl -0x13c(%rbp), %esi
leaq 0xb35(%rip), %rdi       # 0x2074
movb $0x0, %al
callq 0x1060
movl $0x0, -0x4(%rbp)
movl $0x1, -0x174(%rbp)
movq -0x138(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopl (%rax)