// File: /workspace/github_c_makefile_star2_O2/haxlang[P]hax/haxCkalloc.c
// Function: Hax_DbCkalloc
void *
Hax_DbCkalloc(
    Hax_Memoryp *memoryp,
    unsigned long int size,
    char        *file,
    int          line)
{
    Memoryp           *memCtx = (Memoryp *) memoryp;
    struct mem_header *result;

    if (memCtx->validate_memory)
        Hax_ValidateAllMemory (memoryp, file, line);

    result = (struct mem_header *)malloc(size +
                              sizeof(struct mem_header) + GUARD_SIZE);
    if (result == NULL) {
        dump_memory_info(memCtx);
        Hax_Panic((char *) "unable to alloc %lu bytes, %s line %d", size, file,
              line);
    }

    /*
     * Fill in guard zones and size.  Link into allocated list.
     */
    result->length = size;
    result->file = file;
    result->line = line;
    memset ((char *) result->low_guard, GUARD_VALUE, GUARD_SIZE);
    memset (result->body + size, GUARD_VALUE, GUARD_SIZE);
    result->flink = memCtx->allocHead;
    result->blink = NULL;
    if (memCtx->allocHead != NULL)
        memCtx->allocHead->blink = result;
    memCtx->allocHead = result;

    memCtx->total_mallocs++;
    if (memCtx->trace_on_at_malloc &&
	(memCtx->total_mallocs >= memCtx->trace_on_at_malloc)) {
        printf("reached malloc trace enable point (%lld)\n",
                memCtx->total_mallocs);
        memCtx->alloc_tracing = TRUE;
        memCtx->trace_on_at_malloc = 0;
    }

    if (memCtx->alloc_tracing)
        printf("ckalloc %p %lu %s %d\n", result->body, size,
                file, line);

    if (memCtx->break_on_malloc &&
	(memCtx->total_mallocs >= memCtx->break_on_malloc)) {
        memCtx->break_on_malloc = 0;
        printf("reached malloc break limit (%lld)\n",
                memCtx->total_mallocs);
        printf("program will now enter C debugger\n");
	Hax_Breakpoint();
    }

    memCtx->current_malloc_packets++;
    if (memCtx->current_malloc_packets > memCtx->maximum_malloc_packets)
        memCtx->maximum_malloc_packets = memCtx->current_malloc_packets;
    memCtx->current_bytes_malloced += size;
    if (memCtx->current_bytes_malloced > memCtx->maximum_bytes_malloced)
        memCtx->maximum_bytes_malloced = memCtx->current_bytes_malloced;

    if (memCtx->init_malloced_bodies)
        memset (result->body, 0xff, (int) size);

    return result->body;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebp
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r14
cmpl $0x0, 0x48(%rdi)
je 0x6ad9
movq %r14, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x4300
leaq 0x40(%rbx), %rdi
callq 0x4430
movq %rax, %r13
testq %rax, %rax
jne 0x6b08
movq %r14, %rdi
callq 0x6c3c
leaq 0xc975(%rip), %rdi      # 0x1346e
movq %rbx, %rsi
movq %r12, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x4140
movq %rbx, (%r13)
movq %r12, 0x8(%r13)
movl %ebp, 0x10(%r13)
movabsq $-0x1e1e1e1e1e1e1e1f, %rax # imm = 0xE1E1E1E1E1E1E1E1
movq %rax, 0x28(%r13)
movq %rax, 0x30(%r13,%rbx)
movq (%r14), %rax
movq %rax, 0x18(%r13)
andq $0x0, 0x20(%r13)
testq %rax, %rax
je 0x6b3c
movq %r13, 0x20(%rax)
movq %r13, %r15
addq $0x30, %r15
movq %r13, (%r14)
movq 0x8(%r14), %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movl 0x3c(%r14), %eax
testl %eax, %eax
sete %cl
cltq
cmpq %rax, %rsi
setl %al
orb %cl, %al
je 0x6b6f
cmpl $0x0, 0x40(%r14)
jne 0x6b8b
jmp 0x6ba5
leaq 0xc91e(%rip), %rdi      # 0x13494
xorl %eax, %eax
callq 0x4260
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x3c(%r14)
leaq 0xc92c(%rip), %rdi      # 0x134be
movq %r15, %rsi
movq %rbx, %rdx
movq %r12, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x4260
movslq 0x38(%r14), %rax
testq %rax, %rax
je 0x6bdb
movq 0x8(%r14), %rsi
cmpq %rax, %rsi
jl 0x6bdb
andl $0x0, 0x38(%r14)
leaq 0xc911(%rip), %rdi      # 0x134d4
xorl %eax, %eax
callq 0x4260
leaq 0xcbbd(%rip), %rdi      # 0x1378e
callq 0x4120
callq 0x4290
movq 0x28(%r14), %rax
incq %rax
movq %rax, 0x28(%r14)
cmpq 0x30(%r14), %rax
jbe 0x6bf0
movq %rax, 0x30(%r14)
movq 0x18(%r14), %rax
addq %rbx, %rax
movq %rax, 0x18(%r14)
cmpq 0x20(%r14), %rax
jbe 0x6c05
movq %rax, 0x20(%r14)
cmpl $0x0, 0x44(%r14)
je 0x6c2a
movslq %ebx, %rdx
movq %r15, %rdi
movl $0xff, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42b0
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq