#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t, char *, int);
int /*<<< orphan*/ stderr;
void check_allocation1(void *p, size_t size, char *file, int line,
                       int exit_on_null) {
  if (p == NULL) {
    fprintf(stderr,
            "Failed to allocate memory %ld bytes at %s,"
            " line %d.\n",
            size, file, line);
    if (exit_on_null)
      exit(1);
  }
}


x86 assembly (clang, -O0):
<check_allocation1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1180 <check_allocation1+0x60>
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    0xe9e(%rip),%rsi
call   1030 <fprintf@plt>
cmpl   $0x0,-0x20(%rbp)
je     117b <check_allocation1+0x5b>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    1180 <check_allocation1+0x60>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_allocation1>:
push   %rbx
test   %rdi,%rdi
jne    114b <check_allocation1+0x2b>
mov    %r8d,%ebx
mov    %ecx,%r8d
mov    %rdx,%rcx
mov    %rsi,%rdx
mov    0x2ea7(%rip),%rax
mov    (%rax),%edi
lea    0xebe(%rip),%rsi
call   1030 <fprintf@plt>
test   %ebx,%ebx
jne    114d <check_allocation1+0x2d>
pop    %rbx
ret
mov    $0x1,%edi
call   1040 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [53 x i8] c"Failed to allocate memory %ld bytes at %s, line %d.\0A\00"
define void @check_allocation1(i8* readnone %0, i64 %1, i8* %2, i32 %3, i32 %4) {
%6 = icmp eq i8* %0, null
br i1 %6, label %7, label %13
7: ; preds = %5
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i64 %1, i8* %2, i32 %3)
%10 = icmp eq i32 %4, 0
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7, %5
ret void
}