#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
void *malloc(unsigned int);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void *xmalloc(unsigned int size) {
  void *p;
  if (size == 0)
    ++size;
  p = malloc(size);
  if (!p) {
    fprintf(stderr, "xmalloc: malloc(%d) failed", size);
    perror(NULL);
    exit(1);
  }
  return (p);
}


x86 assembly (clang, -O0):
<xmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    115e <xmalloc+0x1e>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a0 <xmalloc+0x60>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe78(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xmalloc>:
push   %rbx
test   %edi,%edi
mov    $0x1,%ebx
cmovne %edi,%ebx
mov    %ebx,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1159 <xmalloc+0x19>
pop    %rbx
ret
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
mov    %ebx,%edx
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"xmalloc: malloc(%d) failed\00"
define i8* @xmalloc(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* %2
%8 = add i32 %7, 1
store i32 %8, i32* %2
br label %9
9: ; preds = %6, %1
%10 = load i32, i32* %2
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %20, label %14
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i32, i32* %2
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = call i32 @perror(i32* null)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %9
%21 = load i8*, i8** %3
ret i8* %21
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"xmalloc: malloc(%d) failed\00"
define noalias i8* @xmalloc(i32 %0) {
%2 = icmp eq i32 %0, 0
%3 = select i1 %2, i32 1, i32 %0
%4 = tail call i8* @malloc(i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %3)
%9 = tail call i32 @perror(i32* null)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %1
ret i8* %4
}