// File: rofl0r[P]ascc/cs_parser.cpp
// Function: free_pointers_from_struct(int, ccCompiledScript*)
void free_pointers_from_struct(int structVarSym, ccCompiledScript *scrip) {
    int structType = sym.entries[structVarSym].vartype;

    for (int dd = 0; (size_t)dd < sym.entries.size(); dd++) {
        if ((sym.entries[dd].stype == SYM_STRUCTMEMBER) &&
            (sym.entries[dd].extends == structType) &&
            ((sym.entries[dd].flags & SFLG_IMPORTED) == 0) &&
            ((sym.entries[dd].flags & SFLG_PROPERTY) == 0)) {

                if (sym.entries[dd].flags & SFLG_POINTER) {
                    int spOffs = (scrip->cur_sp - sym.entries[structVarSym].soffs) - sym.entries[dd].soffs;

                    free_pointer(spOffs, SCMD_MEMZEROPTR, dd, scrip);

                    if (sym.entries[structVarSym].flags & SFLG_ARRAY) {
                        // an array of structs, free any pointers in them
                        for (int ii = 1; ii < sym.entries[structVarSym].arrsize; ii++) {
                            spOffs -= sym.entries[structType].ssize;
                            free_pointer(spOffs, SCMD_MEMZEROPTR, dd, scrip);
                        }
                    }
                }
                else {
                    // non-pointer struct, need to procss its members
                    // **** TODO

                }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movslq -0x4(%rbp), %rsi
leaq 0x3b536(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movswl 0x30(%rax), %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movslq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq 0x3b510(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e80
movq %rax, %rcx
movq -0x28(%rbp), %rax
cmpq %rcx, %rax
jae 0x754a
movslq -0x18(%rbp), %rsi
leaq 0x3b4ec(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movswl 0x20(%rax), %eax
cmpl $0xa, %eax
jne 0x753a
movslq -0x18(%rbp), %rsi
leaq 0x3b4cb(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movswl 0x50(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x753a
movslq -0x18(%rbp), %rsi
leaq 0x3b4aa(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x4, %rax
cmpq $0x0, %rax
jne 0x753a
movslq -0x18(%rbp), %rsi
leaq 0x3b484(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x200, %rax            # imm = 0x200
cmpq $0x0, %rax
jne 0x753a
movslq -0x18(%rbp), %rsi
leaq 0x3b45c(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x100, %rax            # imm = 0x100
cmpq $0x0, %rax
je 0x7536
movq -0x10(%rbp), %rax
movq 0x8d40(%rax), %rax
movq %rax, -0x38(%rbp)
movslq -0x4(%rbp), %rsi
leaq 0x3b425(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq %rax, %rcx
movq -0x38(%rbp), %rax
movslq 0x34(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x30(%rbp)
movslq -0x18(%rbp), %rsi
leaq 0x3b3ff(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq %rax, %rcx
movq -0x30(%rbp), %rax
movslq 0x34(%rcx), %rcx
subq %rcx, %rax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %edi
movl -0x18(%rbp), %edx
movq -0x10(%rbp), %rcx
movl $0x31, %esi
callq 0x7200
movslq -0x4(%rbp), %rsi
leaq 0x3b3c6(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x2, %rax
cmpq $0x0, %rax
je 0x7534
movl $0x1, -0x20(%rbp)
movslq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movslq -0x4(%rbp), %rsi
leaq 0x3b395(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq %rax, %rcx
movq -0x40(%rbp), %rax
cmpq 0x48(%rcx), %rax
jge 0x7532
movslq -0x14(%rbp), %rsi
leaq 0x3b374(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x38(%rax), %rcx
movslq -0x1c(%rbp), %rax
subq %rcx, %rax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %edi
movl -0x18(%rbp), %edx
movq -0x10(%rbp), %rcx
movl $0x31, %esi
callq 0x7200
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x74c8
jmp 0x7534
jmp 0x7538
jmp 0x7538
jmp 0x753a
jmp 0x753c
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x7351
addq $0x40, %rsp
popq %rbp
retq