// File: /workspace/github_c_makefile_star2_O2/haxlang[P]hax/haxCkalloc.c
// Function: ValidateMemory
static void
ValidateMemory (
    Memoryp           *memoryp,
    struct mem_header *memHeaderP,
    char              *file,
    int                line,
    int                nukeGuards)
{
    unsigned char *hiPtr;
    int   idx;
    int   guard_failed = FALSE;
    int byte;

    for (idx = 0; idx < GUARD_SIZE; idx++) {
        byte = *(memHeaderP->low_guard + idx);
        if (byte != GUARD_VALUE) {
            guard_failed = TRUE;
	    byte &= 0xff;
            printf("low guard byte %d is 0x%x  \t%c\n", idx, byte,
	    	    (isprint(byte) ? byte : ' '));
        }
    }
    if (guard_failed) {
        dump_memory_info (memoryp);
        printf ("low guard failed at %p, %s %d\n",
                 memHeaderP->body, file, line);
        printf ("%lu bytes allocated at (%s %d)\n", memHeaderP->length,
		memHeaderP->file, memHeaderP->line);
        Hax_Panic ((char *) "Memory validation failure");
    }

    hiPtr = (unsigned char *)memHeaderP->body + memHeaderP->length;
    for (idx = 0; idx < GUARD_SIZE; idx++) {
        byte = *(hiPtr + idx);
        if (byte != GUARD_VALUE) {
            guard_failed = TRUE;
	    byte &= 0xff;
            printf("hi guard byte %d is 0x%x  \t%c\n", idx, byte,
	    	    (isprint(byte) ? byte : ' '));
        }
    }

    if (guard_failed) {
        dump_memory_info (memoryp);
        printf ("high guard failed at %p, %s %d\n",
                 memHeaderP->body, file, line);
        printf ("%lu bytes allocated at (%s %d)\n", memHeaderP->length,
		memHeaderP->file, memHeaderP->line);
        Hax_Panic ((char *) "Memory validation failure");
    }

    if (nukeGuards) {
        memset ((char *) memHeaderP->low_guard, 0, GUARD_SIZE);
        memset ((char *) hiPtr, 0, GUARD_SIZE);
    }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, 0xc(%rsp)
movl %ecx, 0x8(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, %rbx
movq %rdi, 0x10(%rsp)
leaq 0xcc8c(%rip), %r15      # 0x13540
pushq $0x1
popq %r12
xorl %ebp, %ebp
xorl %r13d, %r13d
cmpq $0x8, %rbp
je 0x6904
movzbl 0x28(%rbx,%rbp), %r14d
cmpl $0xe1, %r14d
je 0x68ff
callq 0x4660
movq (%rax), %rax
movl %r14d, %ecx
movzwl (%rax,%rcx,2), %eax
btl $0xe, %eax
pushq $0x20
popq %rcx
jae 0x68ed
movl %r14d, %ecx
movq %r15, %rdi
movl %ebp, %esi
movl %r14d, %edx
xorl %eax, %eax
callq 0x4260
movl %r12d, %r13d
incq %rbp
jmp 0x68bd
testl %r13d, %r13d
je 0x6954
movq 0x10(%rsp), %rdi
callq 0x6c3c
leaq 0x30(%rbx), %rsi
leaq 0xcc42(%rip), %rdi      # 0x13560
movq 0x18(%rsp), %rdx
movl 0x8(%rsp), %ecx
xorl %eax, %eax
callq 0x4260
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movl 0x10(%rbx), %ecx
leaq 0xcc40(%rip), %rdi      # 0x1357f
xorl %eax, %eax
callq 0x4260
leaq 0xcc52(%rip), %rdi      # 0x1359f
xorl %eax, %eax
callq 0x4140
leaq 0x30(%rbx), %rax
movq (%rbx), %r12
movq %rax, 0x20(%rsp)
addq %rax, %r12
pushq $0x1
popq %rbp
xorl %r14d, %r14d
cmpq $0x8, %r14
je 0x69b4
movzbl (%r12,%r14), %r15d
cmpl $0xe1, %r15d
je 0x69af
callq 0x4660
movq (%rax), %rax
movl %r15d, %ecx
movzwl (%rax,%rcx,2), %eax
btl $0xe, %eax
pushq $0x20
popq %rcx
jae 0x6998
movl %r15d, %ecx
leaq 0xcc1a(%rip), %rdi      # 0x135b9
movl %r14d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x4260
movl %ebp, %r13d
incq %r14
jmp 0x6969
testl %r13d, %r13d
je 0x6a05
movq 0x10(%rsp), %rdi
callq 0x6c3c
leaq 0xcc0e(%rip), %rdi      # 0x135d8
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl 0x8(%rsp), %ecx
xorl %eax, %eax
callq 0x4260
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movl 0x10(%rbx), %ecx
leaq 0xcb8f(%rip), %rdi      # 0x1357f
xorl %eax, %eax
callq 0x4260
leaq 0xcba1(%rip), %rdi      # 0x1359f
xorl %eax, %eax
callq 0x4140
cmpl $0x0, 0xc(%rsp)
je 0x6a16
andq $0x0, 0x28(%rbx)
andq $0x0, (%r12)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq