#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 *, size_t, size_t);
int /*<<< orphan*/ stderr;
void *xrealloc(void *, size_t);
void *xrealloc2(void *old, size_t num, size_t len) {
  if (len && (num * len) / len != num) {
    fprintf(stderr, "Out of memory allocating %zu*%zu bytes!\n", num, len);
    exit(1);
  }
  return xrealloc(old, num * len);
}


x86 assembly (clang, -O0):
<xrealloc2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1191 <xrealloc2+0x61>
mov    -0x10(%rbp),%rax
imul   -0x18(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    -0x10(%rbp),%rax
je     1191 <xrealloc2+0x61>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe7e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
imul   -0x18(%rbp),%rsi
call   1030 <xrealloc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xrealloc2>:
mov    %rdx,%rcx
mov    %rsi,%r8
test   %rdx,%rdx
je     1143 <xrealloc2+0x13>
mov    %rcx,%rax
mul    %r8
jo     114f <xrealloc2+0x1f>
imul   %r8,%rcx
mov    %rcx,%rsi
jmp    1030 <xrealloc@plt>
push   %rax
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
mov    %r8,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"Out of memory allocating %zu*%zu bytes!\0A\00"
define i8* @xrealloc2(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* %6
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %3
%10 = load i64, i64* %5
%11 = load i64, i64* %6
%12 = mul i64 %10, %11
%13 = load i64, i64* %6
%14 = udiv i64 %12, %13
%15 = load i64, i64* %5
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %23
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = load i64, i64* %5
%20 = load i64, i64* %6
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i64 %19, i64 %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %9, %3
%24 = load i8*, i8** %4
%25 = load i64, i64* %5
%26 = load i64, i64* %6
%27 = mul i64 %25, %26
%28 = call i8* @xrealloc(i8* %24, i64 %27)
ret i8* %28
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"Out of memory allocating %zu*%zu bytes!\0A\00"
define i8* @xrealloc2(i8* %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %12, label %5
5: ; preds = %3
%6 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %2, i64 %1)
%7 = extractvalue { i64, i1 } %6, 1
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i64 %1, i64 %2)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %5, %3
%13 = mul i64 %2, %1
%14 = tail call i8* @xrealloc(i8* %0, i64 %13)
ret i8* %14
}