// File: /workspace/github_cpp_makefile_star2_O3/BenLangmead[P]bowtie/./shmem.h
// Function: bool allocSharedMem<unsigned char>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned long, unsigned char**, char const*, bool)
bool allocSharedMem(std::string fname,
                    size_t len,
                    T ** dst,
                    const char *memName,
                    bool verbose)
{
	using namespace std;
	int shmid = -1;
	// Calculate key given string
	key_t key = (key_t)hash_string(fname);
	shmid_ds ds;
	int ret;
	// Reserve 4 bytes at the end for silly synchronization
	size_t shmemLen = len + 4;
	if(verbose) {
		cerr << "Reading " << len << "+4 bytes into shared memory for " << memName << endl;
	}
	T *ptr = NULL;
	while(true) {
		// Create the shrared-memory block
		if((shmid = shmget(key, shmemLen, IPC_CREAT | 0666)) < 0) {
			if(errno == ENOMEM) {
				cerr << "Out of memory allocating shared area " << memName << endl;
			} else if(errno == EACCES) {
				cerr << "EACCES" << endl;
			} else if(errno == EEXIST) {
				cerr << "EEXIST" << endl;
			} else if(errno == EINVAL) {
				cerr << "Warning: shared-memory chunk's segment size doesn't match expected size (" << (shmemLen) << ")" << endl
					 << "Deleting old shared memory block and trying again." << endl;
				shmid = shmget(key, 0, 0);
				if((ret = shmctl(shmid, IPC_RMID, &ds)) < 0) {
					cerr << "shmctl returned " << ret
						 << " for IPC_RMID, errno is " << errno
						 << ", shmid is " << shmid << endl;
					throw 1;
				} else {
					cerr << "Deleted shared mem chunk with shmid " << shmid << endl;
				}
				continue;
			} else if(errno == ENOENT) {
				cerr << "ENOENT" << endl;
			} else if(errno == ENOSPC) {
				cerr << "ENOSPC" << endl;
			} else {
				cerr << "shmget returned " << shmid << " for and errno is " << errno << endl;
			}
			throw 1;
		}
		ptr = (T*)shmat(shmid, 0, 0);
		if(ptr == (void*)-1) {
			cerr << "Failed to attach " << memName << " to shared memory with shmat()." << endl;
			throw 1;
		}
		if(ptr == NULL) {
			cerr << memName << " pointer returned by shmat() was NULL." << endl;
			throw 1;
		}
		// Did I create it, or did I just attach to one created by
		// another process?
		if((ret = shmctl(shmid, IPC_STAT, &ds)) < 0) {
			cerr << "shmctl returned " << ret << " for IPC_STAT and errno is " << errno << endl;
			throw 1;
		}
		if((size_t)ds.shm_segsz != shmemLen) {
			cerr << "Warning: shared-memory chunk's segment size (" << ds.shm_segsz
				 << ") doesn't match expected size (" << shmemLen << ")" << endl
				 << "Deleting old shared memory block and trying again." << endl;
			if((ret = shmctl(shmid, IPC_RMID, &ds)) < 0) {
				cerr << "shmctl returned " << ret << " for IPC_RMID and errno is " << errno << endl;
				throw 1;
			}
		} else {
			break;
		}
	} // while(true)
	*dst = ptr;
	bool initid = (((volatile uint32_t*)((char*)ptr + len))[0] == SHMEM_INIT);
	if(ds.shm_cpid == getpid() && !initid) {
		if(verbose) {
			cerr << "  I (pid = " << getpid() << ") created the "
			     << "shared memory for " << memName << endl;
		}
		// Set this value just off the end of the chunk to
		// indicate that the data hasn't been read yet.
		((volatile uint32_t*)((char*)ptr + len))[0] = SHMEM_UNINIT;
		return true;
	} else {
		if(verbose) {
			cerr << "  I (pid = " << getpid()
			     << ") did not create the shared memory for "
			     << memName << ".  Pid " << ds.shm_cpid << " did." << endl;
		}
		return false;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, %r14
movq %rdx, 0x18(%rsp)
movq %rsi, %r15
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x1158b
movq (%rdi), %rcx
movl $0xf8c9, %edx           # imm = 0xF8C9
xorl %esi, %esi
xorl %r12d, %r12d
imull %edx, %r12d
movsbl (%rcx,%rsi), %edi
addl %edi, %r12d
imull $0x5c6b7, %edx, %edx    # imm = 0x5C6B7
incq %rsi
cmpq %rsi, %rax
jne 0x11570
jmp 0x1158e
xorl %r12d, %r12d
movl %r8d, 0x14(%rsp)
testb %r8b, %r8b
je 0x11636
movq 0x25a4d(%rip), %rbx     # 0x36ff0
leaq 0x1e5a7(%rip), %rsi     # 0x2fb51
movl $0x8, %edx
movq %rbx, %rdi
callq 0x43b0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x41d0
movq %rax, %rbx
leaq 0x1e58e(%rip), %rsi     # 0x2fb5a
movl $0x20, %edx
movq %rax, %rdi
callq 0x43b0
testq %r14, %r14
je 0x115f6
movq %r14, %rdi
callq 0x4140
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x43b0
jmp 0x1160f
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq %rbx, %rdi
addq %rax, %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x45e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movq %r14, 0x8(%rsp)
movq %r15, 0x20(%rsp)
addq $0x4, %r15
movq 0x259a5(%rip), %r13     # 0x36ff0
movl %r12d, %edi
movq %r15, %rsi
movl $0x3b6, %edx            # imm = 0x3B6
callq 0x41a0
movl %eax, %ebp
testl %eax, %eax
js 0x11784
movl %ebp, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4480
testq %rax, %rax
je 0x11b0f
movq %rax, %r14
cmpq $-0x1, %rax
je 0x11b51
movl %ebp, %edi
movl $0x2, %esi
leaq 0x28(%rsp), %rdx
callq 0x4260
testl %eax, %eax
js 0x11b29
cmpq %r15, 0x58(%rsp)
je 0x118a3
movl $0x2d, %edx
movq %r13, %rdi
leaq 0x1e675(%rip), %rsi     # 0x2fd2e
callq 0x43b0
movq 0x58(%rsp), %rsi
movq %r13, %rdi
callq 0x41d0
movq %rax, %rbx
movl $0x1f, %edx
movq %rax, %rdi
leaq 0x1e67f(%rip), %rsi     # 0x2fd5c
callq 0x43b0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x41d0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1cca6(%rip), %rsi     # 0x2e3a5
callq 0x43b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movq %rax, %rbx
movl $0x32, %edx
movq %rax, %rdi
leaq 0x1e4bc(%rip), %rsi     # 0x2fbf9
callq 0x43b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movl %ebp, %edi
xorl %esi, %esi
leaq 0x28(%rsp), %rdx
callq 0x4260
testl %eax, %eax
jns 0x1164b
jmp 0x11b85
callq 0x4050
movq %rax, %r14
movl (%rax), %eax
cmpl $0x16, %eax
jne 0x11aa4
movl $0x49, %edx
movq %r13, %rdi
leaq 0x1e409(%rip), %rsi     # 0x2fbaf
callq 0x43b0
movq %r13, %rdi
movq %r15, %rsi
callq 0x41d0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1cbdd(%rip), %rsi     # 0x2e3a5
callq 0x43b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movq %rax, %rbx
movl $0x32, %edx
movq %rax, %rdi
leaq 0x1e3f3(%rip), %rsi     # 0x2fbf9
callq 0x43b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movl %r12d, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x41a0
movl %eax, %ebp
movl %eax, %edi
xorl %esi, %esi
leaq 0x28(%rsp), %rdx
callq 0x4260
testl %eax, %eax
js 0x11c05
movl $0x24, %edx
movq %r13, %rdi
leaq 0x1e3fd(%rip), %rsi     # 0x2fc62
callq 0x43b0
movq %r13, %rdi
movl %ebp, %esi
callq 0x4610
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
jmp 0x1164b
movq 0x18(%rsp), %rax
movq %r14, (%rax)
movq 0x20(%rsp), %r13
movl (%r14,%r13), %ebx
movl 0x78(%rsp), %ebp
callq 0x44c0
cmpl %eax, %ebp
sete %al
cmpl $0xffaa6161, %ebx       # imm = 0xFFAA6161
setne %bl
andb %al, %bl
cmpb $0x1, %bl
jne 0x1195f
cmpb $0x0, 0x14(%rsp)
je 0x11a0e
movq 0x25708(%rip), %r15     # 0x36ff0
leaq 0x1e4a9(%rip), %rsi     # 0x2fd98
movl $0xb, %edx
movq %r15, %rdi
callq 0x43b0
callq 0x44c0
movq %r15, %rdi
movl %eax, %esi
callq 0x4610
movq %rax, %r15
leaq 0x1e48f(%rip), %rsi     # 0x2fda4
movl $0xe, %edx
movq %rax, %rdi
callq 0x43b0
leaq 0x1e49f(%rip), %rsi     # 0x2fdc8
movl $0x12, %edx
movq %r15, %rdi
callq 0x43b0
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0x119cd
movq %r12, %rdi
callq 0x4140
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x43b0
jmp 0x119e7
cmpb $0x0, 0x14(%rsp)
je 0x11a90
movq 0x2567f(%rip), %r14     # 0x36ff0
leaq 0x1e420(%rip), %rsi     # 0x2fd98
movl $0xb, %edx
movq %r14, %rdi
callq 0x43b0
callq 0x44c0
movq %r14, %rdi
movl %eax, %esi
callq 0x4610
movq %rax, %r14
leaq 0x1e415(%rip), %rsi     # 0x2fdb3
movl $0x27, %edx
movq %rax, %rdi
callq 0x43b0
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x11a18
movq %r15, %rdi
callq 0x4140
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x43b0
jmp 0x11a32
movq (%r15), %rax
movq -0x18(%rax), %rax
movq %r15, %rdi
addq %rax, %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x45e0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %r15, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movl $0xafba4242, (%r14,%r13) # imm = 0xAFBA4242
jmp 0x11a90
movq (%r14), %rax
movq -0x18(%rax), %rax
movq %r14, %rdi
addq %rax, %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x45e0
leaq 0x1e3a2(%rip), %rsi     # 0x2fddb
movl $0x7, %edx
movq %r14, %rdi
callq 0x43b0
movl 0x78(%rsp), %esi
movq %r14, %rdi
callq 0x4610
movq %rax, %r14
leaq 0x1e387(%rip), %rsi     # 0x2fde3
movl $0x5, %edx
movq %rax, %rdi
callq 0x43b0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x4300
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41e0
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0xc, %eax
jle 0x11ad0
cmpl $0xd, %eax
je 0x11bc5
cmpl $0x11, %eax
je 0x11bd5
cmpl $0x1c, %eax
jne 0x11c5c
leaq 0x1e1c3(%rip), %rsi     # 0x2fc8e
jmp 0x11bf3
cmpl $0x2, %eax
je 0x11be5
cmpl $0xc, %eax
jne 0x11c5c
movq 0x25507(%rip), %rbx     # 0x36ff0
leaq 0x1e08b(%rip), %rsi     # 0x2fb7b
movl $0x25, %edx
movq %rbx, %rdi
callq 0x43b0
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x4310
jmp 0x11ca3
movq 0x254da(%rip), %rdi     # 0x36ff0
movq 0x8(%rsp), %rsi
callq 0x4310
leaq 0x1e1c4(%rip), %rsi     # 0x2fceb
jmp 0x11b78
movl %eax, %ebx
movq 0x254be(%rip), %rdi     # 0x36ff0
leaq 0x1e0f3(%rip), %rsi     # 0x2fc2c
callq 0x4310
movq %rax, %rdi
movl %ebx, %esi
callq 0x4610
leaq 0x1e1c3(%rip), %rsi     # 0x2fd12
jmp 0x11bab
movq 0x25498(%rip), %rdi     # 0x36ff0
leaq 0x1e15a(%rip), %rsi     # 0x2fcb9
callq 0x4310
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x4310
leaq 0x1e153(%rip), %rsi     # 0x2fccb
movq %rax, %rdi
callq 0x4310
jmp 0x11c57
movl %eax, %ebx
movq 0x25462(%rip), %rdi     # 0x36ff0
leaq 0x1e097(%rip), %rsi     # 0x2fc2c
callq 0x4310
movq %rax, %rdi
movl %ebx, %esi
callq 0x4610
leaq 0x1e1d1(%rip), %rsi     # 0x2fd7c
movq %rax, %rdi
callq 0x4310
movq %rax, %rbx
callq 0x4050
movl (%rax), %esi
movq %rbx, %rdi
jmp 0x11c52
movq 0x25424(%rip), %r13     # 0x36ff0
leaq 0x1dfce(%rip), %rsi     # 0x2fba1
jmp 0x11bf3
movq 0x25414(%rip), %r13     # 0x36ff0
leaq 0x1dfc5(%rip), %rsi     # 0x2fba8
jmp 0x11bf3
movq 0x25404(%rip), %r13     # 0x36ff0
leaq 0x1e094(%rip), %rsi     # 0x2fc87
movl $0x6, %edx
movq %r13, %rdi
callq 0x43b0
jmp 0x11ca6
movl %eax, %ebx
movq 0x253e2(%rip), %rdi     # 0x36ff0
leaq 0x1e017(%rip), %rsi     # 0x2fc2c
callq 0x4310
movq %rax, %rdi
movl %ebx, %esi
callq 0x4610
leaq 0x1e012(%rip), %rsi     # 0x2fc3d
movq %rax, %rdi
callq 0x4310
movl (%r14), %esi
movq %rax, %rdi
callq 0x4610
leaq 0x1e011(%rip), %rsi     # 0x2fc56
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
movl %ebp, %esi
callq 0x4610
movq %rax, %rdi
jmp 0x11ca9
movq 0x2538d(%rip), %rbx     # 0x36ff0
leaq 0x1e02b(%rip), %rsi     # 0x2fc95
movl $0x10, %edx
movq %rbx, %rdi
callq 0x43b0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x4610
movq %rax, %rbx
leaq 0x1e01b(%rip), %rsi     # 0x2fca6
movl $0x12, %edx
movq %rax, %rdi
callq 0x43b0
movl (%r14), %esi
movq %rbx, %rdi
callq 0x4610
movq %rax, %r13
movq %r13, %rdi
callq 0x4150
movl $0x4, %edi
callq 0x4160
movl $0x1, (%rax)
movq 0x25293(%rip), %rsi     # 0x36f58
movq %rax, %rdi
xorl %edx, %edx
callq 0x45f0
nop