#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*/ exit(int /*<<< orphan*/);
void *malloc(size_t);
int /*<<< orphan*/ puts(char *);
void *xmallocarray(size_t nmemb, size_t size) {
  if ((nmemb >= ((size_t)1 << (sizeof(size_t) * 4)) ||
       size >= ((size_t)1 << (sizeof(size_t) * 4))) &&
      nmemb > 0 && SIZE_MAX / nmemb < size) {
    puts("integer overflow block");
    exit(0);
  }
  void *ptr = malloc(nmemb * size);
  if (ptr == NULL) {
    puts("error in xmallocarray() function");
    exit(0);
  }
  return ptr;
}


x86 assembly (clang, -O0):
<xmallocarray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0x100000000,%rax
cmp    %rax,-0x8(%rbp)
jae    1168 <xmallocarray+0x38>
movabs $0x100000000,%rax
cmp    %rax,-0x10(%rbp)
jb     11a2 <xmallocarray+0x72>
cmpq   $0x0,-0x8(%rbp)
jbe    11a2 <xmallocarray+0x72>
mov    0x2e5e(%rip),%rax
mov    (%rax),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x8(%rbp)
cmp    -0x10(%rbp),%rax
jae    11a2 <xmallocarray+0x72>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rdi
imul   -0x10(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d2 <xmallocarray+0xa2>
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xmallocarray>:
push   %rax
test   %rdi,%rdi
je     1162 <xmallocarray+0x32>
mov    %rsi,%rax
or     %rdi,%rax
shr    $0x20,%rax
je     1162 <xmallocarray+0x32>
mov    0x2e8f(%rip),%rax
mov    (%rax),%rax
mov    %rax,%rcx
or     %rdi,%rcx
shr    $0x20,%rcx
je     1175 <xmallocarray+0x45>
xor    %edx,%edx
div    %rdi
cmp    %rsi,%rax
jb     117e <xmallocarray+0x4e>
imul   %rdi,%rsi
mov    %rsi,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1187 <xmallocarray+0x57>
pop    %rcx
ret
xor    %edx,%edx
div    %edi
cmp    %rsi,%rax
jae    1162 <xmallocarray+0x32>
lea    0xe7b(%rip),%rdi
jmp    118e <xmallocarray+0x5e>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@SIZE_MAX = global i64 0
@.str = [23 x i8] c"integer overflow block\00"
@.str.1 = [33 x i8] c"error in xmallocarray() function\00"
define i8* @xmallocarray(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i64 %0, i64* %3
store i64 %1, i64* %4
%6 = load i64, i64* %3
%7 = icmp uge i64 %6, 4294967296
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i64, i64* %4
%10 = icmp uge i64 %9, 4294967296
br i1 %10, label %11, label %23
11: ; preds = %8, %2
%12 = load i64, i64* %3
%13 = icmp ugt i64 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = load i64, i64* @SIZE_MAX
%16 = load i64, i64* %3
%17 = udiv i64 %15, %16
%18 = load i64, i64* %4
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %14, %11, %8
%24 = load i64, i64* %3
%25 = load i64, i64* %4
%26 = mul i64 %24, %25
%27 = call i8* @malloc(i64 %26)
store i8* %27, i8** %5
%28 = load i8*, i8** %5
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %23
%34 = load i8*, i8** %5
ret i8* %34
}

LLVM IR (-O2):
@SIZE_MAX = global i64 0
@.str = [23 x i8] c"integer overflow block\00"
@.str.1 = [33 x i8] c"error in xmallocarray() function\00"
define noalias i8* @xmallocarray(i64 %0, i64 %1) {
%3 = or i64 %1, %0
%4 = icmp ugt i64 %3, 4294967295
%5 = icmp ne i64 %0, 0
%6 = and i1 %5, %4
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = load i64, i64* @SIZE_MAX
%9 = udiv i64 %8, %0
%10 = icmp ult i64 %9, %1
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %2, %7
%15 = mul i64 %1, %0
%16 = tail call i8* @malloc(i64 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 0)
unreachable
21: ; preds = %14
ret i8* %16
}