// File: 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:
subq $0x168, %rsp            # imm = 0x168
movq %rdi, 0x158(%rsp)
movq %rsi, 0x150(%rsp)
movq 0xb832(%rip), %rax      # 0x15d90
movq %rax, 0x130(%rsp)
movq 0xb82b(%rip), %rax      # 0x15d98
movq %rax, 0x138(%rsp)
movq 0xb824(%rip), %rax      # 0x15da0
movq %rax, 0x140(%rsp)
movq 0x53f5(%rip), %rax      # 0xf980
movq %rax, 0x110(%rsp)
movq 0x53ee(%rip), %rax      # 0xf988
movq %rax, 0x118(%rsp)
movq 0x53e7(%rip), %rax      # 0xf990
movq %rax, 0x120(%rsp)
movq 0x150(%rsp), %rdi
callq 0x2310
movl $0x0, 0x10c(%rsp)
cmpl $0x3, 0x10c(%rsp)
je 0xa699
movslq 0x10c(%rsp), %rcx
leaq 0x110(%rsp), %rax
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x100(%rsp)
movq 0x158(%rsp), %rdi
callq 0x21e0
movq 0x100(%rsp), %rcx
cmpq (%rcx), %rax
jbe 0xa681
movq 0x158(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x158(%rsp), %rdi
callq 0x21e0
movq 0x28(%rsp), %rdi
movq %rax, %rsi
movq 0x100(%rsp), %rax
subq (%rax), %rsi
movq 0x100(%rsp), %rax
movq (%rax), %rdx
movslq 0x10c(%rsp), %rax
movq 0x130(%rsp,%rax,8), %rcx
callq 0x2320
cmpl $0x0, %eax
jne 0xa681
movslq 0x10c(%rsp), %rax
movq 0x130(%rsp,%rax,8), %rsi
movq 0x150(%rsp), %rdi
callq 0x2330
jmp 0xa699
jmp 0xa683
movl 0x10c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10c(%rsp)
jmp 0xa5c9
movq 0x158(%rsp), %rdi
callq 0x2110
movq %rax, %rdi
leaq 0x70(%rsp), %rsi
callq 0x2240
cmpl $0x0, %eax
jne 0xa6f4
movl 0x88(%rsp), %eax
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
je 0xa6e4
callq 0x2040
movl $0x15, (%rax)
movl $0xffffffff, 0x164(%rsp) # imm = 0xFFFFFFFF
jmp 0xa8ed
movl $0x0, 0x164(%rsp)
jmp 0xa8ed
callq 0x2040
cmpl $0x2, (%rax)
je 0xa756
movq 0xb8cb(%rip), %rax      # 0x15fd0
movq (%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x158(%rsp), %rdi
callq 0x2110
movq %rax, 0x20(%rsp)
callq 0x2040
movl (%rax), %edi
callq 0x20d0
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rdx
movq %rax, %rcx
leaq 0x4fed(%rip), %rsi      # 0xf72c
movb $0x0, %al
callq 0x2380
movl $0xffffffff, 0x164(%rsp) # imm = 0xFFFFFFFF
jmp 0xa8ed
movq 0x150(%rsp), %rdi
callq 0x23f0
testb $0x1, %al
jne 0xa777
movl $0xffffffff, 0x164(%rsp) # imm = 0xFFFFFFFF
jmp 0xa8ed
jmp 0xa779
jmp 0xa77b
movl $0x0, 0x6c(%rsp)
cmpl $0x3, 0x6c(%rsp)
je 0xa8d7
movq 0x158(%rsp), %rsi
movslq 0x6c(%rsp), %rax
movq 0x130(%rsp,%rax,8), %rdx
leaq 0x48(%rsp), %rdi
callq 0xba40
leaq 0x48(%rsp), %rdi
callq 0x2110
movq %rax, %rdi
leaq 0x70(%rsp), %rsi
callq 0x2240
cmpl $-0x1, %eax
jne 0xa832
callq 0x2040
cmpl $0x2, (%rax)
je 0xa830
movq 0xb7f6(%rip), %rax      # 0x15fd0
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x158(%rsp), %rdi
callq 0x2110
movq %rax, 0x10(%rsp)
callq 0x2040
movl (%rax), %edi
callq 0x20d0
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rdx
movq %rax, %rcx
leaq 0x4f18(%rip), %rsi      # 0xf72c
movb $0x0, %al
callq 0x2380
movl $0xffffffff, 0x164(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x44(%rsp)
jmp 0xa8af
jmp 0xa8a7
movl 0x88(%rsp), %eax
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
jne 0xa8a5
movslq 0x6c(%rsp), %rax
movq 0x130(%rsp,%rax,8), %rsi
movq 0x150(%rsp), %rdi
callq 0x2330
jmp 0xa85f
movq 0x150(%rsp), %rsi
movq 0x158(%rsp), %rdi
callq 0x22f0
jmp 0xa876
movl $0x0, 0x164(%rsp)
movl $0x1, 0x44(%rsp)
jmp 0xa8af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x38(%rsp)
movl %eax, 0x34(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x21a0
jmp 0xa8fc
jmp 0xa8a7
movl $0x0, 0x44(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x21a0
movl 0x44(%rsp), %eax
testl %eax, %eax
je 0xa8c5
jmp 0xa8c3
jmp 0xa8ed
jmp 0xa8c7
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0xa783
callq 0x2040
movl $0x2, (%rax)
movl $0xffffffff, 0x164(%rsp) # imm = 0xFFFFFFFF
movl 0x164(%rsp), %eax
addq $0x168, %rsp            # imm = 0x168
retq
movq 0x38(%rsp), %rdi
callq 0x2420
nopw %cs:(%rax,%rax)