// File: /workspace/github_cpp_makefile_star2_O2/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 0x15a0(%rip), %rdi      # 0x4e55
leaq 0x15a4(%rip), %rsi      # 0x4e60
callq 0x1100
movq %rax, %rbx
leaq -0x38(%rbp), %r15
andq $0x0, (%r15)
movq %r15, %rdi
callq 0x10d0
movq %r15, %rdi
callq 0x10a0
movq %rax, %rdi
callq 0x1060
leaq 0x1577(%rip), %rsi      # 0x4e62
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1150
testq %r14, %r14
je 0x3925
movl 0x28(%r14), %eax
cmpq $0xf, %rax
ja 0x397f
leaq 0x148e(%rip), %rcx      # 0x4d9c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x173e(%rip), %rdi      # 0x505c
pushq $0x19
jmp 0x39de
leaq 0x153a(%rip), %rdi      # 0x4e66
pushq $0x32
popq %rsi
pushq $0x1
popq %rdx
jmp 0x3a5c
leaq 0x18d6(%rip), %rdi      # 0x5214
pushq $0x3b
jmp 0x39de
leaq 0x1667(%rip), %rdi      # 0x4fb3
pushq $0x48
jmp 0x392e
leaq 0x1874(%rip), %rdi      # 0x51cb
pushq $0x48
jmp 0x39de
leaq 0x1534(%rip), %rdi      # 0x4e99
pushq $0x41
jmp 0x392e
leaq 0x1788(%rip), %rdi      # 0x50f8
pushq $0x47
jmp 0x39de
leaq 0x1681(%rip), %rdi      # 0x4ffc
pushq $0x5f
jmp 0x392e
leaq 0x1907(%rip), %rdi      # 0x528d
pushq $0x1d
jmp 0x39de
leaq 0x15ec(%rip), %rdi      # 0x4f7d
pushq $0x35
jmp 0x392e
leaq 0x153f(%rip), %rdi      # 0x4edb
pushq $0x51
jmp 0x392e
leaq 0x1586(%rip), %rdi      # 0x4f2d
pushq $0x4f
jmp 0x392e
leaq 0x189e(%rip), %rdi      # 0x5250
pushq $0x3c
jmp 0x39de
leaq 0x16b9(%rip), %rdi      # 0x5076
jmp 0x39c6
leaq 0x16f1(%rip), %rdi      # 0x50b7
pushq $0x40
jmp 0x39de
leaq 0x17b6(%rip), %rdi      # 0x5187
pushq $0x43
jmp 0x39de
leaq 0x1764(%rip), %rdi      # 0x5140
pushq $0x46
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x1190
movq 0x10(%r14), %rdx
movq 0x18(%r14), %rcx
movq 0x20(%r14), %r8
leaq 0x18ae(%rip), %rsi      # 0x52ab
movq %rbx, -0x30(%rbp)
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1150
leaq 0xc3e(%rip), %r12       # 0x4650
leaq 0x18c8(%rip), %r15      # 0x52e1
xorl %r13d, %r13d
xorl %ebx, %ebx
jmp 0x3a45
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 0x3a20
leaq 0x151d(%rip), %rdi      # 0x4f6f
pushq $0xd
popq %rsi
pushq $0x1
popq %rdx
movq -0x30(%rbp), %rbx
movq %rbx, %rcx
callq 0x1190
movq %rbx, %rdi
callq 0x10e0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq