// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
testq %rdi, %rdi
jne 0x33f5
leaq 0x3e59(%rip), %rax      # 0x7230
movq (%rax), %rdi
leaq 0xfee(%rip), %rdx       # 0x43cf
leaq 0xf9a(%rip), %rcx       # 0x4382
xorl %esi, %esi
movl $0x333, %r8d            # imm = 0x333
callq 0x23ec
movl 0x10(%rbx), %ebp
testl %ebp, %ebp
jle 0x347b
movq 0x8(%rbx), %r12
testq %r12, %r12
je 0x349f
pushq $0x18
popq %r14
movq %r14, %rdi
callq 0x10c0
movq %rax, %r15
movq %rax, %r13
movq %r14, %rdi
callq 0x10c0
andq $0x0, 0x10(%rax)
movq %rax, (%r15)
movq (%rbx), %rcx
decl %ebp
xorl %esi, %esi
movq %r12, %rdx
movq (%rdx), %rdx
cmpq %rcx, %rdx
je 0x344c
movl %esi, %edi
movl %ebp, %r8d
addl %r8d, %edi
movl %edi, 0x10(%rbx)
decl %esi
jmp 0x3435
negl %esi
movl %esi, 0x10(%r13)
jae 0x350f
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 0x3516
leaq 0x3dae(%rip), %r14      # 0x7230
movq (%r14), %rdi
leaq 0xf54(%rip), %rdx       # 0x43e0
leaq 0xeef(%rip), %rcx       # 0x4382
xorl %ebx, %ebx
movl %ebx, %esi
movl $0x334, %r8d            # imm = 0x334
jmp 0x34c1
leaq 0x3d8a(%rip), %r14      # 0x7230
movq (%r14), %rdi
leaq 0xf44(%rip), %rdx       # 0x43f4
leaq 0xecb(%rip), %rcx       # 0x4382
xorl %ebx, %ebx
movl %ebx, %esi
movl $0x335, %r8d            # imm = 0x335
callq 0x23ec
movq (%r14), %rdi
callq 0x1618
cmpl $-0x1, %eax
je 0x350b
movl $0xc8, %edi
callq 0x10c0
movq %rax, %rbx
movq (%r14), %rdi
callq 0x164c
movq (%rax), %rax
movq %rbx, 0x1a0(%rax)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x1130
testl %eax, %eax
je 0x3520
movq %rbx, %rdi
callq 0x1040
jmp 0x3528
movl %ebx, %eax
jmp 0x352a
movq %rax, (%rax)
movq %rax, 0x8(%rax)
andq $0x0, 0x8(%r13)
movq %r13, %rax
jmp 0x352a
movq (%r14), %rdi
callq 0x1ea8
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq