// File: /workspace/github_c_makefile_star2_O1/meaning-matters[P]Except/List.c
// Function: ListSplitBefore
List * ListSplitBefore(
        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->pHead->pNext;
        while (pNodeOrg != pListOrg->pNodeLast)
        {
            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->pHead->pNext;
            pListNew->pHead->pNext->pPrev = pListNew->pHead;
            pListNew->pHead->pPrev = pListOrg->pNodeLast->pPrev;
            pListNew->pHead->pPrev->pNext = pListNew->pHead;

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

        pListNew->pNodeLast = NULL;

        return pListNew;
    }

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
testq %rdi, %rdi
jne 0x332b
leaq 0x3f23(%rip), %rax      # 0x7230
movq (%rax), %rdi
leaq 0x10b8(%rip), %rdx      # 0x43cf
leaq 0x1064(%rip), %rcx      # 0x4382
xorl %esi, %esi
movl $0x2ed, %r8d            # imm = 0x2ED
callq 0x2468
cmpl $0x0, 0x10(%rbx)
jle 0x33d5
movq 0x8(%rbx), %r12
testq %r12, %r12
je 0x33f9
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)
movl $0x0, 0x10(%r15)
movq (%rbx), %rcx
movq (%rcx), %rdx
cmpq %r12, %rdx
je 0x33a7
movl 0x10(%rbx), %r8d
movl 0x10(%r13), %edi
movq %rdx, %r9
movl %r8d, %edx
movl %edi, %esi
decl %edx
incl %esi
movq (%r9), %r10
movl %esi, %edi
movl %edx, %r8d
movq %r10, %r9
cmpq %r12, %r10
jne 0x3387
movl %edx, 0x10(%rbx)
movl %esi, 0x10(%r13)
cmpl $0x0, 0x10(%r13)
je 0x346b
movq (%rcx), %rdx
movq %rdx, (%rax)
movq %rax, 0x8(%rdx)
movq 0x8(%r12), %rdx
movq %rdx, 0x8(%rax)
movq %rax, (%rdx)
movq %r12, (%rcx)
movq %rcx, 0x8(%r12)
jmp 0x3472
leaq 0x3e54(%rip), %r14      # 0x7230
movq (%r14), %rdi
leaq 0xffa(%rip), %rdx       # 0x43e0
leaq 0xf95(%rip), %rcx       # 0x4382
xorl %ebx, %ebx
movl %ebx, %esi
movl $0x2ee, %r8d            # imm = 0x2EE
jmp 0x341b
leaq 0x3e30(%rip), %r14      # 0x7230
movq (%r14), %rdi
leaq 0xfea(%rip), %rdx       # 0x43f4
leaq 0xf71(%rip), %rcx       # 0x4382
xorl %ebx, %ebx
movl %ebx, %esi
movl $0x2ef, %r8d            # imm = 0x2EF
callq 0x2468
movq (%r14), %rdi
callq 0x1678
cmpl $-0x1, %eax
je 0x3467
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 0x347f
movq %rbx, %rdi
callq 0x1040
jmp 0x3487
movl %ebx, %eax
jmp 0x3489
movq %rax, (%rax)
movq %rax, 0x8(%rax)
movq $0x0, 0x8(%r13)
movq %r13, %rax
jmp 0x3489
movq (%r14), %rdi
callq 0x1eed
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq