#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);
void *xmalloc(size_t size) {
  void *ret = malloc(size);
  if (!ret && !size) {
    ret = malloc(1);
  }
  if (!ret) {
    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   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115f <xmalloc+0x3f>
cmpq   $0x0,-0x8(%rbp)
jne    115f <xmalloc+0x3f>
mov    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b9 <xmalloc+0x99>
mov    -0x8(%rbp),%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119d <xmalloc+0x7d>
cmpq   $0x0,-0x8(%rbp)
jne    119d <xmalloc+0x7d>
mov    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b4 <xmalloc+0x94>
lea    0xe51(%rip),%rdi
call   1040 <die@plt>
jmp    11b9 <xmalloc+0x99>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xmalloc>:
push   %rbx
mov    %rdi,%rbx
call   1030 <malloc@plt>
test   %rbx,%rbx
jne    113d <xmalloc+0x1d>
test   %rax,%rax
jne    113d <xmalloc+0x1d>
mov    $0x1,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     1144 <xmalloc+0x24>
pop    %rbx
ret
mov    %ebx,%edi
call   1030 <malloc@plt>
test   %rbx,%rbx
jne    115f <xmalloc+0x3f>
test   %rax,%rax
jne    115f <xmalloc+0x3f>
mov    $0x1,%edi
call   1030 <malloc@plt>
test   %rax,%rax
jne    1142 <xmalloc+0x22>
lea    0xe95(%rip),%rdi
call   1040 <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 %34, label %17
17: ; preds = %14
%18 = load i64, i64* %2
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %3
%21 = load i8*, i8** %3
%22 = icmp ne i8* %21, null
br i1 %22, label %28, label %23
23: ; preds = %17
%24 = load i64, i64* %2
%25 = icmp ne i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = call i8* @malloc(i32 1)
store i8* %27, i8** %3
br label %28
28: ; preds = %26, %23, %17
%29 = load i8*, i8** %3
%30 = icmp ne i8* %29, null
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call i32 @die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
br label %34
34: ; preds = %33, %14
%35 = load i8*, i8** %3
ret i8* %35
}

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 %23
12: ; preds = %9
%13 = tail call i8* @malloc(i32 %2)
%14 = icmp ne i8* %13, null
%15 = or i1 %5, %14
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
br label %18
18: ; preds = %16, %12
%19 = phi i8* [ %13, %12 ], [ %17, %16 ]
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %18, %21, %9
%24 = phi i8* [ %10, %9 ], [ %19, %18 ], [ null, %21 ]
ret i8* %24
}