#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 *xmalloc(size_t);
void *xmalloc2(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 xmalloc(num * len);
}


x86 assembly (clang, -O0):
<xmalloc2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118d <xmalloc2+0x5d>
mov    -0x8(%rbp),%rax
imul   -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
cmp    -0x8(%rbp),%rax
je     118d <xmalloc2+0x5d>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe82(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rdi
imul   -0x10(%rbp),%rdi
call   1030 <xmalloc@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xmalloc2>:
mov    %rsi,%rcx
mov    %rdi,%r8
test   %rsi,%rsi
je     1143 <xmalloc2+0x13>
mov    %rcx,%rax
mul    %r8
jo     114f <xmalloc2+0x1f>
imul   %r8,%rcx
mov    %rcx,%rdi
jmp    1030 <xmalloc@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* @xmalloc2(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%5 = load i64, i64* %4
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %2
%8 = load i64, i64* %3
%9 = load i64, i64* %4
%10 = mul i64 %8, %9
%11 = load i64, i64* %4
%12 = udiv i64 %10, %11
%13 = load i64, i64* %3
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %21
15: ; preds = %7
%16 = load i32, i32* @stderr
%17 = load i64, i64* %3
%18 = load i64, i64* %4
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i64 %17, i64 %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %7, %2
%22 = load i64, i64* %3
%23 = load i64, i64* %4
%24 = mul i64 %22, %23
%25 = call i8* @xmalloc(i64 %24)
ret i8* %25
}

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