#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*/ aroma_memory_terminate(char *);
int /*<<< orphan*/ aroma_touch_memaddr(void *, size_t, long, char *);
void *malloc(int);
void *aroma_malloc(size_t size, long line, char *filename) {
  void *ret = malloc(size);
  if (!ret && !size) {
    ret = malloc(1);
  }
  if (!ret) {
    if (!ret && !size) {
      ret = malloc(1);
    }
    if (!ret) {
      aroma_memory_terminate("Out Of Memory...\n");
    }
  }
  aroma_touch_memaddr(ret, size, line, filename);
  return ret;
}


x86 assembly (clang, -O0):
<aroma_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1177 <aroma_malloc+0x47>
cmpq   $0x0,-0x8(%rbp)
jne    1177 <aroma_malloc+0x47>
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c2 <aroma_malloc+0x92>
cmpq   $0x0,-0x20(%rbp)
jne    11a6 <aroma_malloc+0x76>
cmpq   $0x0,-0x8(%rbp)
jne    11a6 <aroma_malloc+0x76>
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bd <aroma_malloc+0x8d>
lea    0xe48(%rip),%rdi
call   1030 <aroma_memory_terminate@plt>
jmp    11c2 <aroma_malloc+0x92>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1040 <aroma_touch_memaddr@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aroma_malloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %r12,%r12
jne    1160 <aroma_malloc+0x30>
test   %rbx,%rbx
jne    1160 <aroma_malloc+0x30>
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rbx,%rbx
jne    118a <aroma_malloc+0x5a>
test   %r12,%r12
jne    117c <aroma_malloc+0x4c>
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    118a <aroma_malloc+0x5a>
lea    0xe7d(%rip),%rdi
call   1030 <aroma_memory_terminate@plt>
xor    %ebx,%ebx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1040 <aroma_touch_memaddr@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Out Of Memory...\0A\00"
define i8* @aroma_malloc(i64 %0, i64 %1, i8* %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
store i64 %0, i64* %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%8 = load i64, i64* %4
%9 = trunc i64 %8 to i32
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %3
%14 = load i64, i64* %4
%15 = icmp ne i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = call i8* @malloc(i32 1)
store i8* %17, i8** %7
br label %18
18: ; preds = %16, %13, %3
%19 = load i8*, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %35, label %21
21: ; preds = %18
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %29, label %24
24: ; preds = %21
%25 = load i64, i64* %4
%26 = icmp ne i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = call i8* @malloc(i32 1)
store i8* %28, i8** %7
br label %29
29: ; preds = %27, %24, %21
%30 = load i8*, i8** %7
%31 = icmp ne i8* %30, null
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i32 @aroma_memory_terminate(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
br label %35
35: ; preds = %34, %18
%36 = load i8*, i8** %7
%37 = load i64, i64* %4
%38 = load i64, i64* %5
%39 = load i8*, i8** %6
%40 = call i32 @aroma_touch_memaddr(i8* %36, i64 %37, i64 %38, i8* %39)
%41 = load i8*, i8** %7
ret i8* %41
}

LLVM IR (-O2):
@.str = [18 x i8] c"Out Of Memory...\0A\00"
define i8* @aroma_malloc(i64 %0, i64 %1, i8* %2) {
%4 = trunc i64 %0 to i32
%5 = tail call i8* @malloc(i32 %4)
%6 = icmp ne i8* %5, null
%7 = icmp ne i64 %0, 0
%8 = or i1 %7, %6
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
br label %11
11: ; preds = %9, %3
%12 = phi i8* [ %5, %3 ], [ %10, %9 ]
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %20
14: ; preds = %11
br i1 %7, label %18, label %15
15: ; preds = %14
%16 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %14, %15
%19 = tail call i32 @aroma_memory_terminate(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %15, %18, %11
%21 = phi i8* [ %12, %11 ], [ %16, %15 ], [ null, %18 ]
%22 = tail call i32 @aroma_touch_memaddr(i8* %21, i64 %0, i64 %1, i8* %2)
ret i8* %21
}