// File: /workspace/github_c_makefile_star2_O3/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 0x22d7(%rip), %rsi      # 0xc8a2
callq 0x23b0
testq %rax, %rax
je 0xa61f
movq %rax, %r14
leaq 0x20(%rsp), %rdi
movl $0xb, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x20b0
testq %rax, %rax
je 0xab19
movb $0x0, 0x2b(%rsp)
movl $0x6c676145, %eax       # imm = 0x6C676145
xorl 0x20(%rsp), %eax
movl $0x514d656c, %ecx       # imm = 0x514D656C
xorl 0x23(%rsp), %ecx
orl %eax, %ecx
je 0xa641
leaq 0x224f(%rip), %rdi      # 0xc869
jmp 0xab12
callq 0x2050
movl (%rax), %edi
callq 0x2470
leaq 0x214e(%rip), %rdi      # 0xc780
movq %rax, %rsi
xorl %eax, %eax
callq 0x4bc8
jmp 0xab32
leaq 0x27(%rsp), %rdi
callq 0x2410
cmpl $0x1, %eax
jne 0xab0b
leaq 0x20(%rsp), %r13
leaq 0xd0(%rsp), %r15
movq %rbx, 0x10(%rsp)
movl $0x1, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %r14, %rcx
callq 0x20b0
cmpq $0x1, %rax
movl $0x0, %eax
sbbl %eax, %eax
movzbl 0x20(%rsp), %ecx
orl %ecx, %eax
leal -0x1(%rax), %ecx
cmpl $0x5, %ecx
ja 0xab53
leaq 0x20c8(%rip), %rdx      # 0xc768
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq %r14, %rdi
movq %r13, %rsi
movl $0x20, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab19
movq %r14, %rdi
leaq 0x40(%rsp), %rsi
movl $0x20, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab19
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
movl $0x8, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab19
leaq 0x7b91(%rip), %rax      # 0x12290
movq (%rax), %rax
movq 0x168(%rax), %r15
movq 0x60(%rsp), %rdx
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
callq 0x9130
movq %r15, %rdi
leaq 0xd0(%rsp), %r15
jmp 0xa779
movq %r14, %rdi
movq %r13, %rsi
movl $0x40, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab19
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
movl $0x4, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab19
movl 0x60(%rsp), %esi
movq %r13, %rdi
callq 0x9f58
leaq 0x7b21(%rip), %rcx      # 0x12290
movq (%rcx), %rcx
movq 0x180(%rcx), %rdi
movq %rax, %rsi
callq 0x8d1a
jmp 0xa666
movq %r14, %rdi
movq %r13, %rsi
movl $0x40, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab19
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
movl $0x4, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab19
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
movl $0x4, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab19
movl 0x60(%rsp), %esi
movq %r13, %rdi
callq 0x9b98
movq %rax, %rbp
cmpl $0x0, 0x8(%rsp)
je 0xa8d0
xorl %ebx, %ebx
movl $0x1, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x20b0
testq %rax, %rax
je 0xab49
cmpb $0x5, 0xd0(%rsp)
jne 0xab49
movq %r14, %rdi
leaq 0xb0(%rsp), %rsi
movl $0x20, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab49
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
movl $0x4, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab49
cmpl $0x0, 0xc(%rsp)
je 0xa8bc
xorl %r15d, %r15d
movq %r14, %rdi
leaq 0xd0(%rsp), %r12
movq %r12, %rsi
movl $0x40, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab49
leaq 0x7a08(%rip), %rax      # 0x12290
movq (%rax), %rax
movq 0x170(%rax), %rdi
movq %r12, %rsi
callq 0x97ae
testq %rax, %rax
je 0xa8b2
movq %rbp, %rdi
movq %rax, %rsi
leaq 0xb0(%rsp), %rdx
callq 0x9d7e
incl %r15d
cmpl 0xc(%rsp), %r15d
jb 0xa860
incl %ebx
cmpl 0x8(%rsp), %ebx
leaq 0xd0(%rsp), %r15
jb 0xa7f1
leaq 0x79b9(%rip), %rax      # 0x12290
movq (%rax), %rax
movq 0x178(%rax), %rdi
movq %rbp, %rsi
jmp 0xaafc
movq %r14, %rdi
movq %r13, %rsi
movl $0x40, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab19
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
movl $0x4, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab19
movq %r14, %rdi
leaq 0x64(%rsp), %rsi
movl $0x4, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab19
movq %r14, %rdi
leaq 0x68(%rsp), %rsi
movl $0x4, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab19
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
movl $0x4, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab19
movl 0x60(%rsp), %esi
movl 0x64(%rsp), %edx
movl 0x68(%rsp), %ecx
movq %r13, %rdi
callq 0x92a4
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x8(%rsp)
je 0xaae6
xorl %ebx, %ebx
movl $0x1, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x20b0
testq %rax, %rax
je 0xab71
cmpb $0x3, 0xd0(%rsp)
jne 0xab71
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
movl $0x4, %edx
callq 0xb2ad
cmpl $-0x1, %eax
je 0xab71
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x20b0
testq %rax, %rax
je 0xab71
movl $0x4, %esi
movl $0x1, %edx
leaq 0xb0(%rsp), %rdi
movq %r14, %rcx
callq 0x20b0
testq %rax, %rax
je 0xab71
movl 0xd0(%rsp), %r15d
movl 0xb0(%rsp), %ebp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rbp
sete %r12b
movq %rbp, %rdi
callq 0x4770
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
movq %r14, %rcx
callq 0x20b0
testq %rax, %rax
sete %al
orb %r12b, %al
testq %r15, %r15
je 0xaaa0
testb %al, %al
jne 0xab69
movq %r15, %rdi
callq 0x4770
movq %rax, %r12
movq %r13, %rdi
movl %ebp, %esi
movq %rax, %rdx
movl %r15d, %ecx
callq 0xb8b8
movl %eax, %ebp
movq %r13, %rdi
callq 0x4997
testl %ebp, %ebp
je 0xab66
movq %r12, %rdi
movq %r15, %rsi
jmp 0xaaae
testb %al, %al
jne 0xab69
movq %r13, %rdi
movq %rbp, %rsi
callq 0x54dc
testq %rax, %rax
leaq 0x20(%rsp), %r13
leaq 0xd0(%rsp), %r15
je 0xab71
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x956a
incl %ebx
cmpl 0x8(%rsp), %ebx
jb 0xa994
leaq 0x77a3(%rip), %rax      # 0x12290
movq (%rax), %rax
movq 0x170(%rax), %rdi
movq 0x18(%rsp), %rsi
callq 0x8d1a
movq 0x10(%rsp), %rbx
jmp 0xa666
leaq 0x1d6d(%rip), %rdi      # 0xc87f
xorl %eax, %eax
callq 0x4bc8
movq %r14, %rdi
callq 0x2120
leaq 0x1c7f(%rip), %rdi      # 0xc7a7
movq %rbx, %rsi
xorl %eax, %eax
callq 0x4dc6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %rdi
callq 0x9c34
jmp 0xab7b
cmpl $0xff, %eax
jne 0xab19
movq %r14, %rdi
callq 0x2120
xorl %eax, %eax
jmp 0xab37
movq %r12, %r13
movq %r13, %rdi
callq 0x4997
movq 0x18(%rsp), %rdi
callq 0x93b5
movq 0x10(%rsp), %rbx
jmp 0xab19