#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;
void *realloc(void *, size_t);
scalar_t__ smtp_si_mul_size_t(size_t, size_t, size_t *);
void *smtp_reallocarray(void *ptr, size_t nmemb, size_t size) {
  void *alloc;
  size_t size_mul;
  if (smtp_si_mul_size_t(nmemb, size, &size_mul)) {
    alloc = NULL;
    errno = ENOMEM;
  } else {
    alloc = realloc(ptr, size_mul);
  }
  return alloc;
}


x86 assembly (clang, -O0):
<smtp_reallocarray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <smtp_si_mul_size_t@plt>
cmp    $0x0,%rax
je     116e <smtp_reallocarray+0x4e>
movq   $0x0,-0x20(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%ecx
mov    0x2e71(%rip),%rax
mov    %ecx,(%rax)
jmp    117f <smtp_reallocarray+0x5f>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smtp_reallocarray>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rax
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
call   1030 <smtp_si_mul_size_t@plt>
test   %rax,%rax
je     1156 <smtp_reallocarray+0x36>
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    0x2e88(%rip),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
jmp    1163 <smtp_reallocarray+0x43>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <realloc@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@ENOMEM = global i32 0
@errno = global i32 0
define i8* @smtp_reallocarray(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = load i64, i64* %5
%10 = load i64, i64* %6
%11 = call i64 @smtp_si_mul_size_t(i64 %9, i64 %10, i64* %8)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %3
store i8* null, i8** %7
%14 = load i32, i32* @ENOMEM
store i32 %14, i32* @errno
br label %19
15: ; preds = %3
%16 = load i8*, i8** %4
%17 = load i64, i64* %8
%18 = call i8* @realloc(i8* %16, i64 %17)
store i8* %18, i8** %7
br label %19
19: ; preds = %15, %13
%20 = load i8*, i8** %7
ret i8* %20
}

LLVM IR (-O2):
@ENOMEM = global i32 0
@errno = global i32 0
define noalias i8* @smtp_reallocarray(i8* nocapture %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = call i64 @smtp_si_mul_size_t(i64 %1, i64 %2, i64* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = load i32, i32* @ENOMEM
store i32 %9, i32* @errno
br label %13
10: ; preds = %3
%11 = load i64, i64* %4
%12 = call i8* @realloc(i8* %0, i64 %11)
br label %13
13: ; preds = %10, %8
%14 = phi i8* [ null, %8 ], [ %12, %10 ]
ret i8* %14
}