#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*/ fatal(char *);
void *realloc(void *, size_t);
void *xreallocarray(void *p, size_t n, size_t m) {
  if (n && m > (size_t)-1 / n)
    fatal("out of memory");
  p = realloc(p, n * m);
  if (!p)
    fatal("out of memory");
  return p;
}


x86 assembly (clang, -O0):
<xreallocarray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1172 <xreallocarray+0x52>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0xffffffffffffffff,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jbe    1172 <xreallocarray+0x52>
lea    0xe93(%rip),%rdi
call   1040 <fatal@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
imul   -0x18(%rbp),%rsi
call   1030 <realloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    119f <xreallocarray+0x7f>
lea    0xe66(%rip),%rdi
call   1040 <fatal@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xreallocarray>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
test   %rsi,%rsi
je     1147 <xreallocarray+0x27>
mov    %r15,%rax
mul    %rbx
jno    1147 <xreallocarray+0x27>
lea    0xebe(%rip),%rdi
call   1040 <fatal@plt>
imul   %r15,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116a <xreallocarray+0x4a>
lea    0xe9b(%rip),%rdi
call   1040 <fatal@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"out of memory\00"
define i8* @xreallocarray(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%7 = load i64, i64* %5
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %3
%10 = load i64, i64* %6
%11 = load i64, i64* %5
%12 = udiv i64 -1, %11
%13 = icmp ugt i64 %10, %12
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %9, %3
%17 = load i8*, i8** %4
%18 = load i64, i64* %5
%19 = load i64, i64* %6
%20 = mul i64 %18, %19
%21 = call i8* @realloc(i8* %17, i64 %20)
store i8* %21, i8** %4
%22 = load i8*, i8** %4
%23 = icmp ne i8* %22, null
br i1 %23, label %26, label %24
24: ; preds = %16
%25 = call i32 @fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %16
%27 = load i8*, i8** %4
ret i8* %27
}

LLVM IR (-O2):
@.str = [14 x i8] c"out of memory\00"
define noalias i8* @xreallocarray(i8* nocapture %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %10, label %5
5: ; preds = %3
%6 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %1, i64 %2)
%7 = extractvalue { i64, i1 } %6, 1
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %5, %3
%11 = mul i64 %2, %1
%12 = tail call i8* @realloc(i8* %0, i64 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
ret i8* %12
}