// File: /workspace/github_c_makefile_star2_O0/weaslepalace[P]FreeRTOS_Posix_Sim/FreeRTOS_Kernel/croutine.c
// Function: xCoRoutineCreate
signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex )
{
signed portBASE_TYPE xReturn;
corCRCB *pxCoRoutine;

	/* Allocate the memory that will store the co-routine control block. */
	pxCoRoutine = ( corCRCB * ) pvPortMalloc( sizeof( corCRCB ) );
	if( pxCoRoutine )
	{
		/* If pxCurrentCoRoutine is NULL then this is the first co-routine to
		be created and the co-routine data structures need initialising. */
		if( pxCurrentCoRoutine == NULL )
		{
			pxCurrentCoRoutine = pxCoRoutine;
			prvInitialiseCoRoutineLists();
		}

		/* Check the priority is within limits. */
		if( uxPriority >= configMAX_CO_ROUTINE_PRIORITIES )
		{
			uxPriority = configMAX_CO_ROUTINE_PRIORITIES - 1;
		}

		/* Fill out the co-routine control block from the function parameters. */
		pxCoRoutine->uxState = corINITIAL_STATE;
		pxCoRoutine->uxPriority = uxPriority;
		pxCoRoutine->uxIndex = uxIndex;
		pxCoRoutine->pxCoRoutineFunction = pxCoRoutineCode;

		/* Initialise all the other co-routine control block parameters. */
		vListInitialiseItem( &( pxCoRoutine->xGenericListItem ) );
		vListInitialiseItem( &( pxCoRoutine->xEventListItem ) );

		/* Set the co-routine control block as a link back from the xListItem.
		This is so we can get back to the containing CRCB from a generic item
		in a list. */
		listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine );
		listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine );
	
		/* Event lists are always in priority order. */
		listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxPriority );
		
		/* Now the co-routine has been initialised it can be added to the ready
		list at the correct priority. */
		prvAddCoRoutineToReadyQueue( pxCoRoutine );

		xReturn = pdPASS;
	}
	else
	{		
		xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;
	}
	
	return xReturn;	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x70, %edi
callq 0x42f0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x49d4
movq 0x96ec(%rip), %rax      # 0xdfd0
cmpq $0x0, (%rax)
jne 0x48fd
movq -0x28(%rbp), %rcx
movq 0x96db(%rip), %rax      # 0xdfd0
movq %rcx, (%rax)
callq 0x44b0
cmpq $0x2, -0x10(%rbp)
jb 0x490c
movq $0x1, -0x10(%rbp)
movq -0x28(%rbp), %rax
movw $0x0, 0x68(%rax)
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x8(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
callq 0x4050
movq -0x28(%rbp), %rdi
addq $0x30, %rdi
callq 0x4050
movq -0x28(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
movl %eax, %eax
movl %eax, %ecx
movl $0xa, %eax
subq %rcx, %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movq 0x95e5(%rip), %rcx      # 0xdf78
cmpq (%rcx), %rax
jbe 0x49aa
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rcx
movq 0x95d1(%rip), %rax      # 0xdf78
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq 0x94eb(%rip), %rdi      # 0xdea0
imulq $0x28, 0x58(%rax), %rax
addq %rax, %rdi
movq -0x28(%rbp), %rsi
addq $0x8, %rsi
callq 0x4760
movq $0x1, -0x20(%rbp)
jmp 0x49dc
movq $-0x1, -0x20(%rbp)
movq -0x20(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)