#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
void *malloc(size_t);
int /*<<< orphan*/ stderr;
extern void *xmalloc(size_t size) {
  void *dummy;
  dummy = malloc(size);
  if (dummy == NULL) {
    fprintf(stderr, "Could not allocate ");
    if (size < 1024) {
      fprintf(stderr, "%ib\n", (int)size);
    } else if (size < 1048576) {
      fprintf(stderr, "%fkb\n", size / 1024.);
    } else {
      fprintf(stderr, "%fMb\n", size / 1048576.);
    }
    fprintf(stderr, "Exiting... :-(\n");
    exit(EXIT_FAILURE);
  }
  return dummy;
}


x86 assembly (clang, -O0):
<xmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    126c <xmalloc+0x13c>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
lea    0xecc(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cmpq   $0x400,-0x8(%rbp)
jae    119b <xmalloc+0x6b>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    %eax,%edx
lea    0xeb5(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1247 <xmalloc+0x117>
cmpq   $0x100000,-0x8(%rbp)
jae    11f8 <xmalloc+0xc8>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
movaps 0xe57(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe56(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe27(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe5d(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
jmp    1242 <xmalloc+0x112>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
movaps 0xe08(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe07(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdd0(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe14(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
jmp    1247 <xmalloc+0x117>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xmalloc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <malloc@plt>
test   %rax,%rax
je     1149 <xmalloc+0x19>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e90(%rip),%r14
mov    (%r14),%edi
lea    0xed6(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    $0x3ff,%rbx
ja     117f <xmalloc+0x4f>
mov    (%r14),%edi
lea    0xed0(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11d3 <xmalloc+0xa3>
movq   %rbx,%xmm1
punpckldq 0xe74(%rip),%xmm1
subpd  0xe7c(%rip),%xmm1
mov    (%r14),%edi
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
cmp    $0xfffff,%rbx
ja     11bd <xmalloc+0x8d>
mulsd  0xe74(%rip),%xmm0
lea    0xe8e(%rip),%rsi
jmp    11cc <xmalloc+0x9c>
mulsd  0xe5b(%rip),%xmm0
lea    0xe83(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
mov    (%r14),%edi
lea    0xe78(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"Could not allocate \00"
@.str.1 = [5 x i8] c"%ib\0A\00"
@.str.2 = [6 x i8] c"%fkb\0A\00"
@.str.3 = [6 x i8] c"%fMb\0A\00"
@.str.4 = [16 x i8] c"Exiting... :-(\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @xmalloc(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = call i8* @malloc(i64 %4)
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %39
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%11 = load i64, i64* %2
%12 = icmp ult i64 %11, 1024
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i64, i64* %2
%16 = trunc i64 %15 to i32
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %34
18: ; preds = %8
%19 = load i64, i64* %2
%20 = icmp ult i64 %19, 1048576
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = load i64, i64* %2
%24 = uitofp i64 %23 to double
%25 = fdiv double %24, 1.024000e+03
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %25)
br label %33
27: ; preds = %18
%28 = load i32, i32* @stderr
%29 = load i64, i64* %2
%30 = uitofp i64 %29 to double
%31 = fdiv double %30, 0x4130000000000000
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %31)
br label %33
33: ; preds = %27, %21
br label %34
34: ; preds = %33, %13
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %1
%40 = load i8*, i8** %3
ret i8* %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"Could not allocate \00"
@.str.1 = [5 x i8] c"%ib\0A\00"
@.str.2 = [6 x i8] c"%fkb\0A\00"
@.str.3 = [6 x i8] c"%fMb\0A\00"
@.str.4 = [16 x i8] c"Exiting... :-(\0A\00"
@EXIT_FAILURE = global i32 0
define noalias i8* @xmalloc(i64 %0) {
%2 = tail call i8* @malloc(i64 %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %27
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = icmp ult i64 %0, 1024
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = trunc i64 %0 to i32
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %22
12: ; preds = %4
%13 = icmp ult i64 %0, 1048576
%14 = load i32, i32* @stderr
%15 = uitofp i64 %0 to double
br i1 %13, label %16, label %19
16: ; preds = %12
%17 = fmul double %15, 0x3F50000000000000
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %17)
br label %22
19: ; preds = %12
%20 = fmul double %15, 0x3EB0000000000000
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %20)
br label %22
22: ; preds = %16, %19, %8
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %1
ret i8* %2
}