// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/lbs/storage_findfiles.c
// Function: storage_findfiles
struct elasticqueue *
storage_findfiles(const char * path)
{
	struct stat sb;
	DIR * dir;
	struct dirent * dp;
	struct ptrheap * H;
	struct storage_file * sf;
	char * s;
	uint8_t fileno_exp[8];
	struct elasticqueue * Q;

	/* Create a heap for holding storage_file structures. */
	if ((H = ptrheap_init(fs_compar, NULL, NULL)) == NULL)
		goto err0;

	/* Create a queue for holding the structures in sorted order. */
	if ((Q = elasticqueue_init(sizeof(struct storage_file))) == NULL)
		goto err1;

	/* Open the storage directory. */
	if ((dir = opendir(path)) == NULL) {
		warnp("Cannot open storage directory: %s", path);
		goto err2;
	}

	/*
	 * Look for files named "blks_<64-bit hexified first block #>" and
	 * create storage_file structures for each.
	 */
	while (1) {
		/* Get a pointer to the next directory entry. */
		errno = 0;
		if ((dp = readdir(dir)) == NULL)
			break;

		/* Skip anything which isn't the right length. */
		if (strlen(dp->d_name) != strlen("blks_0123456789abcdef"))
			continue;

		/* Skip anything which doesn't start with "blks_". */
		if (strncmp(dp->d_name, "blks_", 5))
			continue;

		/* Make sure the name has 8 hexified bytes and parse. */
		if (unhexify(&dp->d_name[5], fileno_exp, 8))
			continue;

		/* Construct a full path to the file and stat. */
		if (asprintf(&s, "%s/%s", path, dp->d_name) == -1) {
			warnp("asprintf");
			goto err3;
		}
		if (lstat(s, &sb)) {
			warnp("stat(%s)", s);
			goto err4;
		}

		/* Skip anything other than regular files. */
		if (!S_ISREG(sb.st_mode))
			goto next;

		/* Allocate a file_state structure. */
		if ((sf = malloc(sizeof(struct storage_file))) == NULL)
			goto err4;

		/* Fill in file number and size. */
		sf->fileno = be64dec(fileno_exp);
		sf->len = sb.st_size;

		/* Insert the file into the heap. */
		if (ptrheap_add(H, sf))
			goto err5;

next:
		/* Free the full path to the file. */
		free(s);
	}
	if (errno != 0) {
		warnp("Error reading storage directory: %s", path);
		goto err3;
	}

	/* Close the storage directory. */
	while (closedir(dir)) {
		/* Retry if we were interrupted. */
		if (errno == EINTR)
			continue;

		/* Oops, something bad happened. */
		warnp("Error closing storage directory: %s", path);
		goto err2;
	}

	/* Suck structures from the heap into the queue. */
	while ((sf = ptrheap_getmin(H)) != NULL) {
		if (elasticqueue_add(Q, sf))
			goto err2;
		free(sf);
		ptrheap_deletemin(H);
	}

	/* Free the (now empty) heap. */
	ptrheap_free(H);

	/* Success! */
	return (Q);

err5:
	free(sf);
err4:
	free(s);
err3:
	closedir(dir);
err2:
	elasticqueue_free(Q);
err1:
	while ((sf = ptrheap_getmin(H)) != NULL) {
		ptrheap_deletemin(H);
		free(sf);
	}
	ptrheap_free(H);
err0:
	/* Failure! */
	return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %rbx
leaq 0x2be(%rip), %rdi       # 0x4f85
xorl %r12d, %r12d
xorl %esi, %esi
xorl %edx, %edx
callq 0x563c
testq %rax, %rax
je 0x4ec4
movq %rax, %r14
pushq $0x10
popq %rdi
callq 0x54e8
testq %rax, %rax
je 0x4ef2
movq %rax, %r12
movq %rbx, %rdi
callq 0x2190
movq %rax, %r15
callq 0x20a0
movq %rax, %r13
testq %r15, %r15
je 0x4e3e
movq %rbx, 0x18(%rsp)
movq %r12, 0x8(%rsp)
pushq $0x5
popq %r12
andl $0x0, (%r13)
movq %r15, %rdi
callq 0x2360
testq %rax, %rax
je 0x4e0d
movq %rax, %rbp
leaq 0x13(%rax), %rbx
movq %rbx, %rdi
callq 0x21a0
cmpq $0x15, %rax
jne 0x4d1d
movq %rbx, %rdi
leaq 0x7e58(%rip), %rsi      # 0xcbaa
movq %r12, %rdx
callq 0x20c0
testl %eax, %eax
jne 0x4d1d
addq $0x18, %rbp
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x8873
testl %eax, %eax
jne 0x4d1d
leaq 0x10(%rsp), %rdi
leaq 0x7e2e(%rip), %rsi      # 0xcbb0
movq 0x18(%rsp), %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x7cb4
cmpl $-0x1, %eax
je 0x4f17
movq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x22c0
testl %eax, %eax
jne 0x4f31
movl 0x40(%rsp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x4dfe
pushq $0x10
popq %rdi
callq 0x2380
testq %rax, %rax
je 0x4f76
movq %rax, %rbx
movq 0x20(%rsp), %rax
bswapq %rax
movq %rax, (%rbx)
movq 0x58(%rsp), %rax
movq %rax, 0x8(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x582d
testl %eax, %eax
jne 0x4f52
movq 0x10(%rsp), %rdi
callq 0x2040
jmp 0x4d1d
cmpl $0x0, (%r13)
je 0x4e52
leaq 0x7da4(%rip), %rdi      # 0xcbbf
movq 0x18(%rsp), %rsi
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%r13)
movq 0x8(%rsp), %r12
movq %r15, %rdi
callq 0x2290
jmp 0x4eea
cmpl $0x0, (%r13)
je 0x4ed9
leaq 0x7d38(%rip), %rdi      # 0xcb88
jmp 0x4e7c
movq 0x8(%rsp), %r12
movq 0x18(%rsp), %rbx
movq %r15, %rdi
callq 0x2290
testl %eax, %eax
je 0x4eaf
movl (%r13), %eax
cmpl $0x4, %eax
je 0x4e5c
leaq 0x7d6b(%rip), %rdi      # 0xcbe3
testl %eax, %eax
je 0x4ee0
movq %rbx, %rsi
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%r13)
jmp 0x4eea
movq %rax, %rbx
movq %r12, %rdi
movq %rax, %rsi
callq 0x5555
testl %eax, %eax
jne 0x4eea
movq %rbx, %rdi
callq 0x2040
movq %r14, %rdi
callq 0x5af6
movq %r14, %rdi
callq 0x5921
testq %rax, %rax
jne 0x4e8d
movq %r14, %rdi
callq 0x5b4c
movq %r12, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7ca8(%rip), %rdi      # 0xcb88
movq %rbx, %rsi
xorl %eax, %eax
callq 0x9ec8
movq %r12, %rdi
callq 0x561f
xorl %r12d, %r12d
movq %r14, %rdi
callq 0x5921
testq %rax, %rax
je 0x4ebc
movq %rax, %rbx
movq %r14, %rdi
callq 0x5af6
movq %rbx, %rdi
callq 0x2040
jmp 0x4ef5
cmpl $0x0, (%r13)
je 0x4f5c
leaq 0x72a0(%rip), %rdi      # 0xc1c5
xorl %eax, %eax
callq 0x9d39
jmp 0x4e27
cmpl $0x0, (%r13)
movq 0x10(%rsp), %rsi
leaq 0x7c74(%rip), %rdi      # 0xcbb6
je 0x4f6f
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%r13)
jmp 0x4f76
movq %rbx, %rdi
callq 0x2040
jmp 0x4f76
leaq 0x7262(%rip), %rdi      # 0xc1c5
xorl %eax, %eax
callq 0x9ec8
jmp 0x4e2c
xorl %eax, %eax
callq 0x9ec8
movq 0x10(%rsp), %rdi
callq 0x2040
jmp 0x4e2c