// File: /workspace/github_c_makefile_star2_O1/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 $0xa8, %rsp
movq %rdi, %r12
leaq 0x300(%rip), %rdi       # 0x568f
xorl %r14d, %r14d
xorl %esi, %esi
xorl %edx, %edx
callq 0x5db8
testq %rax, %rax
je 0x55ca
movq %rax, %rbx
movl $0x10, %edi
callq 0x5c50
testq %rax, %rax
je 0x558a
movq %rax, %r14
movq %r12, %rdi
callq 0x2190
movq %rax, %r15
callq 0x20a0
movq %rax, %r13
testq %r15, %r15
je 0x5524
movq %r12, 0x8(%rsp)
movl $0x0, (%r13)
movq %r15, %rdi
callq 0x2360
testq %rax, %rax
je 0x54f8
movq %rax, %rbp
leaq 0x13(%rbp), %r12
movq %r12, %rdi
callq 0x21a0
cmpq $0x15, %rax
jne 0x54dc
movl $0x5, %edx
movq %r12, %rdi
leaq 0x87cf(%rip), %rsi      # 0xdbee
callq 0x20c0
testl %eax, %eax
jne 0x54dc
addq $0x18, %rbp
movl $0x8, %edx
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x945b
testl %eax, %eax
jne 0x54dc
movq %rsp, %rdi
leaq 0x87a0(%rip), %rsi      # 0xdbf4
movq 0x8(%rsp), %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x8b2c
cmpl $-0x1, %eax
je 0x5620
movq (%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x22c0
testl %eax, %eax
jne 0x563a
movl 0x30(%rsp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x54d3
movl $0x10, %edi
callq 0x2380
testq %rax, %rax
je 0x5681
movq %rax, %r12
movq 0x10(%rsp), %rax
bswapq %rax
movq %rax, (%r12)
movq 0x48(%rsp), %rax
movq %rax, 0x8(%r12)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5fcd
testl %eax, %eax
jne 0x565d
movq (%rsp), %rdi
callq 0x2040
movl $0x0, (%r13)
movq %r15, %rdi
callq 0x2360
movq %rax, %rbp
testq %rax, %rax
jne 0x53fa
cmpl $0x0, (%r13)
je 0x5534
leaq 0x86fd(%rip), %rdi      # 0xdc03
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0xac18
movl $0x0, (%r13)
movq %r15, %rdi
callq 0x2290
jmp 0x5582
cmpl $0x0, (%r13)
je 0x5571
leaq 0x869a(%rip), %rdi      # 0xdbcc
jmp 0x555d
movq 0x8(%rsp), %r12
movq %r15, %rdi
callq 0x2290
testl %eax, %eax
je 0x55df
movl (%r13), %eax
cmpl $0x4, %eax
je 0x5539
leaq 0x86ce(%rip), %rdi      # 0xdc27
testl %eax, %eax
je 0x5578
movq %r12, %rsi
xorl %eax, %eax
callq 0xac18
movl $0x0, (%r13)
jmp 0x5582
leaq 0x8654(%rip), %rdi      # 0xdbcc
movq %r12, %rsi
xorl %eax, %eax
callq 0xad37
movq %r14, %rdi
callq 0x5d9b
movq %rbx, %rdi
callq 0x60d3
testq %rax, %rax
je 0x55bf
movq %rax, %r15
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x62e2
movq %r15, %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x60d3
movq %rax, %r15
testq %rax, %rax
jne 0x559d
jmp 0x55c2
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x6338
movq %r14, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x60d3
testq %rax, %rax
je 0x55c2
movq %rax, %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x5cc1
testl %eax, %eax
jne 0x5582
movq %r15, %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x62e2
movq %rbx, %rdi
callq 0x60d3
movq %rax, %r15
testq %rax, %rax
jne 0x55ef
jmp 0x55c2
cmpl $0x0, (%r13)
je 0x5667
leaq 0x7b97(%rip), %rdi      # 0xd1c5
xorl %eax, %eax
callq 0xac18
jmp 0x5512
cmpl $0x0, (%r13)
movq (%rsp), %rsi
leaq 0x85b0(%rip), %rdi      # 0xdbfa
je 0x567a
xorl %eax, %eax
callq 0xac18
movl $0x0, (%r13)
jmp 0x5681
movq %r12, %rdi
callq 0x2040
jmp 0x5681
leaq 0x7b57(%rip), %rdi      # 0xd1c5
xorl %eax, %eax
callq 0xad37
jmp 0x551a
xorl %eax, %eax
callq 0xad37
movq (%rsp), %rdi
callq 0x2040
jmp 0x551a