// File: /workspace/github_cpp_makefile_star2_O1/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 0x117ad
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 0x11792
jmp 0x117b0
xorl %r12d, %r12d
movl %r8d, 0x14(%rsp)
testb %r8b, %r8b
je 0x11858
movq 0x2582b(%rip), %rbx     # 0x36ff0
leaq 0x1f2f5(%rip), %rsi     # 0x30ac1
movl $0x8, %edx
movq %rbx, %rdi
callq 0x43b0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x41d0
movq %rax, %rbx
leaq 0x1f2dc(%rip), %rsi     # 0x30aca
movl $0x20, %edx
movq %rax, %rdi
callq 0x43b0
testq %r14, %r14
je 0x11818
movq %r14, %rdi
callq 0x4140
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x43b0
jmp 0x11831
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 0x25783(%rip), %r13     # 0x36ff0
movl %r12d, %edi
movq %r15, %rsi
movl $0x3b6, %edx            # imm = 0x3B6
callq 0x41a0
movl %eax, %ebp
testl %eax, %eax
js 0x119a6
movl %ebp, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4480
testq %rax, %rax
je 0x11d31
movq %rax, %r14
cmpq $-0x1, %rax
je 0x11d73
movl %ebp, %edi
movl $0x2, %esi
leaq 0x28(%rsp), %rdx
callq 0x4260
testl %eax, %eax
js 0x11d4b
cmpq %r15, 0x58(%rsp)
je 0x11ac5
movl $0x2d, %edx
movq %r13, %rdi
leaq 0x1f3c3(%rip), %rsi     # 0x30c9e
callq 0x43b0
movq 0x58(%rsp), %rsi
movq %r13, %rdi
callq 0x41d0
movq %rax, %rbx
movl $0x1f, %edx
movq %rax, %rdi
leaq 0x1f3cd(%rip), %rsi     # 0x30ccc
callq 0x43b0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x41d0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1d9f4(%rip), %rsi     # 0x2f315
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 0x1f20a(%rip), %rsi     # 0x30b69
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 0x1186d
jmp 0x11da7
callq 0x4050
movq %rax, %r14
movl (%rax), %eax
cmpl $0x16, %eax
jne 0x11cc6
movl $0x49, %edx
movq %r13, %rdi
leaq 0x1f157(%rip), %rsi     # 0x30b1f
callq 0x43b0
movq %r13, %rdi
movq %r15, %rsi
callq 0x41d0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1d92b(%rip), %rsi     # 0x2f315
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 0x1f141(%rip), %rsi     # 0x30b69
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 0x11e27
movl $0x24, %edx
movq %r13, %rdi
leaq 0x1f14b(%rip), %rsi     # 0x30bd2
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 0x1186d
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 0x11b81
cmpb $0x0, 0x14(%rsp)
je 0x11c30
movq 0x254e6(%rip), %r15     # 0x36ff0
leaq 0x1f1f7(%rip), %rsi     # 0x30d08
movl $0xb, %edx
movq %r15, %rdi
callq 0x43b0
callq 0x44c0
movq %r15, %rdi
movl %eax, %esi
callq 0x4610
movq %rax, %r15
leaq 0x1f1dd(%rip), %rsi     # 0x30d14
movl $0xe, %edx
movq %rax, %rdi
callq 0x43b0
leaq 0x1f1ed(%rip), %rsi     # 0x30d38
movl $0x12, %edx
movq %r15, %rdi
callq 0x43b0
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0x11bef
movq %r12, %rdi
callq 0x4140
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x43b0
jmp 0x11c09
cmpb $0x0, 0x14(%rsp)
je 0x11cb2
movq 0x2545d(%rip), %r14     # 0x36ff0
leaq 0x1f16e(%rip), %rsi     # 0x30d08
movl $0xb, %edx
movq %r14, %rdi
callq 0x43b0
callq 0x44c0
movq %r14, %rdi
movl %eax, %esi
callq 0x4610
movq %rax, %r14
leaq 0x1f163(%rip), %rsi     # 0x30d23
movl $0x27, %edx
movq %rax, %rdi
callq 0x43b0
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x11c3a
movq %r15, %rdi
callq 0x4140
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x43b0
jmp 0x11c54
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 0x11cb2
movq (%r14), %rax
movq -0x18(%rax), %rax
movq %r14, %rdi
addq %rax, %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x45e0
leaq 0x1f0f0(%rip), %rsi     # 0x30d4b
movl $0x7, %edx
movq %r14, %rdi
callq 0x43b0
movl 0x78(%rsp), %esi
movq %r14, %rdi
callq 0x4610
movq %rax, %r14
leaq 0x1f0d5(%rip), %rsi     # 0x30d53
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 0x11cf2
cmpl $0xd, %eax
je 0x11de7
cmpl $0x11, %eax
je 0x11df7
cmpl $0x1c, %eax
jne 0x11e7e
leaq 0x1ef11(%rip), %rsi     # 0x30bfe
jmp 0x11e15
cmpl $0x2, %eax
je 0x11e07
cmpl $0xc, %eax
jne 0x11e7e
movq 0x252e5(%rip), %rbx     # 0x36ff0
leaq 0x1edd9(%rip), %rsi     # 0x30aeb
movl $0x25, %edx
movq %rbx, %rdi
callq 0x43b0
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x4310
jmp 0x11ec5
movq 0x252b8(%rip), %rdi     # 0x36ff0
movq 0x8(%rsp), %rsi
callq 0x4310
leaq 0x1ef12(%rip), %rsi     # 0x30c5b
jmp 0x11d9a
movl %eax, %ebx
movq 0x2529c(%rip), %rdi     # 0x36ff0
leaq 0x1ee41(%rip), %rsi     # 0x30b9c
callq 0x4310
movq %rax, %rdi
movl %ebx, %esi
callq 0x4610
leaq 0x1ef11(%rip), %rsi     # 0x30c82
jmp 0x11dcd
movq 0x25276(%rip), %rdi     # 0x36ff0
leaq 0x1eea8(%rip), %rsi     # 0x30c29
callq 0x4310
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x4310
leaq 0x1eea1(%rip), %rsi     # 0x30c3b
movq %rax, %rdi
callq 0x4310
jmp 0x11e79
movl %eax, %ebx
movq 0x25240(%rip), %rdi     # 0x36ff0
leaq 0x1ede5(%rip), %rsi     # 0x30b9c
callq 0x4310
movq %rax, %rdi
movl %ebx, %esi
callq 0x4610
leaq 0x1ef1f(%rip), %rsi     # 0x30cec
movq %rax, %rdi
callq 0x4310
movq %rax, %rbx
callq 0x4050
movl (%rax), %esi
movq %rbx, %rdi
jmp 0x11e74
movq 0x25202(%rip), %r13     # 0x36ff0
leaq 0x1ed1c(%rip), %rsi     # 0x30b11
jmp 0x11e15
movq 0x251f2(%rip), %r13     # 0x36ff0
leaq 0x1ed13(%rip), %rsi     # 0x30b18
jmp 0x11e15
movq 0x251e2(%rip), %r13     # 0x36ff0
leaq 0x1ede2(%rip), %rsi     # 0x30bf7
movl $0x6, %edx
movq %r13, %rdi
callq 0x43b0
jmp 0x11ec8
movl %eax, %ebx
movq 0x251c0(%rip), %rdi     # 0x36ff0
leaq 0x1ed65(%rip), %rsi     # 0x30b9c
callq 0x4310
movq %rax, %rdi
movl %ebx, %esi
callq 0x4610
leaq 0x1ed60(%rip), %rsi     # 0x30bad
movq %rax, %rdi
callq 0x4310
movl (%r14), %esi
movq %rax, %rdi
callq 0x4610
leaq 0x1ed5f(%rip), %rsi     # 0x30bc6
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
movl %ebp, %esi
callq 0x4610
movq %rax, %rdi
jmp 0x11ecb
movq 0x2516b(%rip), %rbx     # 0x36ff0
leaq 0x1ed79(%rip), %rsi     # 0x30c05
movl $0x10, %edx
movq %rbx, %rdi
callq 0x43b0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x4610
movq %rax, %rbx
leaq 0x1ed69(%rip), %rsi     # 0x30c16
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 0x25071(%rip), %rsi     # 0x36f58
movq %rax, %rdi
xorl %edx, %edx
callq 0x45f0
nop