#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*/ die(char *);
void *malloc(int);
int /*<<< orphan*/ release_pack_memory(size_t, int);
void *xmalloc(size_t size) {
  void *ret = malloc(size);
  if (!ret && !size)
    ret = malloc(1);
  if (!ret) {
    release_pack_memory(size, -1);
    ret = malloc(size);
    if (!ret && !size)
      ret = malloc(1);
    if (!ret)
      die("Out of memory, malloc failed");
  }
  return ret;
}


x86 assembly (clang, -O0):
<xmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116f <xmalloc+0x3f>
cmpq   $0x0,-0x8(%rbp)
jne    116f <xmalloc+0x3f>
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d7 <xmalloc+0xa7>
mov    -0x8(%rbp),%rdi
mov    $0xffffffff,%esi
call   1030 <release_pack_memory@plt>
mov    -0x8(%rbp),%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bb <xmalloc+0x8b>
cmpq   $0x0,-0x8(%rbp)
jne    11bb <xmalloc+0x8b>
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d2 <xmalloc+0xa2>
lea    0xe33(%rip),%rdi
call   1050 <die@plt>
jmp    11d7 <xmalloc+0xa7>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xmalloc>:
push   %rbx
mov    %rdi,%rbx
call   1040 <malloc@plt>
test   %rbx,%rbx
jne    114d <xmalloc+0x1d>
test   %rax,%rax
jne    114d <xmalloc+0x1d>
mov    $0x1,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1154 <xmalloc+0x24>
pop    %rbx
ret
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1030 <release_pack_memory@plt>
mov    %ebx,%edi
call   1040 <malloc@plt>
test   %rbx,%rbx
jne    117c <xmalloc+0x4c>
test   %rax,%rax
jne    117c <xmalloc+0x4c>
mov    $0x1,%edi
call   1040 <malloc@plt>
test   %rax,%rax
jne    1152 <xmalloc+0x22>
lea    0xe78(%rip),%rdi
call   1050 <die@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [29 x i8] c"Out of memory, malloc failed\00"
define i8* @xmalloc(i64 %0) {
%2 = trunc i64 %0 to i32
%3 = tail call i8* @malloc(i32 %2)
%4 = icmp ne i8* %3, null
%5 = icmp ne i64 %0, 0
%6 = or i1 %5, %4
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
br label %9
9: ; preds = %7, %1
%10 = phi i8* [ %3, %1 ], [ %8, %7 ]
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = tail call i32 @release_pack_memory(i64 %0, i32 -1)
%14 = tail call i8* @malloc(i32 %2)
%15 = icmp ne i8* %14, null
%16 = or i1 %5, %15
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
br label %19
19: ; preds = %17, %12
%20 = phi i8* [ %14, %12 ], [ %18, %17 ]
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %19, %22, %9
%25 = phi i8* [ %10, %9 ], [ %20, %19 ], [ null, %22 ]
ret i8* %25
}