// File: /workspace/github_c_makefile_star2_O3/serge-404[P]CPM32/cpm.c
// Function: frameup_dpb_alloc
void frameup_dpb_alloc( void)
{
    DWORD spc, bps, free, total;
    DWORD *alloc = (DWORD *)(mem + DMY_ALLOC);
    byte sft;
    int i;

    GetDiskFreeSpace( NULL, &spc, &bps, &free, &total);
    spc *= bps;
    spc >>= 9; sft = 2;
    /* 2008.12 for large disk space (> 2TBytes) */
    while ( spc && (spc & 1) == 0) { spc >>= 1; sft++; }
    free *= spc;
    while ( free > MAXBLK) { free >>= 1; sft++; }
    mem[ DMY_DPB_SFT] = sft;
    *(word *)(mem + DMY_DPB_MSK) = (word)((1 << sft) - 1);

    i = 0;
    while ( free >= 32) {
        free -= 32; alloc[ i++] = 0;
    }
    alloc[ i++] = ~0 << free;
    while ( i < MAXBLK/32) alloc[ i++] = ~0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x70, %rsp
movq 0x9f8b(%rip), %r15      # 0x141f0
movq %rsp, %rsi
xorl %edi, %edi
callq 0x22d0
testl %eax, %eax
je 0xa279
movb $0x2, %cl
xorl %eax, %eax
jmp 0xa2c5
movq 0x8(%rsp), %rsi
movq 0x20(%rsp), %rdi
movq %rsi, %rax
xorl %edx, %edx
divq (%rsp)
subq %rdx, %rsi
movq %rsi, %rax
shrq $0x9, %rax
cmpq $0x200, %rsi            # imm = 0x200
setb %dl
shrl $0x9, %esi
andl $0x1, %esi
movb $0x2, %cl
orb %dl, %sil
jne 0xa2c5
movq %rax, %rdx
shrq %rdx
incb %cl
testq %rax, %rax
je 0xa2c2
andl $0x2, %eax
movq %rdx, %rax
je 0xa2b0
movq %rdx, %rax
imulq %rax, %rdi
cmpq $0x401, %rdi            # imm = 0x401
jb 0xa2e8
movq %rdi, %r14
shrq %r14
incb %cl
cmpq $0x801, %rdi            # imm = 0x801
movq %r14, %rdi
ja 0xa2d5
jmp 0xa2eb
movq %rdi, %r14
leaq 0xff20(%r15), %rbx
movq 0x9ef7(%rip), %rdx      # 0x141f0
movb %cl, 0xff12(%rdx)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
shll %cl, %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
notl %esi
movw %si, 0xff13(%rdx)
cmpq $0x1f, %r14
jbe 0xa404
leaq -0x20(%r14), %r13
movq %r13, %r12
shrq $0x5, %r12
leaq 0x8(,%r12,8), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2150
leaq 0x2(%r12), %rax
andq $-0x2, %rax
movq %r14, %xmm0
movq %r13, %xmm1
pshufd $0x44, %xmm1, %xmm2     # xmm2 = xmm1[0,1,0,1]
psrlq $0x5, %xmm2
movl $0x2, %ecx
movdqa 0x69db(%rip), %xmm3     # 0x10d40
movdqa %xmm0, %xmm1
paddq %xmm3, %xmm0
leaq (%rax,%rcx), %rdx
addq $-0x2, %rdx
addq $-0x2, %rcx
cmpq $0x2, %rdx
jne 0xa365
negq %rcx
movq %rcx, %xmm3
pshufd $0x44, %xmm3, %xmm3     # xmm3 = xmm3[0,1,0,1]
por 0x69bc(%rip), %xmm3     # 0x10d50
movdqa 0x69c4(%rip), %xmm4     # 0x10d60
pxor %xmm4, %xmm2
pxor %xmm4, %xmm3
movdqa %xmm3, %xmm4
pcmpgtd %xmm2, %xmm4
pshufd $0xa0, %xmm4, %xmm5     # xmm5 = xmm4[0,0,2,2]
pcmpeqd %xmm2, %xmm3
pshufd $0xf5, %xmm3, %xmm2     # xmm2 = xmm3[1,1,3,3]
pand %xmm5, %xmm2
pshufd $0xf5, %xmm4, %xmm3     # xmm3 = xmm4[1,1,3,3]
por %xmm2, %xmm3
pand %xmm3, %xmm1
pandn %xmm0, %xmm3
por %xmm1, %xmm3
pshufd $0xee, %xmm3, %xmm0     # xmm0 = xmm3[2,3,2,3]
paddq %xmm3, %xmm0
movd %xmm0, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
incl %r12d
cltq
movq %rax, (%rbx,%r12,8)
cmpl $0x1e, %r12d
jbe 0xa411
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movl %r14d, %ecx
shll %cl, %eax
cltq
movq %rax, (%rbx)
xorl %r12d, %r12d
leaq (%r15,%r12,8), %rdi
addq $0xff28, %rdi           # imm = 0xFF28
shll $0x3, %r12d
movl $0xf0, %edx
subl %r12d, %edx
addq $0x8, %rdx
movl $0xff, %esi
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x2150