// File: /workspace/github_c_makefile_star2_O0/Enes1313[P]DataStructures/DS/eaDSCircularBuffer.c
// Function: eaDSCircularBufferAdd
int eaDSCircularBufferAdd(eaDSCircularBuffer circularBuffer, const void * data, size_t len)
{
	if (circularBuffer->Stop)
	{
		return EXIT_FAILURE;
	}

	if (circularBuffer->Tail >= circularBuffer->Head)
	{
		if (len <= (circularBuffer->Capacity - circularBuffer->Tail))
		{
			circularBuffer->dataCopy((char *)circularBuffer->Data + circularBuffer->SizeOfData * circularBuffer->Tail, data, circularBuffer->SizeOfData * len);
			circularBuffer->Tail += len;

			if (circularBuffer->Tail == circularBuffer->Capacity)
			{
				circularBuffer->Tail = 0;
			}
		}
		else
		{
			if (len > (circularBuffer->Head + circularBuffer->Capacity - circularBuffer->Tail))
			{
				return EXIT_FAILURE;
			}
			else
			{
				circularBuffer->dataCopy((char *)circularBuffer->Data + circularBuffer->SizeOfData * circularBuffer->Tail, data, circularBuffer->SizeOfData * (circularBuffer->Capacity - circularBuffer->Tail));
				circularBuffer->dataCopy(circularBuffer->Data, (char *)data + circularBuffer->SizeOfData * (circularBuffer->Capacity - circularBuffer->Tail), circularBuffer->SizeOfData * (len - circularBuffer->Capacity + circularBuffer->Tail));
				circularBuffer->Tail = len - circularBuffer->Capacity + circularBuffer->Tail;
			}
		}
	}
	else
	{
		if (len > (circularBuffer->Head - circularBuffer->Tail))
		{
			return EXIT_FAILURE;
		}
		else
		{
			circularBuffer->dataCopy((char *)circularBuffer->Data + circularBuffer->SizeOfData * circularBuffer->Tail, data, circularBuffer->SizeOfData * len);
			circularBuffer->Tail += len;
		}
	}

	if (circularBuffer->Head == circularBuffer->Tail)
	{
		circularBuffer->Stop = 1;
	}

	return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0x139a
movl $0x1, -0x4(%rbp)
jmp 0x15a6
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jb 0x1518
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x10(%rbp), %rdx
subq 0x10(%rdx), %rcx
cmpq %rcx, %rax
ja 0x1432
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rdi
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x10(%rbp), %rdx
imulq 0x10(%rdx), %rcx
addq %rcx, %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rdx
imulq -0x20(%rbp), %rdx
callq *%rax
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jne 0x142d
movq -0x10(%rbp), %rax
movq $0x0, 0x10(%rax)
jmp 0x1516
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x10(%rbp), %rdx
addq 0x18(%rdx), %rcx
movq -0x10(%rbp), %rdx
subq 0x10(%rdx), %rcx
cmpq %rcx, %rax
jbe 0x145f
movl $0x1, -0x4(%rbp)
jmp 0x15a6
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rdi
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x10(%rbp), %rdx
imulq 0x10(%rdx), %rcx
addq %rcx, %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rdx
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x10(%rbp), %r8
subq 0x10(%r8), %rcx
imulq %rcx, %rdx
callq *%rax
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x10(%rbp), %rdx
movq 0x18(%rdx), %rdx
movq -0x10(%rbp), %r8
subq 0x10(%r8), %rdx
imulq %rdx, %rcx
addq %rcx, %rsi
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rdx
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %r8
subq 0x18(%r8), %rcx
movq -0x10(%rbp), %r8
addq 0x10(%r8), %rcx
imulq %rcx, %rdx
callq *%rax
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
subq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
addq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x1516
jmp 0x1582
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x10(%rbp), %rdx
subq 0x10(%rdx), %rcx
cmpq %rcx, %rax
jbe 0x153a
movl $0x1, -0x4(%rbp)
jmp 0x15a6
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rdi
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x10(%rbp), %rdx
imulq 0x10(%rdx), %rcx
addq %rcx, %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rdx
imulq -0x20(%rbp), %rdx
callq *%rax
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
jmp 0x1582
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x159f
movq -0x10(%rbp), %rax
movl $0x1, 0x20(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nop