// File: 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
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
leaq 0x237e(%rip), %rdi      # 0x6f41
leaq 0x2382(%rip), %rsi      # 0x6f4c
callq 0x1100
movq %rax, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x10d0
leaq -0x20(%rbp), %rdi
callq 0x10a0
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1060
movq -0x30(%rbp), %rdi
movq %rax, %rdx
leaq 0x2336(%rip), %rsi      # 0x6f4e
movb $0x0, %al
callq 0x1140
cmpq $0x0, -0x8(%rbp)
jne 0x4c46
movq -0x10(%rbp), %rdi
leaq 0x2321(%rip), %rsi      # 0x6f52
movb $0x0, %al
callq 0x1140
movq -0x10(%rbp), %rdi
callq 0x10e0
jmp 0x4ed2
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
movq %rax, -0x38(%rbp)
subq $0xf, %rax
ja 0x4dec
movq -0x38(%rbp), %rax
leaq 0x21f2(%rip), %rcx      # 0x6e58
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rdi
leaq 0x230b(%rip), %rsi      # 0x6f85
movb $0x0, %al
callq 0x1140
movq -0x10(%rbp), %rdi
callq 0x10e0
jmp 0x4ed2
movq -0x10(%rbp), %rdi
leaq 0x232d(%rip), %rsi      # 0x6fc7
movb $0x0, %al
callq 0x1140
movq -0x10(%rbp), %rdi
callq 0x10e0
jmp 0x4ed2
movq -0x10(%rbp), %rdi
leaq 0x235f(%rip), %rsi      # 0x7019
movb $0x0, %al
callq 0x1140
movq -0x10(%rbp), %rdi
callq 0x10e0
jmp 0x4ed2
movq -0x10(%rbp), %rdi
leaq 0x238f(%rip), %rsi      # 0x7069
movb $0x0, %al
callq 0x1140
movq -0x10(%rbp), %rdi
callq 0x10e0
jmp 0x4ed2
movq -0x10(%rbp), %rdi
leaq 0x23a5(%rip), %rsi      # 0x709f
movb $0x0, %al
callq 0x1140
movq -0x10(%rbp), %rdi
callq 0x10e0
jmp 0x4ed2
movq -0x10(%rbp), %rdi
leaq 0x23ce(%rip), %rsi      # 0x70e8
movb $0x0, %al
callq 0x1140
movq -0x10(%rbp), %rdi
callq 0x10e0
jmp 0x4ed2
movq -0x10(%rbp), %rdi
leaq 0x240e(%rip), %rsi      # 0x7148
movb $0x0, %al
callq 0x1140
jmp 0x4dfe
movq -0x10(%rbp), %rdi
leaq 0x2411(%rip), %rsi      # 0x7162
movb $0x0, %al
callq 0x1140
jmp 0x4dfe
movq -0x10(%rbp), %rdi
leaq 0x243b(%rip), %rsi      # 0x71a3
movb $0x0, %al
callq 0x1140
jmp 0x4dfe
movq -0x10(%rbp), %rdi
leaq 0x2465(%rip), %rsi      # 0x71e4
movb $0x0, %al
callq 0x1140
jmp 0x4dfe
movq -0x10(%rbp), %rdi
leaq 0x2499(%rip), %rsi      # 0x722c
movb $0x0, %al
callq 0x1140
jmp 0x4dfe
movq -0x10(%rbp), %rdi
leaq 0x24cc(%rip), %rsi      # 0x7273
movb $0x0, %al
callq 0x1140
jmp 0x4dfe
movq -0x10(%rbp), %rdi
leaq 0x24fc(%rip), %rsi      # 0x72b7
movb $0x0, %al
callq 0x1140
jmp 0x4dfe
movq -0x10(%rbp), %rdi
leaq 0x2531(%rip), %rsi      # 0x7300
movb $0x0, %al
callq 0x1140
jmp 0x4dfe
movq -0x10(%rbp), %rdi
leaq 0x2559(%rip), %rsi      # 0x733c
movb $0x0, %al
callq 0x1140
jmp 0x4dfe
movq -0x10(%rbp), %rdi
leaq 0x2582(%rip), %rsi      # 0x7379
movb $0x0, %al
callq 0x1140
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x20(%rax), %r8
leaq 0x2576(%rip), %rsi      # 0x7397
movb $0x0, %al
callq 0x1140
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x4eb7
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
imulq $0x30, -0x28(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
imulq $0x30, -0x28(%rbp), %rcx
addq %rcx, %rax
cmpq $0x0, 0x18(%rax)
je 0x4e84
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
imulq $0x30, -0x28(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x4e91
leaq 0x19b4(%rip), %rax      # 0x683f
movq %rax, -0x48(%rbp)
jmp 0x4e91
movl -0x3c(%rbp), %esi
movq -0x48(%rbp), %rdx
leaq 0x252e(%rip), %rdi      # 0x73cd
movb $0x0, %al
callq 0x1040
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x4e30
movq -0x10(%rbp), %rdi
leaq 0x2199(%rip), %rsi      # 0x705b
movb $0x0, %al
callq 0x1140
movq -0x10(%rbp), %rdi
callq 0x10e0
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)