// File: /workspace/github_cpp_makefile_star2_O2/conchoecia[P]fasta_stats/src/open_compressed.cc
// Function: find_suffix(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
int find_suffix(std::string &filename, std::string &suffix) {
	const char *suffix_list[3] = { ".gz", ".bz2", ".Z" };
	const size_t suffix_size[3] = { 3, 4, 2 };
	suffix.clear();
	for (int i = 0; i != 3; ++i) {
		const size_t &j = suffix_size[i];
		if (filename.size() > j && filename.compare(filename.size() - j, j, suffix_list[i]) == 0) {
			suffix = suffix_list[i];
			break;
		}
	}
	struct stat buf;
	if (stat(filename.c_str(), &buf) == 0) {
		/* only open regular files */
		if ((buf.st_mode & S_IFDIR) != 0) {
			errno = EISDIR;
			return -1;
		} else {
			return 0;
		}
	} else if (errno != ENOENT) {
		fprintf(stderr, "Error: stat: %s: %s\n", filename.c_str(), strerror(errno));
		return -1;
	} else if (!suffix.empty()) {
		return -1;
	}
	for (int i = 0; i != 3; ++i) {
		const std::string s(filename + suffix_list[i]);
		if (stat(s.c_str(), &buf) == -1) {
			if (errno != ENOENT) {
				fprintf(stderr, "Error: stat: %s: %s\n", filename.c_str(), strerror(errno));
				return -1;
			}
		} else if ((buf.st_mode & S_IFDIR) == 0) {
			suffix = suffix_list[i];
			filename += suffix;
			return 0;
		}
	}
	errno = ENOENT;
	return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, %rbp
movq %rdi, %rbx
andq $0x0, 0x8(%rsi)
movq (%rsi), %rax
movb $0x0, (%rax)
xorl %r14d, %r14d
leaq 0x22eb(%rip), %r13      # 0x68a0
leaq 0x57d4(%rip), %r12      # 0x9d90
cmpq $0x18, %r14
je 0x45f3
movq 0x8(%rbx), %rsi
movq (%r14,%r13), %rdx
subq %rdx, %rsi
jbe 0x45e2
movq (%r14,%r12), %r15
movq %rbx, %rdi
movq %r15, %rcx
callq 0x22a0
testl %eax, %eax
je 0x45e8
addq $0x8, %r14
jmp 0x45bc
movq %rbp, %rdi
movq %r15, %rsi
callq 0x23a0
movq (%rbx), %rdi
leaq 0x38(%rsp), %rsi
callq 0x2210
testl %eax, %eax
je 0x46e5
callq 0x2040
movq %rax, 0x8(%rsp)
movl (%rax), %edi
cmpl $0x2, %edi
jne 0x4708
cmpq $0x0, 0x8(%rbp)
jne 0x4731
movq %rbp, 0x10(%rsp)
xorl %r15d, %r15d
cmpq $0x18, %r15
je 0x46fb
movq (%r15,%r12), %r13
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x50ad
movq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x2210
cmpl $-0x1, %eax
je 0x468d
movb $0x1, %r14b
testb $0x40, 0x51(%rsp)
jne 0x469c
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x23a0
xorl %r14d, %r14d
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x23c0
xorl %ebp, %ebp
jmp 0x469c
movq 0x8(%rsp), %rax
movl (%rax), %edi
movb $0x1, %r14b
cmpl $0x2, %edi
jne 0x46b4
leaq 0x18(%rsp), %rdi
callq 0x2120
addq $0x8, %r15
testb %r14b, %r14b
jne 0x4630
jmp 0x4734
movq 0x5915(%rip), %rax      # 0x9fd0
movq (%rax), %r13
movq (%rbx), %rbp
callq 0x20d0
xorl %r14d, %r14d
movq %r13, %rdi
leaq 0x1fd9(%rip), %rsi      # 0x66ac
movq %rbp, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x22f0
pushq $-0x1
popq %rbp
jmp 0x469c
xorl %ebp, %ebp
testb $0x40, 0x51(%rsp)
je 0x4734
callq 0x2040
movl $0x15, (%rax)
jmp 0x4731
movq 0x8(%rsp), %rax
movl $0x2, (%rax)
jmp 0x4731
movq 0x58c1(%rip), %rax      # 0x9fd0
movq (%rax), %r14
movq (%rbx), %rbx
callq 0x20d0
leaq 0x1f8b(%rip), %rsi      # 0x66ac
movq %r14, %rdi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x22f0
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x2120
movq %rbx, %rdi
callq 0x2370