#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*/ Panic(char *, char *, int, ...);
void *malloc(size_t);
void *UtilSafeMallocInternal(int bugNumber, size_t size, char *file,
                             int lineno) {
  void *result = malloc(size);
  if (result == ((void *)0) && size != 0) {
    if (bugNumber == -1) {
      Panic("Unrecoverable memory allocation failure at %s:%d\n", file, lineno);
    } else {
      Panic("Unrecoverable memory allocation failure at %s:%d.  Bug "
            "number: %d\n",
            file, lineno, bugNumber);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<UtilSafeMallocInternal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119a <UtilSafeMallocInternal+0x7a>
cmpq   $0x0,-0x10(%rbp)
je     119a <UtilSafeMallocInternal+0x7a>
cmpl   $0xffffffff,-0x4(%rbp)
jne    117d <UtilSafeMallocInternal+0x5d>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <Panic@plt>
jmp    1195 <UtilSafeMallocInternal+0x75>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x4(%rbp),%ecx
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <Panic@plt>
jmp    119a <UtilSafeMallocInternal+0x7a>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UtilSafeMallocInternal>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %edi,%r12d
mov    %rsi,%rdi
call   1030 <malloc@plt>
mov    %rax,%rbx
test   %rbp,%rbp
je     117c <UtilSafeMallocInternal+0x5c>
test   %rbx,%rbx
jne    117c <UtilSafeMallocInternal+0x5c>
cmp    $0xffffffff,%r12d
je     1168 <UtilSafeMallocInternal+0x48>
lea    0xedc(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1040 <Panic@plt>
jmp    117c <UtilSafeMallocInternal+0x5c>
lea    0xe91(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <Panic@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"Unrecoverable memory allocation failure at %s:%d\0A\00"
@.str.1 = [67 x i8] c"Unrecoverable memory allocation failure at %s:%d. Bug number: %d\0A\00"
define i8* @UtilSafeMallocInternal(i32 %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i64, i64* %6
%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 %30
14: ; preds = %4
%15 = load i64, i64* %6
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %14
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i8*, i8** %7
%22 = load i32, i32* %8
%23 = call i32 (i8*, i8*, i32, ...) @Panic(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %21, i32 %22)
br label %29
24: ; preds = %17
%25 = load i8*, i8** %7
%26 = load i32, i32* %8
%27 = load i32, i32* %5
%28 = call i32 (i8*, i8*, i32, ...) @Panic(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i8* %25, i32 %26, i32 %27)
br label %29
29: ; preds = %24, %20
br label %30
30: ; preds = %29, %14, %4
%31 = load i8*, i8** %9
ret i8* %31
}

LLVM IR (-O2):
@.str = [50 x i8] c"Unrecoverable memory allocation failure at %s:%d\0A\00"
@.str.1 = [67 x i8] c"Unrecoverable memory allocation failure at %s:%d. Bug number: %d\0A\00"
define noalias i8* @UtilSafeMallocInternal(i32 %0, i64 %1, i8* %2, i32 %3) {
%5 = tail call i8* @malloc(i64 %1)
%6 = icmp eq i8* %5, null
%7 = icmp ne i64 %1, 0
%8 = and i1 %7, %6
br i1 %8, label %9, label %15
9: ; preds = %4
%10 = icmp eq i32 %0, -1
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i32 (i8*, i8*, i32, ...) @Panic(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %3)
br label %15
13: ; preds = %9
%14 = tail call i32 (i8*, i8*, i32, ...) @Panic(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %3, i32 %0)
br label %15
15: ; preds = %11, %13, %4
ret i8* %5
}