#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 *);
void *malloc(size_t);
void *realloc(void *, size_t);
int /*<<< orphan*/ stderr;
void *xrealloc(void *ptr, size_t nmemb, size_t size) {
  void *retval;
  size_t total = nmemb * size;
  if (((double)size * (int)(nmemb & (((size_t)-1) >> 1))) != total ||
      NULL == (retval = (ptr == NULL ? malloc(total) : realloc(ptr, total)))) {
    fprintf(stderr, "FATAL: Allocation failure.\n");
    exit(-1);
  }
  return retval;
}


x86 assembly (clang, -O0):
<xrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
imul   %rcx,%rax
mov    %rax,-0x28(%rbp)
movaps 0xe95(%rip),%xmm3
movq   -0x18(%rbp),%xmm0
punpckldq %xmm3,%xmm0
movapd 0xe94(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movq   -0x28(%rbp),%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jne    11fd <xrealloc+0xbd>
jp     11fd <xrealloc+0xbd>
cmpq   $0x0,-0x8(%rbp)
jne    11d9 <xrealloc+0x99>
mov    -0x28(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
jmp    11ea <xrealloc+0xaa>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    121c <xrealloc+0xdc>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xrealloc>:
push   %rax
movq   %rdx,%xmm0
imul   %rsi,%rdx
movdqa 0xeae(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xeb2(%rip),%xmm2
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm3
unpckhpd %xmm0,%xmm3
addsd  %xmm0,%xmm3
xorps  %xmm0,%xmm0
cvtsi2sd %esi,%xmm0
mulsd  %xmm3,%xmm0
movq   %rdx,%xmm3
punpckldq %xmm1,%xmm3
subpd  %xmm2,%xmm3
movapd %xmm3,%xmm1
unpckhpd %xmm3,%xmm1
addsd  %xmm3,%xmm1
ucomisd %xmm1,%xmm0
jne    11bb <xrealloc+0x7b>
jp     11bb <xrealloc+0x7b>
test   %rdi,%rdi
je     11ae <xrealloc+0x6e>
mov    %rdx,%rsi
call   1050 <realloc@plt>
test   %rax,%rax
je     11bb <xrealloc+0x7b>
pop    %rcx
ret
mov    %rdx,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
jne    11ac <xrealloc+0x6c>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"FATAL: Allocation failure.\0A\00"
define i8* @xrealloc(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = load i64, i64* %5
%10 = load i64, i64* %6
%11 = mul i64 %9, %10
store i64 %11, i64* %8
%12 = load i64, i64* %6
%13 = uitofp i64 %12 to double
%14 = load i64, i64* %5
%15 = and i64 %14, 9223372036854775807
%16 = trunc i64 %15 to i32
%17 = sitofp i32 %16 to double
%18 = fmul double %13, %17
%19 = load i64, i64* %8
%20 = uitofp i64 %19 to double
%21 = fcmp une double %18, %20
br i1 %21, label %35, label %22
22: ; preds = %3
%23 = load i8*, i8** %4
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i64, i64* %8
%27 = call i8* @malloc(i64 %26)
br label %32
28: ; preds = %22
%29 = load i8*, i8** %4
%30 = load i64, i64* %8
%31 = call i8* @realloc(i8* %29, i64 %30)
br label %32
32: ; preds = %28, %25
%33 = phi i8* [ %27, %25 ], [ %31, %28 ]
store i8* %33, i8** %7
%34 = icmp eq i8* null, %33
br i1 %34, label %35, label %39
35: ; preds = %32, %3
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%38 = call i32 @exit(i32 -1)
unreachable
39: ; preds = %32
%40 = load i8*, i8** %7
ret i8* %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"FATAL: Allocation failure.\0A\00"
define i8* @xrealloc(i8* %0, i64 %1, i64 %2) {
%4 = mul i64 %2, %1
%5 = uitofp i64 %2 to double
%6 = trunc i64 %1 to i32
%7 = sitofp i32 %6 to double
%8 = fmul double %5, %7
%9 = uitofp i64 %4 to double
%10 = fcmp une double %8, %9
br i1 %10, label %20, label %11
11: ; preds = %3
%12 = icmp eq i8* %0, null
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i8* @malloc(i64 %4)
br label %17
15: ; preds = %11
%16 = tail call i8* @realloc(i8* %0, i64 %4)
br label %17
17: ; preds = %15, %13
%18 = phi i8* [ %14, %13 ], [ %16, %15 ]
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %17, %3
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%23 = tail call i32 @exit(i32 -1)
unreachable
24: ; preds = %17
ret i8* %18
}