#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 */
void *alloc_d(size_t, int, int, char const *);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
void *calloc_d(size_t n, size_t size, int line, const char *file) {
  do {
    assert(((line >= 0)) && ("assertion failed in ASSUME"));
  } while (0);
  do {
    assert(((file != NULL)) && ("assertion failed in ASSUME"));
  } while (0);
  assert((n <= n * size) && ("overflow has occcured"));
  assert((size <= n * size) && ("overflow has occured"));
  return alloc_d(n * size, 1, line, file);
}


x86 assembly (clang, -O0):
<calloc_d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x21(%rbp)
jl     1150 <calloc_d+0x30>
mov    $0x1,%al
mov    %al,-0x21(%rbp)
jmp    1150 <calloc_d+0x30>
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
jmp    1162 <calloc_d+0x42>
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x22(%rbp)
je     117c <calloc_d+0x5c>
mov    $0x1,%al
mov    %al,-0x22(%rbp)
jmp    117c <calloc_d+0x5c>
mov    -0x22(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rcx
mov    -0x8(%rbp),%rdx
imul   -0x10(%rbp),%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x23(%rbp)
ja     11ae <calloc_d+0x8e>
mov    $0x1,%al
mov    %al,-0x23(%rbp)
jmp    11ae <calloc_d+0x8e>
mov    -0x23(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rdx
imul   -0x10(%rbp),%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x24(%rbp)
ja     11e0 <calloc_d+0xc0>
mov    $0x1,%al
mov    %al,-0x24(%rbp)
jmp    11e0 <calloc_d+0xc0>
mov    -0x24(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
imul   -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1040 <alloc_d@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calloc_d>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%rbp
mov    %edx,%edi
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
mov    %r12,%rbx
imul   %rbp,%rbx
xor    %edi,%edi
cmp    %rbp,%rbx
setae  %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmp    %r12,%rbx
setae  %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r14,%rcx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <alloc_d@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"assertion failed in ASSUME\00"
@.str.1 = [22 x i8] c"overflow has occcured\00"
@.str.2 = [21 x i8] c"overflow has occured\00"
define i8* @calloc_d(i64 %0, i64 %1, i32 %2, i8* %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
store i64 %0, i64* %5
store i64 %1, i64* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
br label %9
9: ; preds = %4
%10 = load i32, i32* %7
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9
br label %13
13: ; preds = %12, %9
%14 = phi i1 [ false, %9 ], [ true, %12 ]
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
br label %17
17: ; preds = %13
br label %18
18: ; preds = %17
%19 = load i8*, i8** %8
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %18
br label %22
22: ; preds = %21, %18
%23 = phi i1 [ false, %18 ], [ true, %21 ]
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
br label %26
26: ; preds = %22
%27 = load i64, i64* %5
%28 = load i64, i64* %5
%29 = load i64, i64* %6
%30 = mul i64 %28, %29
%31 = icmp ule i64 %27, %30
br i1 %31, label %32, label %33
32: ; preds = %26
br label %33
33: ; preds = %32, %26
%34 = phi i1 [ false, %26 ], [ true, %32 ]
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = load i64, i64* %6
%38 = load i64, i64* %5
%39 = load i64, i64* %6
%40 = mul i64 %38, %39
%41 = icmp ule i64 %37, %40
br i1 %41, label %42, label %43
42: ; preds = %33
br label %43
43: ; preds = %42, %33
%44 = phi i1 [ false, %33 ], [ true, %42 ]
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = load i64, i64* %5
%48 = load i64, i64* %6
%49 = mul i64 %47, %48
%50 = load i32, i32* %7
%51 = load i8*, i8** %8
%52 = call i8* @alloc_d(i64 %49, i32 1, i32 %50, i8* %51)
ret i8* %52
}

LLVM IR (-O2):
define i8* @calloc_d(i64 %0, i64 %1, i32 %2, i8* %3) {
%5 = xor i32 %2, -1
%6 = lshr i32 %5, 31
%7 = tail call i32 @assert(i32 %6)
%8 = icmp ne i8* %3, null
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = mul i64 %1, %0
%12 = icmp uge i64 %11, %0
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = icmp uge i64 %11, %1
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i8* @alloc_d(i64 %11, i32 1, i32 %2, i8* %3)
ret i8* %18
}