// File: /workspace/github_c_makefile_star2_O1/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 %r12
pushq %rbx
movl %ecx, %ebp
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r14
cmpl $0x0, 0x48(%rdi)
je 0x718f
movq (%r14), %r15
testq %r15, %r15
je 0x718f
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x6f1d
movq 0x18(%r15), %r15
jmp 0x7171
leaq 0x40(%rbx), %rdi
callq 0x4410
movq %rax, %r15
testq %rax, %rax
jne 0x71be
movq %r14, %rdi
callq 0x72e6
leaq 0xe2bf(%rip), %rdi      # 0x1546e
movq %rbx, %rsi
movq %r12, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x4140
movq %rbx, (%r15)
movq %r12, 0x8(%r15)
movl %ebp, 0x10(%r15)
movabsq $-0x1e1e1e1e1e1e1e1f, %rax # imm = 0xE1E1E1E1E1E1E1E1
movq %rax, 0x28(%r15)
movq %rax, 0x30(%r15,%rbx)
movq (%r14), %rax
movq %rax, 0x18(%r15)
movq $0x0, 0x20(%r15)
testq %rax, %rax
je 0x71f4
movq %r15, 0x20(%rax)
movq %r15, (%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
jne 0x7233
leaq 0xe276(%rip), %rdi      # 0x15494
xorl %eax, %eax
callq 0x4260
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x3c(%r14)
addq $0x30, %r15
cmpl $0x0, 0x40(%r14)
je 0x7258
leaq 0xe279(%rip), %rdi      # 0x154be
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 0x7291
movq 0x8(%r14), %rsi
cmpq %rax, %rsi
jl 0x7291
movl $0x0, 0x38(%r14)
leaq 0xe25b(%rip), %rdi      # 0x154d4
xorl %eax, %eax
callq 0x4260
leaq 0xe507(%rip), %rdi      # 0x1578e
callq 0x4120
callq 0x4290
movq 0x28(%r14), %rax
incq %rax
movq %rax, 0x28(%r14)
cmpq 0x30(%r14), %rax
jbe 0x72a6
movq %rax, 0x30(%r14)
movq 0x18(%r14), %rax
addq %rbx, %rax
movq %rax, 0x18(%r14)
cmpq 0x20(%r14), %rax
jbe 0x72bb
movq %rax, 0x20(%r14)
cmpl $0x0, 0x44(%r14)
je 0x72da
movslq %ebx, %rdx
movq %r15, %rdi
movl $0xff, %esi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x42b0
movq %r15, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq