#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*/ ENOMEM;
int /*<<< orphan*/ *__errno_location();
void *malloc(size_t);
void *__libc_calloc(size_t nmemb, size_t _size) {
  register size_t size = _size * nmemb;
  if (nmemb && size / nmemb != _size) {
    (*__errno_location()) = ENOMEM;
    return 0;
  }
  return malloc(size);
}


x86 assembly (clang, -O0):
<__libc_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1183 <__libc_calloc+0x63>
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
cmp    -0x18(%rbp),%rax
je     1183 <__libc_calloc+0x63>
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <__errno_location@plt>
mov    -0x24(%rbp),%ecx
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    1190 <__libc_calloc+0x70>
mov    -0x20(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__libc_calloc>:
mov    %rdi,%rax
mul    %rsi
seto   %cl
test   %rdi,%rdi
je     1149 <__libc_calloc+0x29>
test   %cl,%cl
je     1149 <__libc_calloc+0x29>
push   %rbx
mov    0x2ea6(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1030 <__errno_location@plt>
mov    %ebx,(%rax)
xor    %eax,%eax
pop    %rbx
ret
mov    %rax,%rdi
jmp    1040 <malloc@plt>

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

LLVM IR (-O2):
@ENOMEM = global i32 0
define noalias i8* @__libc_calloc(i64 %0, i64 %1) {
%3 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %0, i64 %1)
%4 = extractvalue { i64, i1 } %3, 0
%5 = icmp eq i64 %0, 0
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = extractvalue { i64, i1 } %3, 1
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = load i32, i32* @ENOMEM
%10 = tail call i32* (...) @__errno_location()
store i32 %9, i32* %10
br label %13
11: ; preds = %6, %2
%12 = tail call i8* @malloc(i64 %4)
br label %13
13: ; preds = %11, %8
%14 = phi i8* [ null, %8 ], [ %12, %11 ]
ret i8* %14
}