// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
leaq 0x41a(%rip), %rdi       # 0x6790
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x7340
movq %rax, -0xb8(%rbp)
cmpq $0x0, %rax
jne 0x6394
jmp 0x6773
movl $0x10, %edi
callq 0x7070
movq %rax, -0xd8(%rbp)
cmpq $0x0, %rax
jne 0x63b0
jmp 0x6732
movq -0x10(%rbp), %rdi
callq 0x21a0
movq %rax, -0xa8(%rbp)
cmpq $0x0, %rax
jne 0x640a
jmp 0x63c8
callq 0x20a0
cmpl $0x0, (%rax)
je 0x63f1
movq -0x10(%rbp), %rsi
leaq 0xc98f(%rip), %rdi      # 0x12d6c
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6403
movq -0x10(%rbp), %rsi
leaq 0xc970(%rip), %rdi      # 0x12d6c
movb $0x0, %al
callq 0xf2c0
jmp 0x6405
jmp 0x6726
jmp 0x640c
callq 0x20a0
movl $0x0, (%rax)
movq -0xa8(%rbp), %rdi
callq 0x2380
movq %rax, -0xb0(%rbp)
cmpq $0x0, %rax
jne 0x6435
jmp 0x65e9
movq -0xb0(%rbp), %rdi
addq $0x13, %rdi
callq 0x21b0
cmpq $0x15, %rax
je 0x644d
jmp 0x640c
movq -0xb0(%rbp), %rdi
addq $0x13, %rdi
leaq 0xc92f(%rip), %rsi      # 0x12d8e
movl $0x5, %edx
callq 0x20c0
cmpl $0x0, %eax
je 0x6470
jmp 0x640c
movq -0xb0(%rbp), %rdi
addq $0x13, %rdi
addq $0x5, %rdi
leaq -0xd0(%rbp), %rsi
movl $0x8, %edx
callq 0xca10
cmpl $0x0, %eax
je 0x649a
jmp 0x640c
movq -0x10(%rbp), %rdx
movq -0xb0(%rbp), %rcx
addq $0x13, %rcx
leaq -0xc8(%rbp), %rdi
leaq 0xc8dd(%rip), %rsi      # 0x12d94
movb $0x0, %al
callq 0xb850
cmpl $-0x1, %eax
jne 0x64ff
jmp 0x64c5
callq 0x20a0
cmpl $0x0, (%rax)
je 0x64ea
leaq 0xbe0f(%rip), %rdi      # 0x122e5
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x64f8
leaq 0xbdf4(%rip), %rdi      # 0x122e5
movb $0x0, %al
callq 0xf2c0
jmp 0x64fa
jmp 0x671a
movq -0xc8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x22d0
cmpl $0x0, %eax
je 0x6561
jmp 0x6519
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6545
movq -0xc8(%rbp), %rsi
leaq 0xc869(%rip), %rdi      # 0x12d9a
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x655a
movq -0xc8(%rbp), %rsi
leaq 0xc847(%rip), %rdi      # 0x12d9a
movb $0x0, %al
callq 0xf2c0
jmp 0x655c
jmp 0x670e
movl -0x88(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x8000, %eax           # imm = 0x8000
je 0x6575
jmp 0x65d8
movl $0x10, %edi
callq 0x23a0
movq %rax, -0xc0(%rbp)
cmpq $0x0, %rax
jne 0x6591
jmp 0x670e
leaq -0xd0(%rbp), %rdi
callq 0x67f0
movq %rax, %rcx
movq -0xc0(%rbp), %rax
movq %rcx, (%rax)
movq -0x70(%rbp), %rcx
movq -0xc0(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x76e0
cmpl $0x0, %eax
je 0x65d6
jmp 0x6702
jmp 0x65d8
movq -0xc8(%rbp), %rdi
callq 0x2040
jmp 0x640c
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6637
jmp 0x65f5
callq 0x20a0
cmpl $0x0, (%rax)
je 0x661e
movq -0x10(%rbp), %rsi
leaq 0xc799(%rip), %rdi      # 0x12da3
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6630
movq -0x10(%rbp), %rsi
leaq 0xc77a(%rip), %rdi      # 0x12da3
movb $0x0, %al
callq 0xf2c0
jmp 0x6632
jmp 0x671a
jmp 0x6639
movq -0xa8(%rbp), %rdi
callq 0x22b0
cmpl $0x0, %eax
je 0x669a
callq 0x20a0
cmpl $0x4, (%rax)
jne 0x6656
jmp 0x6639
jmp 0x6658
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6681
movq -0x10(%rbp), %rsi
leaq 0xc75a(%rip), %rdi      # 0x12dc7
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6693
movq -0x10(%rbp), %rsi
leaq 0xc73b(%rip), %rdi      # 0x12dc7
movb $0x0, %al
callq 0xf2c0
jmp 0x6695
jmp 0x6726
jmp 0x669c
movq -0xb8(%rbp), %rdi
callq 0x7890
movq %rax, -0xc0(%rbp)
cmpq $0x0, %rax
je 0x66e9
movq -0xd8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x7130
cmpl $0x0, %eax
je 0x66cf
jmp 0x6726
movq -0xc0(%rbp), %rdi
callq 0x2040
movq -0xb8(%rbp), %rdi
callq 0x7bd0
jmp 0x669c
movq -0xb8(%rbp), %rdi
callq 0x7cd0
movq -0xd8(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x677b
movq -0xc0(%rbp), %rdi
callq 0x2040
movq -0xc8(%rbp), %rdi
callq 0x2040
movq -0xa8(%rbp), %rdi
callq 0x22b0
movq -0xd8(%rbp), %rdi
callq 0x7310
jmp 0x6734
movq -0xb8(%rbp), %rdi
callq 0x7890
movq %rax, -0xc0(%rbp)
cmpq $0x0, %rax
je 0x6767
movq -0xb8(%rbp), %rdi
callq 0x7bd0
movq -0xc0(%rbp), %rdi
callq 0x2040
jmp 0x6734
movq -0xb8(%rbp), %rdi
callq 0x7cd0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax,%rax)