// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %rsi, %rbx
movq %rdi, %r14
cmpl $0x0, 0x48(%rdi)
je 0x7062
movq (%r14), %r12
testq %r12, %r12
je 0x7062
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x6dc9
movq 0x18(%r12), %r12
jmp 0x7043
leaq 0x40(%rbx), %rdi
callq 0x4420
movq %rax, %r13
testq %rax, %rax
jne 0x7091
movq %r14, %rdi
callq 0x71cb
leaq 0xd3ec(%rip), %rdi      # 0x1446e
movq %rbx, %rsi
movq %r15, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x4140
movq %rbx, (%r13)
movq %r15, 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)
movq $0x0, 0x20(%r13)
testq %rax, %rax
je 0x70c8
movq %r13, 0x20(%rax)
movq %r13, %r12
addq $0x30, %r12
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 0x70fb
cmpl $0x0, 0x40(%r14)
jne 0x7117
jmp 0x7131
leaq 0xd392(%rip), %rdi      # 0x14494
xorl %eax, %eax
callq 0x4260
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x3c(%r14)
leaq 0xd3a0(%rip), %rdi      # 0x144be
movq %r12, %rsi
movq %rbx, %rdx
movq %r15, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x4260
movslq 0x38(%r14), %rax
testq %rax, %rax
je 0x716a
movq 0x8(%r14), %rsi
cmpq %rax, %rsi
jl 0x716a
movl $0x0, 0x38(%r14)
leaq 0xd382(%rip), %rdi      # 0x144d4
xorl %eax, %eax
callq 0x4260
leaq 0xd62e(%rip), %rdi      # 0x1478e
callq 0x4120
callq 0x4290
movq 0x28(%r14), %rax
incq %rax
movq %rax, 0x28(%r14)
cmpq 0x30(%r14), %rax
jbe 0x717f
movq %rax, 0x30(%r14)
movq 0x18(%r14), %rax
addq %rbx, %rax
movq %rax, 0x18(%r14)
cmpq 0x20(%r14), %rax
jbe 0x7194
movq %rax, 0x20(%r14)
cmpl $0x0, 0x44(%r14)
je 0x71b9
movslq %ebx, %rdx
movq %r12, %rdi
movl $0xff, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42b0
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq