// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movq %rdi, %rbx
movq $0x0, 0x8(%rsi)
movq (%rsi), %rax
movb $0x0, (%rax)
xorl %r13d, %r13d
leaq 0x2163(%rip), %rbp      # 0x68a0
leaq 0x464c(%rip), %r12      # 0x8d90
movq 0x8(%rbx), %rsi
movq (%r13,%rbp), %rdx
subq %rdx, %rsi
jbe 0x4766
movq (%r13,%r12), %r15
movq %rbx, %rdi
movq %r15, %rcx
callq 0x2290
testl %eax, %eax
je 0x4772
addq $0x8, %r13
cmpq $0x18, %r13
jne 0x4744
jmp 0x4791
movq 0x8(%r14), %r13
movq %r15, %rdi
callq 0x2130
movq %r14, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r15, %rcx
movq %rax, %r8
callq 0x2310
movq (%rbx), %rdi
leaq 0x38(%rsp), %rsi
callq 0x2200
testl %eax, %eax
je 0x48a2
callq 0x2040
movq %rax, 0x10(%rsp)
movl (%rax), %esi
cmpl $0x2, %esi
jne 0x48cb
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq $0x0, 0x8(%r14)
jne 0x48d8
xorl %r15d, %r15d
movq (%r15,%r12), %r13
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %rbp
movq %rbp, %rdi
callq 0x5646
movq %rbp, %rdi
movq %r13, %rsi
callq 0x23a0
movq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x2200
cmpl $-0x1, %eax
je 0x4856
movb $0x1, %bpl
testb $0x40, 0x51(%rsp)
jne 0x4865
movq 0x8(%r14), %rbp
movq %r13, %rdi
callq 0x2130
movq %r14, %rdi
xorl %esi, %esi
movq %rbp, %rdx
movq %r13, %rcx
movq %rax, %r8
callq 0x2310
movq (%r14), %rsi
movq 0x8(%r14), %rdx
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x20e0
movl $0x0, 0xc(%rsp)
jmp 0x4865
movq 0x10(%rsp), %rax
movl (%rax), %esi
movb $0x1, %bpl
cmpl $0x2, %esi
jne 0x488e
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x4879
callq 0x2220
testb %bpl, %bpl
je 0x48b8
addq $0x8, %r15
cmpq $0x18, %r15
jne 0x47ce
jmp 0x48be
movq %rbx, %rdi
callq 0x24a9
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
xorl %ebp, %ebp
jmp 0x4865
xorl %eax, %eax
testb $0x40, 0x51(%rsp)
je 0x48d8
callq 0x2040
movl $0x15, (%rax)
jmp 0x48d3
movl 0xc(%rsp), %eax
jmp 0x48d8
movq 0x10(%rsp), %rax
movl $0x2, (%rax)
jmp 0x48d3
movq %rbx, %rdi
callq 0x2473
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x48ec
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x4903
callq 0x2220
movq %rbx, %rdi
callq 0x2370