// File: /workspace/github_c_makefile_star2_O1/meaning-matters[P]Except/List.c
// Function: ListSplitAfter
List * ListSplitAfter(
        List *      pListOrg)       /* pointer to original list */
    {
        List *      pListNew;
        ListNode *  pNodeOrg;

        assert(pListOrg != NULL);
        validate(pListOrg->count > 0, NULL);
        validate(pListOrg->pNodeLast != NULL, NULL);

        pListNew = malloc(sizeof(List));

        pListNew->pHead = malloc(sizeof(ListNode));
        pListNew->pHead->pData = NULL;
        pListNew->count = 0;

        pNodeOrg = pListOrg->pNodeLast->pNext;
        while (pNodeOrg != pListOrg->pHead)
        {
            pListOrg->count--;
            pListNew->count++;

            pNodeOrg = pNodeOrg->pNext;
        }

        if (pListNew->count == 0)
        {
            pListNew->pHead->pPrev = pListNew->pHead->pNext = pListNew->pHead;
        }
        else
        {
            /* connect list part to new list */
            pListNew->pHead->pNext = pListOrg->pNodeLast->pNext;
            pListNew->pHead->pNext->pPrev = pListNew->pHead;
            pListNew->pHead->pPrev = pListOrg->pHead->pPrev;
            pListNew->pHead->pPrev->pNext = pListNew->pHead;

            /* bind last accessed node and original dummy node together */
            pListOrg->pNodeLast->pNext = pListOrg->pHead;
            pListOrg->pHead->pPrev = pListOrg->pNodeLast;
        }

        pListNew->pNodeLast = NULL;

        return pListNew;
    }

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
testq %rdi, %rdi
jne 0x34c9
leaq 0x3d85(%rip), %rax      # 0x7230
movq (%rax), %rdi
leaq 0xf1a(%rip), %rdx       # 0x43cf
leaq 0xec6(%rip), %rcx       # 0x4382
xorl %esi, %esi
movl $0x333, %r8d            # imm = 0x333
callq 0x2468
cmpl $0x0, 0x10(%rbx)
jle 0x3532
movq 0x8(%rbx), %r12
testq %r12, %r12
je 0x3556
movl $0x18, %r14d
movq %r14, %rdi
callq 0x10c0
movq %rax, %r15
movq %rax, %r13
movq %r14, %rdi
callq 0x10c0
movq %rax, (%r15)
movq $0x0, 0x10(%rax)
movq (%rbx), %rcx
movq (%r12), %rdi
cmpq %rcx, %rdi
je 0x35c8
movl 0x10(%rbx), %edx
xorl %r8d, %r8d
movl %r8d, %esi
incl %esi
movq (%rdi), %r9
movq %r9, %rdi
movl %esi, %r8d
cmpq %rcx, %r9
jne 0x3515
subl %esi, %edx
movl %edx, 0x10(%rbx)
jmp 0x35ca
leaq 0x3cf7(%rip), %r14      # 0x7230
movq (%r14), %rdi
leaq 0xe9d(%rip), %rdx       # 0x43e0
leaq 0xe38(%rip), %rcx       # 0x4382
xorl %ebx, %ebx
movl %ebx, %esi
movl $0x334, %r8d            # imm = 0x334
jmp 0x3578
leaq 0x3cd3(%rip), %r14      # 0x7230
movq (%r14), %rdi
leaq 0xe8d(%rip), %rdx       # 0x43f4
leaq 0xe14(%rip), %rcx       # 0x4382
xorl %ebx, %ebx
movl %ebx, %esi
movl $0x335, %r8d            # imm = 0x335
callq 0x2468
movq (%r14), %rdi
callq 0x1678
cmpl $-0x1, %eax
je 0x35c4
movl $0xc8, %edi
callq 0x10c0
movq %rax, %rbx
movq (%r14), %rdi
callq 0x16ae
movq (%rax), %rax
movq %rbx, 0x1a0(%rax)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x1130
testl %eax, %eax
je 0x3606
movq %rbx, %rdi
callq 0x1040
jmp 0x360e
movl %ebx, %eax
jmp 0x3610
xorl %esi, %esi
movl %esi, 0x10(%r13)
testl %esi, %esi
je 0x35f2
movq (%r12), %rdx
movq %rdx, (%rax)
movq %rax, 0x8(%rdx)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq %rax, (%rdx)
movq %rcx, (%r12)
movq %r12, 0x8(%rcx)
jmp 0x35f9
movq %rax, (%rax)
movq %rax, 0x8(%rax)
movq $0x0, 0x8(%r13)
movq %r13, %rax
jmp 0x3610
movq (%r14), %rdi
callq 0x1eed
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq