// File: /workspace/github_c_makefile_star2_O0/darkautism[P]lfqueue/test_multithread.c
// Function: main
int main() {
	struct lfq_ctx ctx;
	int i = 0;
	lfq_init(&ctx, MAX_CONSUMER);
	THREAD_TOKEN thread_d[MAX_CONSUMER];
	THREAD_TOKEN thread_a[MAX_PRODUCER];
	
	ATOMIC_ADD(&cn_producer, 1);
	for ( i = 0 ; i < MAX_CONSUMER ; i++ ) {
#if defined __GNUC__ || defined __CYGWIN__ || defined __MINGW32__
		pthread_create(&thread_d[i], NULL, delq, (void*)&ctx);
#else
#pragma warning(disable:4133)
		thread_d[i] = CreateThread(NULL, 0, delq, &ctx, 0, 0);
#endif
	}
	
	for ( i = 0 ; i < MAX_PRODUCER ; i++ ){
		ATOMIC_ADD(&cn_producer, 1);
#if defined __GNUC__ || defined __CYGWIN__ || defined __MINGW32__
		pthread_create(&thread_a[i], NULL, addq, (void*)&ctx);
#else
#pragma warning(disable:4133)
		thread_a[i] = CreateThread(NULL, 0, addq, &ctx, 0, 0);
#endif
		
	}
	
	ATOMIC_SUB(&cn_producer, 1);
	
	for (i = 0; i < MAX_PRODUCER; i++)
		THREAD_WAIT(thread_a[i]);
	
	for ( i = 0 ; i < MAX_CONSUMER ; i++ )
		THREAD_WAIT(thread_d[i]);

	long freecount = lfg_count_freelist(&ctx);
	int clean = lfq_clean(&ctx);

	printf("Total push %"PRId64" elements, pop %"PRId64" elements. freelist=%ld, clean = %d\n", cn_added, cn_deled, freecount, clean);
	if ( cn_added == cn_deled )
		printf("Test PASS!!\n");
	else
		printf("Test Failed!!\n");

	return (cn_added != cn_deled);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
andq $-0x40, %rsp
subq $0x480, %rsp            # imm = 0x480
movl $0x0, 0x46c(%rsp)
movl $0x0, 0x3bc(%rsp)
leaq 0x3c0(%rsp), %rdi
movl $0x64, %esi
callq 0x15d0
lock
incl 0x2ca6(%rip)            # 0x40a4
movl $0x0, 0x3bc(%rsp)
cmpl $0x64, 0x3bc(%rsp)
jge 0x1455
movslq 0x3bc(%rsp), %rax
leaq 0x90(%rsp), %rdi
shlq $0x3, %rax
addq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x155(%rip), %rdx      # 0x12e0
leaq 0x3c0(%rsp), %rcx
callq 0x10a0
movl 0x3bc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3bc(%rsp)
jmp 0x1409
movl $0x0, 0x3bc(%rsp)
cmpl $0xa, 0x3bc(%rsp)
jge 0x14b0
lock
incl 0x2c33(%rip)            # 0x40a4
movslq 0x3bc(%rsp), %rax
leaq 0x40(%rsp), %rdi
shlq $0x3, %rax
addq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x2a0(%rip), %rdx      # 0x11f0
leaq 0x3c0(%rsp), %rcx
callq 0x10a0
movl 0x3bc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3bc(%rsp)
jmp 0x1460
lock
decl 0x2bed(%rip)            # 0x40a4
movl $0x0, 0x3bc(%rsp)
cmpl $0xa, 0x3bc(%rsp)
jge 0x14f5
movslq 0x3bc(%rsp), %rax
movq 0x40(%rsp,%rax,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10d0
movl 0x3bc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3bc(%rsp)
jmp 0x14c2
movl $0x0, 0x3bc(%rsp)
cmpl $0x64, 0x3bc(%rsp)
jge 0x1536
movslq 0x3bc(%rsp), %rax
movq 0x90(%rsp,%rax,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10d0
movl 0x3bc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3bc(%rsp)
jmp 0x1500
leaq 0x3c0(%rsp), %rdi
callq 0x16e0
movq %rax, 0x38(%rsp)
leaq 0x3c0(%rsp), %rdi
callq 0x1730
movl %eax, 0x34(%rsp)
movq 0x2b30(%rip), %rsi      # 0x4090
movq 0x2b31(%rip), %rdx      # 0x4098
movq 0x38(%rsp), %rcx
movl 0x34(%rsp), %r8d
leaq 0xb0d(%rip), %rdi       # 0x2085
movb $0x0, %al
callq 0x1050
movq 0x2b0a(%rip), %rax      # 0x4090
movq 0x2b0b(%rip), %rcx      # 0x4098
cmpq %rcx, %rax
jne 0x15a2
leaq 0xb31(%rip), %rdi       # 0x20ca
movb $0x0, %al
callq 0x1050
jmp 0x15b0
leaq 0xb2e(%rip), %rdi       # 0x20d7
movb $0x0, %al
callq 0x1050
movq 0x2ad9(%rip), %rax      # 0x4090
movq 0x2ada(%rip), %rcx      # 0x4098
cmpq %rcx, %rax
setne %al
andb $0x1, %al
movzbl %al, %eax
movq %rbp, %rsp
popq %rbp
retq
nop