// File: /workspace/github_c_makefile_star2_O0/open-mesh-mirror[P]batmand/allocate.c
// Function: debugMalloc
void *debugMalloc(uint32_t length, int32_t tag)
{
	unsigned char *memory;
	struct chunkHeader *chunkHeader;
	struct chunkTrailer *chunkTrailer;
	unsigned char *chunk;

/* 	printf("sizeof(struct chunkHeader) = %u, sizeof (struct chunkTrailer) = %u\n", sizeof (struct chunkHeader), sizeof (struct chunkTrailer)); */

	memory = malloc(length + sizeof(struct chunkHeader) + sizeof(struct chunkTrailer) + getHeaderPad() + getTrailerPad(length));

	if (memory == NULL)
	{
		debug_output( 0, "Cannot allocate %u bytes, malloc tag = %d\n", (unsigned int)(length + sizeof(struct chunkHeader) + sizeof(struct chunkTrailer)), tag );
		restore_and_exit(0);
	}

	chunkHeader = (struct chunkHeader *)memory;
	chunk = memory + sizeof(struct chunkHeader) + getHeaderPad();
	chunkTrailer = (struct chunkTrailer *)(memory + sizeof(struct chunkHeader) + length + getHeaderPad() + getTrailerPad(length));

	fillPadding((unsigned char*)chunkHeader + sizeof(struct chunkHeader), getHeaderPad());
	fillPadding(chunk + length, getTrailerPad(length));

	chunkHeader->length = length;
	chunkHeader->tag = tag;
	chunkHeader->magicNumber = MAGIC_NUMBER;

	chunkTrailer->magicNumber = MAGIC_NUMBER;

	pthread_mutex_lock(&chunk_mutex);
	chunkHeader->next = chunkList;
	chunkList = chunkHeader;
	pthread_mutex_unlock(&chunk_mutex);

#if defined MEMORY_USAGE

	addMemory( length, tag );

#endif

	return chunk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl -0x4(%rbp), %eax
addq $0x18, %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
callq 0x7110
movq %rax, %rcx
movq -0x38(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x4(%rbp), %eax
movl %eax, %edi
callq 0x7160
movq -0x30(%rbp), %rdi
addq %rax, %rdi
callq 0x2310
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x7298
movl -0x4(%rbp), %eax
addq $0x18, %rax
addq $0x4, %rax
movl %eax, %edx
movl -0x8(%rbp), %ecx
xorl %edi, %edi
leaq 0xe4f0(%rip), %rsi      # 0x1577a
movb $0x0, %al
callq 0x123f0
xorl %edi, %edi
callq 0x10180
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x60(%rbp)
callq 0x7110
movq %rax, %rcx
movq -0x60(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
addq $0x18, %rax
movl -0x4(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
callq 0x7110
movq %rax, %rcx
movq -0x58(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl -0x4(%rbp), %eax
movl %eax, %edi
callq 0x7160
movq %rax, %rcx
movq -0x50(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x48(%rbp)
callq 0x7110
movq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x73b0
movq -0x28(%rbp), %rax
movl -0x4(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0x4(%rbp), %eax
movl %eax, %edi
callq 0x7160
movq -0x40(%rbp), %rdi
movq %rax, %rsi
callq 0x73b0
movl -0x4(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x8(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
movl $0x12345678, 0x10(%rax) # imm = 0x12345678
movq -0x20(%rbp), %rax
movl $0x12345678, (%rax)     # imm = 0x12345678
leaq 0x14203(%rip), %rdi     # 0x1b570
callq 0x24e0
movq 0x141bf(%rip), %rcx     # 0x1b538
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq %rax, 0x141ad(%rip)     # 0x1b538
leaq 0x141de(%rip), %rdi     # 0x1b570
callq 0x2300
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
callq 0x7400
movq -0x28(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)