// File: /workspace/github_c_makefile_star2_O3/weaslepalace[P]FreeRTOS_Posix_Sim/AsyncIO/PosixMessageQueueIPC.c
// Function: xPosixIPCOpen
mqd_t xPosixIPCOpen( const portCHAR *pcPipeName, void (*vMessageInterruptHandler)(xMessageObject,void*), void *pvContext )
{
mqd_t hPipeHandle;
struct sigaction sigrt;

	hPipeHandle = mq_open( pcPipeName, O_RDWR | O_CREAT | O_NONBLOCK, S_IRUSR | S_IWUSR, NULL );
	if ( -1 == hPipeHandle )
	{
		hPipeHandle = mq_unlink( pcPipeName );
		hPipeHandle = 0;
		printf( "Problem opening message pipe.\n" );
	}
	else
	{
		printf( "Pipe Open: %s\n", pcPipeName );
	}

	/* If this is a receive pipe then we set-up the interrupt handler. */
	if ( ( 0 != hPipeHandle ) && ( NULL != vMessageInterruptHandler ) )
	{
		/* Establish the signal handler. */
		sigrt.sa_flags = SA_SIGINFO;						/* Need some information to be passed. */
		sigrt.sa_handler = (__sighandler_t)prvPosixIPCInterruptHandler;		/* This is the function to call. */
		sigfillset( &sigrt.sa_mask );
		sigdelset( &sigrt.sa_mask, SIG_MSG_RX );
		sigdelset( &sigrt.sa_mask, SIG_TICK );

		if ( 0 != sigaction( SIG_MSG_RX, &sigrt, NULL ) )	/* Register the Signal Handler. */
		{
			printf( "Problem installing SIG_MSG_RT\n" );
		}		/* Parameters to the signal handler. */

		/* No establish the notify parameters. */
		xActualParameters.hPipe = hPipeHandle;
		xActualParameters.pvFunction = vMessageInterruptHandler;
		xActualParameters.pvContext = pvContext;
		xParameters.sival_ptr = &xActualParameters;

		/* Set-up the notifcation. */
		xMessageEvent.sigev_notify = SIGEV_SIGNAL;				/* How to signal. */
		xMessageEvent.sigev_signo = SIG_MSG_RX;					/* Signal number to use. */
		xMessageEvent.sigev_value = xParameters;				/* Parameters to pass to the signal handler. */
		xMessageEvent.sigev_notify_function = NULL;				/* Signal handler function. */
		xMessageEvent.sigev_notify_attributes = NULL;			/* Parameters if a new thread is created to execute the signal handler. */

		/* Register the notification. */
		if ( 0 != mq_notify( hPipeHandle, &xMessageEvent ) )
		{
			printf( "Failed to install Rx interrupt handler: %d.\n", errno );
		}
	}
	return hPipeHandle;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r13
xorl %r12d, %r12d
movl $0x842, %esi            # imm = 0x842
movl $0x180, %edx            # imm = 0x180
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x4360
cmpl $-0x1, %eax
je 0x80b9
movl %eax, %ebx
leaq 0x12b3(%rip), %rdi      # 0x9288
movq %r13, %rsi
xorl %eax, %eax
callq 0x4170
testl %ebx, %ebx
sete %al
testq %r15, %r15
sete %cl
orb %al, %cl
jne 0x80b4
leaq -0xb8(%rbp), %r12
movl $0x4, 0x80(%r12)
leaq 0xd6(%rip), %rax        # 0x80e2
movq %rax, -0x8(%r12)
movq %r12, %rdi
callq 0x4340
movq %r12, %rdi
movl $0x22, %esi
callq 0x45e0
movq %r12, %rdi
movl $0xe, %esi
callq 0x45e0
leaq -0xc0(%rbp), %rsi
movl $0x22, %edi
xorl %edx, %edx
callq 0x40f0
testl %eax, %eax
je 0x8056
leaq 0x12a1(%rip), %rdi      # 0x92f2
callq 0x40c0
movl %ebx, 0x4d04(%rip)      # 0xcd60
leaq 0x4cfd(%rip), %rax      # 0xcd60
movq %r15, 0x4cfe(%rip)      # 0xcd68
movq %r14, 0x4cff(%rip)      # 0xcd70
leaq 0x4d00(%rip), %rsi      # 0xcd78
movq $0x22, 0x4cfd(%rip) # 0xcd80
movq %rax, 0x4cee(%rip)      # 0xcd78
xorps %xmm0, %xmm0
movups %xmm0, 0x4cf4(%rip)     # 0xcd88
movl %ebx, %edi
callq 0x4610
testl %eax, %eax
je 0x80b4
callq 0x40a0
movl (%rax), %esi
leaq 0x11fa(%rip), %rdi      # 0x92a7
xorl %eax, %eax
callq 0x4170
movl %ebx, %r12d
jmp 0x80cd
movq %r13, %rdi
callq 0x46d0
leaq 0x120c(%rip), %rdi      # 0x92d4
callq 0x40c0
movl %r12d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq