#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(int);
void *safe_malloc_mul_2op_(size_t, size_t);
void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3) {
  if (!size1 || (!size2 && !size3))
    return malloc(1);
  size2 += size3;
  if (size2 < size3)
    return 0;
  return safe_malloc_mul_2op_(size1, size2);
}


x86 assembly (clang, -O0):
<safe_malloc_muladd2_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1155 <safe_malloc_muladd2_+0x35>
cmpq   $0x0,-0x18(%rbp)
jne    1168 <safe_malloc_muladd2_+0x48>
cmpq   $0x0,-0x20(%rbp)
jne    1168 <safe_malloc_muladd2_+0x48>
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11a0 <safe_malloc_muladd2_+0x80>
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    118f <safe_malloc_muladd2_+0x6f>
movq   $0x0,-0x8(%rbp)
jmp    11a0 <safe_malloc_muladd2_+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <safe_malloc_mul_2op_@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_malloc_muladd2_>:
test   %rdi,%rdi
je     1135 <safe_malloc_muladd2_+0x15>
mov    %rdx,%rax
or     %rsi,%rax
je     1135 <safe_malloc_muladd2_+0x15>
add    %rsi,%rdx
jae    113f <safe_malloc_muladd2_+0x1f>
xor    %eax,%eax
ret
mov    $0x1,%edi
jmp    1040 <malloc@plt>
mov    %rdx,%rsi
jmp    1030 <safe_malloc_mul_2op_@plt>

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

LLVM IR (-O2):
define i8* @safe_malloc_muladd2_(i64 %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %0, 0
%5 = or i64 %2, %1
%6 = icmp eq i64 %5, 0
%7 = or i1 %4, %6
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
br label %15
10: ; preds = %3
%11 = add i64 %2, %1
%12 = icmp ult i64 %11, %2
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i8* @safe_malloc_mul_2op_(i64 %0, i64 %11)
br label %15
15: ; preds = %10, %13, %8
%16 = phi i8* [ %14, %13 ], [ %9, %8 ], [ null, %10 ]
ret i8* %16
}