// File: /workspace/github_c_makefile_star2_O2/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 0x4380
cmpl $-0x1, %eax
je 0x7e07
movl %eax, %ebx
leaq 0x563(%rip), %rdi       # 0x8288
movq %r13, %rsi
xorl %eax, %eax
callq 0x4190
testl %ebx, %ebx
sete %al
testq %r15, %r15
sete %cl
orb %al, %cl
jne 0x7e02
leaq -0xb8(%rbp), %r12
movl $0x4, 0x80(%r12)
leaq 0xd4(%rip), %rax        # 0x7e30
movq %rax, -0x8(%r12)
movq %r12, %rdi
callq 0x4360
pushq $0x22
popq %r13
movq %r12, %rdi
movl %r13d, %esi
callq 0x4610
pushq $0xe
popq %rsi
movq %r12, %rdi
callq 0x4610
leaq -0xc0(%rbp), %rsi
movl %r13d, %edi
xorl %edx, %edx
callq 0x40f0
testl %eax, %eax
je 0x7da4
leaq 0x553(%rip), %rdi       # 0x82f2
callq 0x40c0
movl %ebx, 0x3fd6(%rip)      # 0xbd80
leaq 0x3fcf(%rip), %rax      # 0xbd80
movq %r15, 0x3fd0(%rip)      # 0xbd88
movq %r14, 0x3fd1(%rip)      # 0xbd90
leaq 0x3fd2(%rip), %rsi      # 0xbd98
movq $0x22, 0x3fcf(%rip) # 0xbda0
movq %rax, 0x3fc0(%rip)      # 0xbd98
xorps %xmm0, %xmm0
movups %xmm0, 0x3fc6(%rip)     # 0xbda8
movl %ebx, %edi
callq 0x4640
testl %eax, %eax
je 0x7e02
callq 0x40a0
movl (%rax), %esi
leaq 0x4ac(%rip), %rdi       # 0x82a7
xorl %eax, %eax
callq 0x4190
movl %ebx, %r12d
jmp 0x7e1b
movq %r13, %rdi
callq 0x4700
leaq 0x4be(%rip), %rdi       # 0x82d4
callq 0x40c0
movl %r12d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq