#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ coco_error(char *);
void *malloc(size_t const);
void *coco_allocate_memory(const size_t size) {
  void *data;
  if (size == 0) {
    coco_error("coco_allocate_memory() called with 0 size.");
    return NULL;
  }
  data = malloc(size);
  if (data == NULL)
    coco_error("coco_allocate_memory() failed.");
  return data;
}


x86 assembly (clang, -O0):
<coco_allocate_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1150 <coco_allocate_memory+0x30>
lea    0xec2(%rip),%rdi
call   1030 <coco_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    117c <coco_allocate_memory+0x5c>
mov    -0x10(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1174 <coco_allocate_memory+0x54>
lea    0xebc(%rip),%rdi
call   1030 <coco_error@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<coco_allocate_memory>:
push   %rax
test   %rdi,%rdi
je     1132 <coco_allocate_memory+0x12>
call   1040 <malloc@plt>
test   %rax,%rax
je     113b <coco_allocate_memory+0x1b>
pop    %rcx
ret
lea    0xec7(%rip),%rdi
jmp    1142 <coco_allocate_memory+0x22>
lea    0xee9(%rip),%rdi
call   1030 <coco_error@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [43 x i8] c"coco_allocate_memory() called with 0 size.\00"
@.str.1 = [31 x i8] c"coco_allocate_memory() failed.\00"
define i8* @coco_allocate_memory(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @coco_error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %18
9: ; preds = %1
%10 = load i64, i64* %3
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @coco_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %9
%17 = load i8*, i8** %4
store i8* %17, i8** %2
br label %18
18: ; preds = %16, %7
%19 = load i8*, i8** %2
ret i8* %19
}

LLVM IR (-O2):
@.str = [43 x i8] c"coco_allocate_memory() called with 0 size.\00"
@.str.1 = [31 x i8] c"coco_allocate_memory() failed.\00"
define noalias i8* @coco_allocate_memory(i64 %0) {
%2 = icmp eq i64 %0, 0
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = tail call i8* @malloc(i64 %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3, %1
%7 = phi i8* [ getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), %3 ]
%8 = tail call i32 @coco_error(i8* %7)
br label %9
9: ; preds = %6, %3
%10 = phi i8* [ %4, %3 ], [ null, %6 ]
ret i8* %10
}