// File: /workspace/github_cpp_makefile_star2_O1/AndreyVV-100[P]GachiLang/TreeBase/Stack.cpp
// Function: StackLog(Stack*)
void StackLog(Stack* stk)
{
	FILE* file = fopen ("stklog.txt", "a");

	struct tm* mytime = nullptr;
	time_t alltime = 0;
	time (&alltime);
	mytime = localtime (&alltime);
	fprintf (file, "\n%s", asctime (mytime));

	if (!stk)
	{
		fprintf (file, "Stack [STK_NULL] : The address of stack is null.\n\n");

		fclose (file);

		return;
	}

	switch (stk->status_error)
	{
		case BUF_NULL:
			fprintf(file, "Stack [BUF_NULL] : The address of buffer is nullptr.\n" "End of log.\n");
			fclose(file);
			return;

		case STK_PETREL_B:
			fprintf(file, "Stack [STK_PETREL_B] : The begin stormy petrel in stack was damaged.\n" "End of log.\n");
			fclose(file);
			return;

		case STK_PETREL_E:
			fprintf(file, "Stack [STK_PETREL_E] : The end stormy petrel in stack was damaged.\n" "End of log.\n");
			fclose(file);
			return;

		case STK_DEL:
			fprintf(file, "Stack [STK_DEL] : The stack was deleted.\n" "End of log.\n");
			fclose(file);
			return;

		case DO_MEM_ERR:
			fprintf(file, "Stack [DO_MEM_ERR] : The program can`t pick out new memory.\n" "End of log.\n");
			fclose(file);
			return;

		case NOT_CREATED:
			fprintf(file, "Stack [NOT_CREATED] : Attempt to manipulation with stack which wasn`t constructed.\n" "End of log.\n");
			fclose(file);
			return;

		case STK_GOOD:
			fprintf (file, "Stack [STK_GOOD] : Nice!\n");
			break;

		case BAD_SIZE_CAP:
			fprintf (file, "Stack [BAD_SIZE_CAP] : The size of stack is more then capacity.\n");
			break;

		case BAD_SIZE_ZERO:
			fprintf (file,  "Stack [BAD_SIZE_ZERO] : StackPop was called when size was zero.\n");
			break;

		case BAD_CAP:
			fprintf (file, "Stack [BAD_CAP] : The capacity of stack is less then minimal capacity.\n");
			break;

		case BUF_PETREL_B:
			fprintf (file, "Stack [BUF_PETREL_B] : The begin stormy petrel in buffer was damaged.\n");
			break;

		case BUF_PETREL_E:
			fprintf (file, "Stack [BUF_PETREL_E] : The end stormy petrel in buffer was damaged.");
			break;

		case BAD_CREATE:
			fprintf (file, "Stack [BAD_CREATE] : Trying to construct stack which already not empty.\n");
			break;

		case ERR_HASH_STK:
			fprintf (file, "Stack [ERR_HASH_STK] : Data in stack was changed illegally.");
			break;

		case ERR_HASH_BUF:
			fprintf (file, "Stack [ERR_HASH_BUF] : Data in buffer was changed illegally.");
			break;

		default:
			fprintf (file, "Stack [UNK] : Unknown error.\n");
			break;
	};

	fprintf (file, "size = %lu\n" "capacity = %lu\n" "min_capacity = %lu\n" "buffer:\n", 
			   stk->size,     stk->capacity,     stk->min_capacity);

	/*
	fprintf (file, "begin buffer petrel = %llX\n" "end buffer petrel   = %llX\n",
		*((storm*) (stk->buffer - 1)),
		*((storm*) (stk->buffer + stk->capacity)));
	

	for (int element = 0; element < stk->capacity; element++)
		fprintf (file, "[%d] = %lf\n", element, stk->buffer[element]);
		*/
	for (size_t i_elem = 0; i_elem < stk->size; i_elem++)
		printf ("Type: %d - %s\n", stk->buffer[i_elem].type, (stk->buffer[i_elem].ind) ? stk->buffer[i_elem].ind : "");

	fprintf (file, "\n" "End of log.\n");
	fclose  (file);

	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
leaq 0x2277(%rip), %rdi      # 0x5e6d
leaq 0x227b(%rip), %rsi      # 0x5e78
callq 0x1110
movq %rax, %rbx
leaq -0x38(%rbp), %r15
movq $0x0, (%r15)
movq %r15, %rdi
callq 0x10e0
movq %r15, %rdi
callq 0x10b0
movq %rax, %rdi
callq 0x1060
leaq 0x224b(%rip), %rsi      # 0x5e7a
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1160
testq %r14, %r14
je 0x3c70
movl 0x28(%r14), %eax
cmpq $0xf, %rax
ja 0x3ce3
leaq 0x215e(%rip), %rcx      # 0x5db4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x240e(%rip), %rdi      # 0x6074
movl $0x19, %esi
jmp 0x3d63
leaq 0x2207(%rip), %rdi      # 0x5e7e
movl $0x32, %esi
movl $0x1, %edx
jmp 0x3deb
leaq 0x259f(%rip), %rdi      # 0x622c
movl $0x3b, %esi
jmp 0x3d63
leaq 0x232d(%rip), %rdi      # 0x5fcb
movl $0x48, %esi
jmp 0x3c7c
leaq 0x2537(%rip), %rdi      # 0x61e3
movl $0x48, %esi
jmp 0x3d63
leaq 0x21f4(%rip), %rdi      # 0x5eb1
movl $0x41, %esi
jmp 0x3c7c
leaq 0x2445(%rip), %rdi      # 0x6110
movl $0x47, %esi
jmp 0x3d63
leaq 0x2338(%rip), %rdi      # 0x6014
movl $0x5f, %esi
jmp 0x3c7c
leaq 0x25bb(%rip), %rdi      # 0x62a5
movl $0x1d, %esi
jmp 0x3d63
leaq 0x229d(%rip), %rdi      # 0x5f95
movl $0x35, %esi
jmp 0x3c7c
leaq 0x21ea(%rip), %rdi      # 0x5ef3
movl $0x51, %esi
jmp 0x3c7c
leaq 0x222b(%rip), %rdi      # 0x5f45
movl $0x4f, %esi
jmp 0x3c7c
leaq 0x253d(%rip), %rdi      # 0x6268
movl $0x3c, %esi
jmp 0x3d63
leaq 0x2355(%rip), %rdi      # 0x608e
jmp 0x3d42
leaq 0x238d(%rip), %rdi      # 0x60cf
movl $0x40, %esi
jmp 0x3d63
leaq 0x244f(%rip), %rdi      # 0x619f
movl $0x43, %esi
jmp 0x3d63
leaq 0x23fa(%rip), %rdi      # 0x6158
movl $0x46, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x11a0
movq 0x10(%r14), %rdx
movq 0x18(%r14), %rcx
movq 0x20(%r14), %r8
leaq 0x2540(%rip), %rsi      # 0x62c3
movq %rbx, -0x30(%rbp)
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1160
cmpq $0x0, 0x10(%r14)
je 0x3dd6
leaq 0x18d9(%rip), %r12      # 0x5678
leaq 0x2553(%rip), %r15      # 0x62f9
xorl %r13d, %r13d
xorl %ebx, %ebx
movq 0x8(%r14), %rax
movl (%rax,%r13), %esi
movq 0x18(%rax,%r13), %rdx
testq %rdx, %rdx
cmoveq %r12, %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0x1040
incq %rbx
addq $0x30, %r13
cmpq 0x10(%r14), %rbx
jb 0x3dab
leaq 0x21aa(%rip), %rdi      # 0x5f87
movl $0xd, %esi
movl $0x1, %edx
movq -0x30(%rbp), %rbx
movq %rbx, %rcx
callq 0x11a0
movq %rbx, %rdi
callq 0x10f0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq