void *u_malloc(size)
int size;
{
  void *p;
  if (size < 0)
    u_crash("u_malloc: Illegal size");
  if (size == 0)
    return (0);
  p = malloc(size);
  if (!p)
    u_crash("u_malloc: Out of memory");
  return (p);
}


x86 assembly (clang, -O0):
<u_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1143 <u_malloc+0x23>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1040 <u_crash@plt>
cmpl   $0x0,-0xc(%rbp)
jne    115a <u_malloc+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    1188 <u_malloc+0x68>
movslq -0xc(%rbp),%rdi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1180 <u_malloc+0x60>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <u_crash@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u_malloc>:
push   %rbx
mov    %edi,%ebx
test   %edi,%edi
js     112d <u_malloc+0xd>
jne    113b <u_malloc+0x1b>
xor    %ebx,%ebx
jmp    115b <u_malloc+0x3b>
lea    0xecc(%rip),%rdi
xor    %eax,%eax
call   1040 <u_crash@plt>
movslq %ebx,%rdi
call   1030 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    115b <u_malloc+0x3b>
lea    0xec5(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <u_crash@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"u_malloc: Illegal size\00"
@.str.1 = [24 x i8] c"u_malloc: Out of memory\00"
define i8* @u_malloc(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 (i8*, ...) bitcast (i32 (...)* @u_crash to i32 (i8*, ...)*)(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9
store i8* null, i8** %2
br label %23
13: ; preds = %9
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = call i8* @malloc(i64 %15)
store i8* %16, i8** %4
%17 = load i8*, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %21, label %19
19: ; preds = %13
%20 = call i32 (i8*, ...) bitcast (i32 (...)* @u_crash to i32 (i8*, ...)*)(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %13
%22 = load i8*, i8** %4
store i8* %22, i8** %2
br label %23
23: ; preds = %21, %12
%24 = load i8*, i8** %2
ret i8* %24
}

LLVM IR (-O2):
@.str = [23 x i8] c"u_malloc: Illegal size\00"
@.str.1 = [24 x i8] c"u_malloc: Out of memory\00"
define i8* @u_malloc(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 (i8*, ...) bitcast (i32 (...)* @u_crash to i32 (i8*, ...)*)(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %7
5: ; preds = %1
%6 = icmp eq i32 %0, 0
br i1 %6, label %13, label %7
7: ; preds = %3, %5
%8 = sext i32 %0 to i64
%9 = tail call i8* @malloc(i64 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 (i8*, ...) bitcast (i32 (...)* @u_crash to i32 (i8*, ...)*)(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %7, %11, %5
%14 = phi i8* [ null, %5 ], [ null, %11 ], [ %9, %7 ]
ret i8* %14
}