#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 *malloc(size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ syserr(char *, size_t);
void *safe_raw_allocate(size_t number, size_t sizeOfElement) {
  if (number == 0)
    return NULL;
  size_t size = number * sizeOfElement;
  void *data = malloc(size);
  if (data == NULL)
    syserr(
        "safe_raw_allocate - malloc returned NULL while allocating %zu bytes",
        size);
  memset(data, 0, size);
  return data;
}


x86 assembly (clang, -O0):
<safe_raw_allocate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1158 <safe_raw_allocate+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11a4 <safe_raw_allocate+0x74>
mov    -0x10(%rbp),%rax
imul   -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118d <safe_raw_allocate+0x5d>
mov    -0x20(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1030 <syserr@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_raw_allocate>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     116e <safe_raw_allocate+0x3e>
mov    %rsi,%rbx
imul   %rdi,%rbx
mov    %rbx,%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    115f <safe_raw_allocate+0x2f>
lea    0xea9(%rip),%rdi
mov    %rbx,%rsi
call   1030 <syserr@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <memset@plt>
jmp    1171 <safe_raw_allocate+0x41>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [68 x i8] c"safe_raw_allocate - malloc returned NULL while allocating %zu bytes\00"
define i8* @safe_raw_allocate(i64 %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
store i64 %0, i64* %4
store i64 %1, i64* %5
%8 = load i64, i64* %4
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i8* null, i8** %3
br label %27
11: ; preds = %2
%12 = load i64, i64* %4
%13 = load i64, i64* %5
%14 = mul i64 %12, %13
store i64 %14, i64* %6
%15 = load i64, i64* %6
%16 = call i8* @malloc(i64 %15)
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = load i64, i64* %6
%21 = call i32 @syserr(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i64 %20)
br label %22
22: ; preds = %19, %11
%23 = load i8*, i8** %7
%24 = load i64, i64* %6
%25 = call i32 @memset(i8* %23, i32 0, i64 %24)
%26 = load i8*, i8** %7
store i8* %26, i8** %3
br label %27
27: ; preds = %22, %10
%28 = load i8*, i8** %3
ret i8* %28
}

LLVM IR (-O2):
@.str = [68 x i8] c"safe_raw_allocate - malloc returned NULL while allocating %zu bytes\00"
define i8* @safe_raw_allocate(i64 %0, i64 %1) {
%3 = icmp eq i64 %0, 0
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = mul i64 %1, %0
%6 = tail call i8* @malloc(i64 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @syserr(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i64 %5)
br label %10
10: ; preds = %8, %4
%11 = tail call i32 @memset(i8* %6, i32 0, i64 %5)
br label %12
12: ; preds = %2, %10
%13 = phi i8* [ %6, %10 ], [ null, %2 ]
ret i8* %13
}