// File: /workspace/github_c_makefile_star2_O2/yakushstanislav[P]EagleMQ/src/storage.c
// Function: storage_load
int storage_load(const char *filename)
{
	FILE *fp;
	int type;
	int state = 1;

	fp = fopen(filename, "r");
	if (!fp) {
		warning("Failed opening storage for loading: %s",  strerror(errno));
		return EG_STATUS_ERR;
	}

	if (storage_read_magic(fp) != EG_STATUS_OK)
		goto error;

	while (state)
	{
		if ((type = storage_read_type(fp)) == -1)
			goto error;

		switch (type)
		{
			case EG_STORAGE_TYPE_USER:
				if (storage_load_user(fp) != EG_STATUS_OK) goto error;
				break;

			case EG_STORAGE_TYPE_QUEUE:
				if (storage_load_queue(fp) != EG_STATUS_OK) goto error;
				break;

			case EG_STORAGE_TYPE_ROUTE:
				if (storage_load_route(fp) != EG_STATUS_OK) goto error;
				break;

			case EG_STORAGE_TYPE_CHANNEL:
				if (storage_load_channel(fp) != EG_STATUS_OK) goto error;
				break;

			case EG_STORAGE_EOF:
				state = 0;
				break;

			default:
				goto error;
		}
	}

	fclose(fp);

	return EG_STATUS_OK;

error:
	fclose(fp);

	fatal("Error read storage %s", filename);

	return EG_STATUS_ERR;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, %rbx
leaq 0x30ab(%rip), %rsi      # 0xc862
callq 0x23c0
testq %rax, %rax
je 0x9805
movq %rax, %r14
leaq 0x20(%rsp), %rsi
pushq $0xb
popq %rdx
movq %rax, %rdi
callq 0xa332
cmpl $-0x1, %eax
je 0x9c78
leaq 0x20(%rsp), %rdi
movb $0x0, 0xb(%rdi)
leaq 0x3034(%rip), %rsi      # 0xc821
pushq $0x7
popq %rdx
callq 0x2320
testl %eax, %eax
je 0x9827
leaq 0x3029(%rip), %rdi      # 0xc829
jmp 0x9c71
callq 0x2050
movl (%rax), %edi
callq 0x2480
leaq 0x2f28(%rip), %rdi      # 0xc740
movq %rax, %rsi
xorl %eax, %eax
callq 0x4548
jmp 0x9c91
leaq 0x27(%rsp), %rdi
callq 0x2420
cmpl $0x1, %eax
jne 0x9c6a
leaq 0x20(%rsp), %r13
pushq $0x4
popq %r12
leaq 0xd0(%rsp), %r15
pushq $0x4
popq %rbp
movq %r14, %rdi
callq 0x9cda
leal -0x1(%rax), %ecx
cmpl $0x5, %ecx
ja 0x9cc7
leaq 0x2ebf(%rip), %rdx      # 0xc728
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq %r14, %rdi
movq %r13, %rsi
pushq $0x20
popq %rdx
callq 0xa355
cmpl $-0x1, %eax
je 0x9c78
movq %r14, %rdi
leaq 0x40(%rsp), %rsi
pushq $0x20
popq %rdx
callq 0xa355
cmpl $-0x1, %eax
je 0x9c78
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0xa355
cmpl $-0x1, %eax
je 0x9c78
leaq 0x89ce(%rip), %rax      # 0x12290
movq (%rax), %rax
movq 0x168(%rax), %r15
movq 0x60(%rsp), %rdx
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
callq 0x845c
movq %r15, %rdi
leaq 0xd0(%rsp), %r15
jmp 0x9938
movq %r14, %rdi
movq %r13, %rsi
pushq $0x40
popq %rdx
callq 0xa355
cmpl $-0x1, %eax
je 0x9c78
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
movl %r12d, %edx
callq 0xa355
cmpl $-0x1, %eax
je 0x9c78
movl 0x60(%rsp), %esi
movq %r13, %rdi
callq 0x918c
leaq 0x8962(%rip), %rcx      # 0x12290
movq (%rcx), %rcx
movq 0x180(%rcx), %rdi
movq %rax, %rsi
callq 0x8096
jmp 0x984e
movq %r14, %rdi
movq %r13, %rsi
pushq $0x40
popq %rdx
callq 0xa355
cmpl $-0x1, %eax
je 0x9c78
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
movl %r12d, %edx
callq 0xa355
cmpl $-0x1, %eax
je 0x9c78
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
movl %r12d, %edx
callq 0xa355
cmpl $-0x1, %eax
je 0x9c78
movl 0x60(%rsp), %esi
movq %r13, %rdi
callq 0x8e04
movq %rax, %rbp
xorl %r13d, %r13d
cmpl 0x8(%rsp), %r13d
jae 0x9c3c
movq %r14, %rdi
callq 0x9cda
cmpl $0x5, %eax
jne 0x9ca6
movq %r14, %rdi
leaq 0xb0(%rsp), %rsi
pushq $0x20
popq %rdx
callq 0xa355
cmpl $-0x1, %eax
je 0x9ca6
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
movl %r12d, %edx
callq 0xa355
cmpl $-0x1, %eax
je 0x9ca6
xorl %r12d, %r12d
cmpl 0xc(%rsp), %r12d
jae 0x9a50
movq %r14, %rdi
leaq 0xd0(%rsp), %r15
movq %r15, %rsi
pushq $0x40
popq %rdx
callq 0xa355
cmpl $-0x1, %eax
je 0x9ca6
leaq 0x886f(%rip), %rax      # 0x12290
movq (%rax), %rax
movq 0x170(%rax), %rdi
movq %r15, %rsi
callq 0x8a49
testq %rax, %rax
je 0x9a4b
movq %rbp, %rdi
movq %rax, %rsi
leaq 0xb0(%rsp), %rdx
callq 0x8fc4
incl %r12d
jmp 0x99f4
incl %r13d
pushq $0x4
popq %r12
jmp 0x99a0
movq %r14, %rdi
movq %r13, %rsi
pushq $0x40
popq %rdx
callq 0xa355
cmpl $-0x1, %eax
je 0x9c78
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
movl %r12d, %edx
callq 0xa355
cmpl $-0x1, %eax
je 0x9c78
movq %r14, %rdi
leaq 0x64(%rsp), %rsi
movl %r12d, %edx
callq 0xa355
cmpl $-0x1, %eax
je 0x9c78
movq %r14, %rdi
leaq 0x68(%rsp), %rsi
movl %r12d, %edx
callq 0xa355
cmpl $-0x1, %eax
je 0x9c78
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
movl %r12d, %edx
callq 0xa355
cmpl $-0x1, %eax
je 0x9c78
movl 0x60(%rsp), %esi
movl 0x64(%rsp), %edx
movl 0x68(%rsp), %ecx
movq %r13, %rdi
callq 0x85a8
movq %rax, 0x10(%rsp)
xorl %eax, %eax
cmpl 0x8(%rsp), %eax
jae 0x9c1c
movl %eax, 0x1c(%rsp)
movq %r14, %rdi
callq 0x9cda
cmpl $0x3, %eax
jne 0x9cbb
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
movl %r12d, %edx
callq 0xa355
cmpl $-0x1, %eax
je 0x9cbb
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0xa332
cmpl $-0x1, %eax
je 0x9cbb
movq %r14, %rdi
leaq 0xb0(%rsp), %rsi
movq %rbp, %rdx
callq 0xa332
cmpl $-0x1, %eax
je 0x9cbb
movl 0xd0(%rsp), %ebp
movl 0xb0(%rsp), %r13d
movq %r13, %rdi
callq 0x40f8
movq %rax, %r12
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0xa332
testq %rbp, %rbp
je 0x9bd7
cmpl $-0x1, %eax
je 0x9cb3
movq %rbp, %rdi
callq 0x40f8
movq %rax, %r15
movq %r12, %rdi
movl %r13d, %esi
movq %rax, %rdx
movl %ebp, %ecx
callq 0xad14
movl %eax, %r13d
movq %r12, %rdi
callq 0x430e
testl %r13d, %r13d
je 0x9cb0
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4e1c
leaq 0xd0(%rsp), %r15
jmp 0x9beb
cmpl $-0x1, %eax
je 0x9cb3
movq %r12, %rdi
movq %r13, %rsi
callq 0x4e1c
testq %rax, %rax
leaq 0x20(%rsp), %r13
pushq $0x4
popq %r12
pushq $0x4
popq %rbp
je 0x9cbb
movl 0xc(%rsp), %edx
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x8816
movl 0x1c(%rsp), %eax
incl %eax
jmp 0x9af2
leaq 0x866d(%rip), %rax      # 0x12290
movq (%rax), %rax
movq 0x170(%rax), %rdi
movq 0x10(%rsp), %rsi
callq 0x8096
jmp 0x984e
leaq 0x864d(%rip), %rax      # 0x12290
movq (%rax), %rax
movq 0x178(%rax), %rdi
movq %rbp, %rsi
callq 0x8096
leaq 0xd0(%rsp), %r15
pushq $0x4
popq %rbp
leaq 0x20(%rsp), %r13
jmp 0x984e
leaq 0x2bce(%rip), %rdi      # 0xc83f
xorl %eax, %eax
callq 0x4548
movq %r14, %rdi
callq 0x2120
leaq 0x2ae0(%rip), %rdi      # 0xc767
movq %rbx, %rsi
xorl %eax, %eax
callq 0x4741
pushq $-0x1
popq %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %rdi
callq 0x8e9b
jmp 0x9c78
movq %r15, %r12
movq %r12, %rdi
callq 0x430e
movq 0x10(%rsp), %rdi
callq 0x86b3
jmp 0x9c78
cmpl $0xff, %eax
jne 0x9c78
movq %r14, %rdi
callq 0x2120
xorl %eax, %eax
jmp 0x9c94