#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 */
typedef scalar_t__ ret_ptr;

/* Variables and functions */
int /*<<< orphan*/ __softboundmpx_store_null_return_metadata();
int /*<<< orphan*/ __softboundmpx_store_return_metadata(void *, char *);
void *calloc(size_t, size_t);
__attribute__((__weak__, __always___)) void *softboundmpx_calloc(size_t nmemb,
                                                                 size_t size) {
  void *ret_ptr = calloc(nmemb, size);
  if (ret_ptr != NULL) {
    __softboundmpx_store_return_metadata(ret_ptr,
                                         ((char *)(ret_ptr) + (nmemb * size)));
  } else {
    __softboundmpx_store_null_return_metadata();
  }
  return ret_ptr;
}


x86 assembly (clang, -O0):
<softboundmpx_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     117a <softboundmpx_calloc+0x4a>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rax
imul   -0x10(%rbp),%rax
add    %rax,%rsi
call   1040 <__softboundmpx_store_return_metadata@plt>
jmp    1181 <softboundmpx_calloc+0x51>
mov    $0x0,%al
call   1050 <__softboundmpx_store_null_return_metadata@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<softboundmpx_calloc>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r15
call   1030 <calloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     115c <softboundmpx_calloc+0x2c>
imul   %r15,%rbx
mov    %r14,%rsi
add    %rbx,%rsi
mov    %r14,%rdi
call   1040 <__softboundmpx_store_return_metadata@plt>
jmp    1163 <softboundmpx_calloc+0x33>
xor    %eax,%eax
call   1050 <__softboundmpx_store_null_return_metadata@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define weak i8* @softboundmpx_calloc(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 = load i64, i64* %4
%8 = call i8* @calloc(i64 %6, i64 %7)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = load i8*, i8** %5
%14 = load i64, i64* %3
%15 = load i64, i64* %4
%16 = mul i64 %14, %15
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = call i32 @__softboundmpx_store_return_metadata(i8* %12, i8* %17)
br label %21
19: ; preds = %2
%20 = call i32 (...) @__softboundmpx_store_null_return_metadata()
br label %21
21: ; preds = %19, %11
%22 = load i8*, i8** %5
ret i8* %22
}

LLVM IR (-O2):
define weak i8* @softboundmpx_calloc(i64 %0, i64 %1) {
%3 = tail call i8* @calloc(i64 %0, i64 %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = mul i64 %1, %0
%7 = getelementptr inbounds i8, i8* %3, i64 %6
%8 = tail call i32 @__softboundmpx_store_return_metadata(i8* %3, i8* %7)
br label %11
9: ; preds = %2
%10 = tail call i32 (...) @__softboundmpx_store_null_return_metadata()
br label %11
11: ; preds = %9, %5
ret i8* %3
}