void _allocate_memory(ptr, size, filename, linenumber) void **ptr;
int size;
char *filename;
int linenumber;
{
  void *tmp;
  if (!ptr)
    __cause_ex1("protectionfail", filename, linenumber);
  if (size < 0)
    __cause_ex1("rangefail", filename, linenumber);
  tmp = malloc(size);
  if (!tmp)
    __cause_ex1("spacefail", filename, linenumber);
  *ptr = tmp;
}


x86 assembly (clang, -O0):
<_allocate_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1156 <_allocate_memory+0x36>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <__cause_ex1@plt>
cmpl   $0x0,-0xc(%rbp)
jge    1175 <_allocate_memory+0x55>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1040 <__cause_ex1@plt>
movslq -0xc(%rbp),%rdi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a2 <_allocate_memory+0x82>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <__cause_ex1@plt>
mov    -0x28(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_allocate_memory>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%rbx
test   %rdi,%rdi
je     116d <_allocate_memory+0x4d>
test   %ebp,%ebp
js     1185 <_allocate_memory+0x65>
movslq %ebp,%rdi
call   1030 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    115f <_allocate_memory+0x3f>
lea    0xec7(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <__cause_ex1@plt>
mov    %rbp,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe8c(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <__cause_ex1@plt>
test   %ebp,%ebp
jns    113b <_allocate_memory+0x1b>
lea    0xe83(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <__cause_ex1@plt>
jmp    113b <_allocate_memory+0x1b>

LLVM IR (-O0):
@.str = [15 x i8] c"protectionfail\00"
@.str.1 = [10 x i8] c"rangefail\00"
@.str.2 = [10 x i8] c"spacefail\00"
define void @_allocate_memory(i8** %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i8**, i8*** %5
%11 = icmp ne i8** %10, null
br i1 %11, label %16, label %12
12: ; preds = %4
%13 = load i8*, i8** %7
%14 = load i32, i32* %8
%15 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @__cause_ex1 to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %14)
br label %16
16: ; preds = %12, %4
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i8*, i8** %7
%21 = load i32, i32* %8
%22 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @__cause_ex1 to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32 %21)
br label %23
23: ; preds = %19, %16
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = call i8* @malloc(i64 %25)
store i8* %26, i8** %9
%27 = load i8*, i8** %9
%28 = icmp ne i8* %27, null
br i1 %28, label %33, label %29
29: ; preds = %23
%30 = load i8*, i8** %7
%31 = load i32, i32* %8
%32 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @__cause_ex1 to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %30, i32 %31)
br label %33
33: ; preds = %29, %23
%34 = load i8*, i8** %9
%35 = load i8**, i8*** %5
store i8* %34, i8** %35
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"protectionfail\00"
@.str.1 = [10 x i8] c"rangefail\00"
@.str.2 = [10 x i8] c"spacefail\00"
define void @_allocate_memory(i8** writeonly %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp eq i8** %0, null
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @__cause_ex1 to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %3)
br label %8
8: ; preds = %6, %4
%9 = icmp slt i32 %1, 0
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @__cause_ex1 to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %3)
br label %12
12: ; preds = %10, %8
%13 = sext i32 %1 to i64
%14 = tail call i8* @malloc(i64 %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @__cause_ex1 to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %2, i32 %3)
br label %18
18: ; preds = %16, %12
store i8* %14, i8** %0
ret void
}