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


x86 assembly (clang, -O0):
<xmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movaps 0xecd(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xecc(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe9d(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe7f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11a9 <xmalloc+0x79>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
movsd  -0x10(%rbp),%xmm0
lea    0xe8c(%rip),%rsi
call   1040 <fprintf@plt>
cmpq   $0x0,-0x8(%rbp)
jne    11c2 <xmalloc+0x92>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <fail@plt>
mov    -0x8(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1229 <xmalloc+0xf9>
movaps 0xe2f(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe2e(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdff(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
movsd  -0x20(%rbp),%xmm0
lea    0xe49(%rip),%rdi
mov    $0x1,%al
call   1030 <fail@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xmalloc>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
movq   %rdi,%xmm0
punpckldq 0xeb9(%rip),%xmm0
subpd  0xec1(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
mulsd  0xebd(%rip),%xmm1
movapd %xmm1,(%rsp)
ucomisd 0xeb8(%rip),%xmm1
jbe    118f <xmalloc+0x5f>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
mov    %r14,%rdx
movapd (%rsp),%xmm0
call   1040 <fprintf@plt>
test   %r14,%r14
jne    11a2 <xmalloc+0x72>
lea    0xebd(%rip),%rdi
xor    %eax,%eax
call   1030 <fail@plt>
mov    %r14,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c8 <xmalloc+0x98>
lea    0xeb2(%rip),%rdi
mov    %r14,%rsi
movapd (%rsp),%xmm0
mov    $0x1,%al
call   1030 <fail@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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