// File: /workspace/github_c_makefile_star2_O3/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       # 0x56b7
xorl %r14d, %r14d
xorl %esi, %esi
xorl %edx, %edx
callq 0x5dcc
testq %rax, %rax
je 0x55f2
movq %rax, %rbx
movl $0x10, %edi
callq 0x5c68
testq %rax, %rax
je 0x55b2
movq %rax, %r14
movq %r12, %rdi
callq 0x2190
movq %rax, %r15
callq 0x20a0
movq %rax, %r13
testq %r15, %r15
je 0x554c
movq %r12, 0x8(%rsp)
movl $0x0, (%r13)
movq %r15, %rdi
callq 0x2360
testq %rax, %rax
je 0x5520
movq %rax, %rbp
leaq 0x13(%rbp), %r12
movq %r12, %rdi
callq 0x21a0
cmpq $0x15, %rax
jne 0x5504
movl $0x5, %edx
movq %r12, %rdi
leaq 0x8727(%rip), %rsi      # 0xdb6e
callq 0x20c0
testl %eax, %eax
jne 0x5504
addq $0x18, %rbp
movl $0x8, %edx
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x9577
testl %eax, %eax
jne 0x5504
movq %rsp, %rdi
leaq 0x86f8(%rip), %rsi      # 0xdb74
movq 0x8(%rsp), %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x8ba4
cmpl $-0x1, %eax
je 0x5648
movq (%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x22c0
testl %eax, %eax
jne 0x5662
movl 0x30(%rsp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x54fb
movl $0x10, %edi
callq 0x2380
testq %rax, %rax
je 0x56a9
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 0x5fdf
testl %eax, %eax
jne 0x5685
movq (%rsp), %rdi
callq 0x2040
movl $0x0, (%r13)
movq %r15, %rdi
callq 0x2360
movq %rax, %rbp
testq %rax, %rax
jne 0x5422
cmpl $0x0, (%r13)
je 0x555c
leaq 0x8655(%rip), %rdi      # 0xdb83
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0xacd8
movl $0x0, (%r13)
movq %r15, %rdi
callq 0x2290
jmp 0x55aa
cmpl $0x0, (%r13)
je 0x5599
leaq 0x85f2(%rip), %rdi      # 0xdb4c
jmp 0x5585
movq 0x8(%rsp), %r12
movq %r15, %rdi
callq 0x2290
testl %eax, %eax
je 0x5607
movl (%r13), %eax
cmpl $0x4, %eax
je 0x5561
leaq 0x8626(%rip), %rdi      # 0xdba7
testl %eax, %eax
je 0x55a0
movq %r12, %rsi
xorl %eax, %eax
callq 0xacd8
movl $0x0, (%r13)
jmp 0x55aa
leaq 0x85ac(%rip), %rdi      # 0xdb4c
movq %r12, %rsi
xorl %eax, %eax
callq 0xadf7
movq %r14, %rdi
callq 0x5db1
movq %rbx, %rdi
callq 0x60f0
testq %rax, %rax
je 0x55e7
movq %rax, %r15
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x6305
movq %r15, %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x60f0
movq %rax, %r15
testq %rax, %rax
jne 0x55c5
jmp 0x55ea
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x635b
movq %r14, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x60f0
testq %rax, %rax
je 0x55ea
movq %rax, %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x5cd9
testl %eax, %eax
jne 0x55aa
movq %r15, %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x6305
movq %rbx, %rdi
callq 0x60f0
movq %rax, %r15
testq %rax, %rax
jne 0x5617
jmp 0x55ea
cmpl $0x0, (%r13)
je 0x568f
leaq 0x7b6f(%rip), %rdi      # 0xd1c5
xorl %eax, %eax
callq 0xacd8
jmp 0x553a
cmpl $0x0, (%r13)
movq (%rsp), %rsi
leaq 0x8508(%rip), %rdi      # 0xdb7a
je 0x56a2
xorl %eax, %eax
callq 0xacd8
movl $0x0, (%r13)
jmp 0x56a9
movq %r12, %rdi
callq 0x2040
jmp 0x56a9
leaq 0x7b2f(%rip), %rdi      # 0xd1c5
xorl %eax, %eax
callq 0xadf7
jmp 0x5542
xorl %eax, %eax
callq 0xadf7
movq (%rsp), %rdi
callq 0x2040
jmp 0x5542