#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 *calloc(size_t, size_t);
int /*<<< orphan*/ fail(int, char const *, unsigned int, char *, long);
void *scalloc(size_t nmemb, size_t size, const char *file, unsigned line) {
  void *restrict res = calloc(nmemb, size);
  if (!res && nmemb)
    fail(1, file, line, "allocation of %ld bytes failed\n", (long)size * nmemb);
  return res;
}


x86 assembly (clang, -O0):
<scalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117f <scalloc+0x5f>
cmpq   $0x0,-0x8(%rbp)
je     117f <scalloc+0x5f>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%r8
imul   -0x8(%rbp),%r8
mov    $0x1,%edi
lea    0xe86(%rip),%rcx
call   1030 <fail@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scalloc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1040 <calloc@plt>
mov    %rax,%r12
test   %rbp,%rbp
je     1164 <scalloc+0x44>
test   %r12,%r12
jne    1164 <scalloc+0x44>
imul   %rbp,%rbx
lea    0xeaf(%rip),%rcx
mov    $0x1,%edi
mov    %r15,%rsi
mov    %r14d,%edx
mov    %rbx,%r8
call   1030 <fail@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"allocation of %ld bytes failed\0A\00"
define i8* @scalloc(i64 %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i64 %0, i64* %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i64, i64* %5
%11 = load i64, i64* %6
%12 = call i8* @calloc(i64 %10, i64 %11)
store i8* %12, i8** %9
%13 = load i8*, i8** %9
%14 = icmp ne i8* %13, null
br i1 %14, label %25, label %15
15: ; preds = %4
%16 = load i64, i64* %5
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = load i8*, i8** %7
%20 = load i32, i32* %8
%21 = load i64, i64* %6
%22 = load i64, i64* %5
%23 = mul i64 %21, %22
%24 = call i32 @fail(i32 1, i8* %19, i32 %20, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i64 %23)
br label %25
25: ; preds = %18, %15, %4
%26 = load i8*, i8** %9
ret i8* %26
}

LLVM IR (-O2):
@.str = [32 x i8] c"allocation of %ld bytes failed\0A\00"
define noalias i8* @scalloc(i64 %0, i64 %1, i8* %2, i32 %3) {
%5 = tail call i8* @calloc(i64 %0, i64 %1)
%6 = icmp eq i8* %5, null
%7 = icmp ne i64 %0, 0
%8 = and i1 %7, %6
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = mul i64 %1, %0
%11 = tail call i32 @fail(i32 1, i8* %2, i32 %3, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i64 %10)
br label %12
12: ; preds = %9, %4
ret i8* %5
}