#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 */
size_t SIZE_MAX;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *gettext(char *);
int /*<<< orphan*/ stderr;
void *utils_realloc(void *, size_t);
void *utils_realloc_n(void *ptr, size_t nmemb, size_t size) {
  assert(nmemb > 0);
  assert(size > 0);
  if (SIZE_MAX / size < nmemb) {
    fprintf(stderr,
            gettext("Couldn't resize array due to integer overflow.\n"));
    abort();
  }
  return utils_realloc(ptr, nmemb * size);
}


x86 assembly (clang, -O0):
<utils_realloc_n>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    -0x10(%rbp),%rax
jae    11ce <utils_realloc_n+0x7e>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xe49(%rip),%rdi
call   1040 <gettext@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rsi
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
imul   -0x18(%rbp),%rsi
call   1070 <utils_realloc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utils_realloc_n>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%rax
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
je     11ae <utils_realloc_n+0x5e>
xor    %edx,%edx
div    %rbx
cmp    %r15,%rax
jb     11b7 <utils_realloc_n+0x67>
imul   %r15,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <utils_realloc@plt>
xor    %edx,%edx
div    %ebx
cmp    %r15,%rax
jae    119a <utils_realloc_n+0x4a>
mov    0x2e22(%rip),%rax
mov    (%rax),%ebx
lea    0xe39(%rip),%rdi
call   1040 <gettext@plt>
mov    %ebx,%edi
mov    %rax,%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@SIZE_MAX = global i64 0
@stderr = global i32 0
@.str = [48 x i8] c"Couldn't resize array due to integer overflow.\0A\00"
define i8* @utils_realloc_n(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 ugt i64 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i64, i64* %6
%12 = icmp ugt i64 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i64, i64* @SIZE_MAX
%16 = load i64, i64* %6
%17 = udiv i64 %15, %16
%18 = load i64, i64* %5
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %3
%21 = load i32, i32* @stderr
%22 = call i8* @gettext(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @fprintf(i32 %21, i8* %22)
%24 = call i32 (...) @abort()
unreachable
25: ; preds = %3
%26 = load i8*, i8** %4
%27 = load i64, i64* %5
%28 = load i64, i64* %6
%29 = mul i64 %27, %28
%30 = call i8* @utils_realloc(i8* %26, i64 %29)
ret i8* %30
}

LLVM IR (-O2):
@SIZE_MAX = global i64 0
@stderr = global i32 0
@.str = [48 x i8] c"Couldn't resize array due to integer overflow.\0A\00"
define i8* @utils_realloc_n(i8* %0, i64 %1, i64 %2) {
%4 = icmp ne i64 %1, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp ne i64 %2, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = load i64, i64* @SIZE_MAX
%11 = udiv i64 %10, %2
%12 = icmp ult i64 %11, %1
br i1 %12, label %13, label %18
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = tail call i8* @gettext(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @fprintf(i32 %14, i8* %15)
%17 = tail call i32 (...) @abort()
unreachable
18: ; preds = %3
%19 = mul i64 %2, %1
%20 = tail call i8* @utils_realloc(i8* %0, i64 %19)
ret i8* %20
}