#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 errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, size_t,
                           char const *, char const *, int);
void *malloc(size_t);
int /*<<< orphan*/ stderr;
void *my_malloc(size_t s, const char *file, int line, const char *func) {
  void *p = malloc(s);
  if (p == NULL) {
    fprintf(stderr, "Out of memory: %d, %li bytes in %s (%s:%i)\n", errno, s,
            func, file, line);
    exit(1);
  }
  return p;
}


x86 assembly (clang, -O0):
<my_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1199 <my_malloc+0x69>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x10(%rbp),%r9
mov    -0x14(%rbp),%eax
lea    0xe79(%rip),%rsi
mov    %eax,(%rsp)
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_malloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
call   1040 <malloc@plt>
test   %rax,%rax
je     1157 <my_malloc+0x27>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
mov    %ebp,(%rsp)
lea    0xe8d(%rip),%rsi
mov    %rbx,%rcx
mov    %r14,%r8
mov    %r15,%r9
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"Out of memory: %d, %li bytes in %s (%s:%i)\0A\00"
@errno = global i32 0
define i8* @my_malloc(i64 %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i64 %0, i64* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%10 = load i64, i64* %5
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %9
%12 = load i8*, i8** %9
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %23
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = load i64, i64* %5
%18 = load i8*, i8** %8
%19 = load i8*, i8** %6
%20 = load i32, i32* %7
%21 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %16, i64 %17, i8* %18, i8* %19, i32 %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %4
%24 = load i8*, i8** %9
ret i8* %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"Out of memory: %d, %li bytes in %s (%s:%i)\0A\00"
@errno = global i32 0
define noalias i8* @my_malloc(i64 %0, i8* %1, i32 %2, i8* %3) {
%5 = tail call i8* @malloc(i64 %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %9, i64 %0, i8* %3, i8* %1, i32 %2)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %4
ret i8* %5
}