#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*/ check_size_argument_overflow(size_t, size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
void *vpx_malloc(size_t);
void *vpx_calloc(size_t num, size_t size) {
  void *x;
  if (!check_size_argument_overflow(num, size))
    return NULL;
  x = vpx_malloc(num * size);
  if (x)
    memset(x, 0, num * size);
  return x;
}


x86 assembly (clang, -O0):
<vpx_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <check_size_argument_overflow@plt>
cmp    $0x0,%eax
jne    1163 <vpx_calloc+0x33>
movq   $0x0,-0x8(%rbp)
jmp    119c <vpx_calloc+0x6c>
mov    -0x10(%rbp),%rdi
imul   -0x18(%rbp),%rdi
call   1040 <vpx_malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1194 <vpx_calloc+0x64>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
imul   -0x18(%rbp),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vpx_calloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <check_size_argument_overflow@plt>
test   %eax,%eax
je     1166 <vpx_calloc+0x36>
imul   %r14,%rbx
mov    %rbx,%rdi
call   1040 <vpx_malloc@plt>
test   %rax,%rax
je     1166 <vpx_calloc+0x36>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
jmp    1169 <vpx_calloc+0x39>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @vpx_calloc(i64 %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
store i64 %0, i64* %4
store i64 %1, i64* %5
%7 = load i64, i64* %4
%8 = load i64, i64* %5
%9 = call i32 @check_size_argument_overflow(i64 %7, i64 %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %2
store i8* null, i8** %3
br label %27
12: ; preds = %2
%13 = load i64, i64* %4
%14 = load i64, i64* %5
%15 = mul i64 %13, %14
%16 = call i8* @vpx_malloc(i64 %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %25
19: ; preds = %12
%20 = load i8*, i8** %6
%21 = load i64, i64* %4
%22 = load i64, i64* %5
%23 = mul i64 %21, %22
%24 = call i32 @memset(i8* %20, i32 0, i64 %23)
br label %25
25: ; preds = %19, %12
%26 = load i8*, i8** %6
store i8* %26, i8** %3
br label %27
27: ; preds = %25, %11
%28 = load i8*, i8** %3
ret i8* %28
}

LLVM IR (-O2):
define i8* @vpx_calloc(i64 %0, i64 %1) {
%3 = tail call i32 @check_size_argument_overflow(i64 %0, i64 %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = mul i64 %1, %0
%7 = tail call i8* @vpx_malloc(i64 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @memset(i8* %7, i32 0, i64 %6)
br label %11
11: ; preds = %5, %9, %2
%12 = phi i8* [ null, %2 ], [ %7, %9 ], [ null, %5 ]
ret i8* %12
}