#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*/ fprintf(int /*<<< orphan*/, char *, ...);
void *malloc(size_t);
int /*<<< orphan*/ stderr;
void *xmalloc(size_t size) {
  if (size == 0)
    fprintf(stderr, "xmalloc: zero size");
  void *p = malloc(size);
  if (!p) {
    double sm = size / (0x100000 * 1.0);
    fprintf(stderr,
            "xmalloc: out of memory when requesting "
            "%zu bytes (%gMB)",
            size, sm);
  }
  return p;
}


x86 assembly (clang, -O0):
<xmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114e <xmalloc+0x2e>
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
lea    0xee9(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11be <xmalloc+0x9e>
movaps 0xea3(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xea2(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe6b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
movsd  -0x18(%rbp),%xmm0
lea    0xe8c(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xmalloc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
jne    1143 <xmalloc+0x23>
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
lea    0xeec(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %r14,%rdi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1196 <xmalloc+0x76>
movq   %r14,%xmm1
punpckldq 0xea0(%rip),%xmm1
subpd  0xea8(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xea4(%rip),%xmm0
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rsi
mov    %r14,%rdx
mov    $0x1,%al
call   1030 <fprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"xmalloc: zero size\00"
@.str.1 = [56 x i8] c"xmalloc: out of memory when requesting %zu bytes (%gMB)\00"
define i8* @xmalloc(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca double
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %1
%11 = load i64, i64* %2
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %23, label %15
15: ; preds = %10
%16 = load i64, i64* %2
%17 = uitofp i64 %16 to double
%18 = fdiv double %17, 0x4130000000000000
store double %18, double* %4
%19 = load i32, i32* @stderr
%20 = load i64, i64* %2
%21 = load double, double* %4
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i64 %20, double %21)
br label %23
23: ; preds = %15, %10
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"xmalloc: zero size\00"
@.str.1 = [56 x i8] c"xmalloc: out of memory when requesting %zu bytes (%gMB)\00"
define noalias i8* @xmalloc(i64 %0) {
%2 = icmp eq i64 %0, 0
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = load i32, i32* @stderr
%5 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %3, %1
%7 = tail call i8* @malloc(i64 %0)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = uitofp i64 %0 to double
%11 = fmul double %10, 0x3EB0000000000000
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i64 %0, double %11)
br label %14
14: ; preds = %9, %6
ret i8* %7
}