// File: /workspace/github_c_makefile_star2_O1/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 0x270f(%rip), %rsi      # 0xc866
callq 0x23c0
testq %rax, %rax
je 0xa1ab
movq %rax, %r14
leaq 0x20(%rsp), %rdi
movl $0xb, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x20c0
testq %rax, %rax
je 0xa6eb
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 0xa1cd
leaq 0x2687(%rip), %rdi      # 0xc82d
jmp 0xa6e4
callq 0x2050
movl (%rax), %edi
callq 0x2480
leaq 0x2586(%rip), %rdi      # 0xc744
movq %rax, %rsi
xorl %eax, %eax
callq 0x4734
jmp 0xa704
leaq 0x27(%rsp), %rdi
callq 0x2420
cmpl $0x1, %eax
jne 0xa6dd
leaq 0x60(%rsp), %r13
leaq 0x20(%rsp), %r12
leaq 0x253b(%rip), %rbp      # 0xc72c
leaq 0xb0(%rsp), %r15
movl $0x1, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r14, %rcx
callq 0x20c0
cmpq $0x1, %rax
movl $0x0, %eax
sbbl %eax, %eax
movzbl 0x20(%rsp), %ecx
orl %ecx, %eax
leal -0x1(%rax), %ecx
cmpl $0x5, %ecx
ja 0xa731
movslq (%rbp,%rcx,4), %rax
addq %rbp, %rax
jmpq *%rax
movq %r14, %rdi
movq %r12, %rsi
movl $0x20, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa6eb
movq %r14, %rdi
leaq 0x40(%rsp), %rsi
movl $0x20, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa6eb
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
movl $0x8, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa6eb
leaq 0x8004(%rip), %rax      # 0x12290
movq (%rax), %rax
movq 0x168(%rax), %r15
movq 0x60(%rsp), %rdx
movq %r12, %rdi
leaq 0x40(%rsp), %rsi
callq 0x8c98
movq %r15, %rdi
leaq 0xb0(%rsp), %r15
jmp 0xa304
movq %r14, %rdi
movq %r12, %rsi
movl $0x40, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa6eb
movq %r14, %rdi
movq %r13, %rsi
movl $0x4, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa6eb
movl 0x60(%rsp), %esi
movq %r12, %rdi
callq 0x9ac8
leaq 0x7f96(%rip), %rcx      # 0x12290
movq (%rcx), %rcx
movq 0x180(%rcx), %rdi
movq %rax, %rsi
callq 0x8886
jmp 0xa1f9
movq %r14, %rdi
movq %r12, %rsi
movl $0x40, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa6eb
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
movl $0x4, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa6eb
movq %r14, %rdi
leaq 0x64(%rsp), %rsi
movl $0x4, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa6eb
movq %r14, %rdi
leaq 0x68(%rsp), %rsi
movl $0x4, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa6eb
movq %r14, %rdi
movq %rsp, %rsi
movl $0x4, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa6eb
movl 0x60(%rsp), %esi
movl 0x64(%rsp), %edx
movl 0x68(%rsp), %ecx
movq %r12, %rdi
callq 0x8e0c
movq %rax, 0x8(%rsp)
cmpl $0x0, (%rsp)
je 0xa54f
xorl %r13d, %r13d
movl $0x1, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x20c0
testq %rax, %rax
je 0xa725
cmpb $0x3, 0xb0(%rsp)
jne 0xa725
movq %r14, %rdi
leaq 0x4(%rsp), %rsi
movl $0x4, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa725
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x20c0
testq %rax, %rax
je 0xa4db
movl $0x4, %esi
movl $0x1, %edx
leaq 0xf0(%rsp), %rdi
movq %r14, %rcx
callq 0x20c0
testq %rax, %rax
je 0xa4db
movl 0xb0(%rsp), %eax
movq %rax, 0x18(%rsp)
movl 0xf0(%rsp), %ebp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rbp
sete %r15b
movq %rbp, %rdi
callq 0x42f0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
movq %r14, %rcx
callq 0x20c0
testq %rax, %rax
sete %al
orb %r15b, %al
movq 0x18(%rsp), %r15
testq %r15, %r15
je 0xa4df
testb %al, %al
jne 0xa4e3
movq %r15, %rdi
callq 0x42f0
movq %r12, %rdi
movl %ebp, %esi
movq %rax, 0x10(%rsp)
movq %rax, %rdx
movl %r15d, %ecx
callq 0xb8a8
movl %eax, %ebp
movq %r12, %rdi
callq 0x44fe
testl %ebp, %ebp
movq %r15, %rsi
leaq 0xb0(%rsp), %r15
je 0xa513
movq 0x10(%rsp), %rdi
callq 0x503c
movq %rax, %rsi
jmp 0xa51f
xorl %esi, %esi
jmp 0xa52b
testb %al, %al
je 0xa4ef
movq %r12, %rdi
callq 0x44fe
xorl %esi, %esi
jmp 0xa4fd
movq %r12, %rdi
movq %rbp, %rsi
callq 0x503c
movq %rax, %rsi
leaq 0x20(%rsp), %r12
leaq 0x2223(%rip), %rbp      # 0xc72c
leaq 0xb0(%rsp), %r15
jmp 0xa52b
movq 0x10(%rsp), %rdi
callq 0x44fe
xorl %esi, %esi
leaq 0x20(%rsp), %r12
leaq 0x2201(%rip), %rbp      # 0xc72c
testq %rsi, %rsi
je 0xa725
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rdi
callq 0x90d2
incl %r13d
cmpl (%rsp), %r13d
jb 0xa3ba
leaq 0x7d3a(%rip), %rax      # 0x12290
movq (%rax), %rax
movq 0x170(%rax), %rdi
movq 0x8(%rsp), %rsi
callq 0x8886
leaq 0x60(%rsp), %r13
jmp 0xa1f9
movq %r14, %rdi
movq %r12, %rsi
movl $0x40, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa6eb
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
movl $0x4, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa6eb
movq %r14, %rdi
movq %rsp, %rsi
movl $0x4, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa6eb
movl 0x60(%rsp), %esi
movq %r12, %rdi
callq 0x9700
movq %rax, %rbp
cmpl $0x0, (%rsp)
je 0xa6bf
xorl %r15d, %r15d
movl $0x1, %esi
movl $0x1, %edx
leaq 0xb0(%rsp), %rdi
movq %r14, %rcx
callq 0x20c0
testq %rax, %rax
je 0xa71b
cmpb $0x5, 0xb0(%rsp)
jne 0xa71b
movq %r14, %rdi
leaq 0xf0(%rsp), %rsi
movl $0x20, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa71b
movq %r14, %rdi
leaq 0x4(%rsp), %rsi
movl $0x4, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa71b
cmpl $0x0, 0x4(%rsp)
je 0xa6ad
xorl %r12d, %r12d
movq %r14, %rdi
leaq 0xb0(%rsp), %r13
movq %r13, %rsi
movl $0x40, %edx
callq 0xae6f
cmpl $-0x1, %eax
je 0xa71b
leaq 0x7c17(%rip), %rax      # 0x12290
movq (%rax), %rax
movq 0x170(%rax), %rdi
movq %r13, %rsi
callq 0x9316
testq %rax, %rax
je 0xa6a3
movq %rbp, %rdi
movq %rax, %rsi
leaq 0xf0(%rsp), %rdx
callq 0x98e6
incl %r12d
cmpl 0x4(%rsp), %r12d
jb 0xa651
incl %r15d
cmpl (%rsp), %r15d
leaq 0x60(%rsp), %r13
jb 0xa5dd
leaq 0x7bca(%rip), %rax      # 0x12290
movq (%rax), %rax
movq 0x178(%rax), %rdi
movq %rbp, %rsi
callq 0x8886
jmp 0xa1e5
leaq 0x215f(%rip), %rdi      # 0xc843
xorl %eax, %eax
callq 0x4734
movq %r14, %rdi
callq 0x2130
leaq 0x2071(%rip), %rdi      # 0xc76b
movq %rbx, %rsi
xorl %eax, %eax
callq 0x4932
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 0x979c
jmp 0xa6eb
movq 0x8(%rsp), %rdi
callq 0x8f1d
jmp 0xa6eb
cmpl $0xff, %eax
jne 0xa6eb
movq %r14, %rdi
callq 0x2130
xorl %eax, %eax
jmp 0xa709