#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*/ aprintf(char *, ...);
int /*<<< orphan*/ comma_print(char *, int);
int /*<<< orphan*/ exit(int);
void mem_warn(char *name, int size, int exitcode) {
  static char buf[128];
  aprintf("\n"
          "\x1b[1m\x1b[31m"
          "\aCannot allocate enough memory for "
          "function %s."
          "\x1b[0m\x1b[37m"
          "\n",
          name);
  comma_print(buf, size);
  aprintf("    "
          "\x1b[1m\x1b[31m"
          "(Needed %s bytes.)"
          "\x1b[0m\x1b[37m"
          "\n\n",
          buf);
  if (exitcode != 0) {
    aprintf("    "
            "\x1b[1m\x1b[31m"
            "Program terminated."
            "\x1b[0m\x1b[37m"
            "\n\n");
    exit(exitcode);
  }
}


x86 assembly (clang, -O0):
<mem_warn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <aprintf@plt>
mov    -0xc(%rbp),%esi
lea    0x2ef2(%rip),%rdi
call   1040 <comma_print@plt>
lea    0xeda(%rip),%rdi
lea    0x2edf(%rip),%rsi
mov    $0x0,%al
call   1030 <aprintf@plt>
cmpl   $0x0,-0x10(%rbp)
je     1198 <mem_warn+0x68>
lea    0xee6(%rip),%rdi
mov    $0x0,%al
call   1030 <aprintf@plt>
mov    -0x10(%rbp),%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_warn>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rsi
lea    0xebd(%rip),%rdi
xor    %eax,%eax
call   1030 <aprintf@plt>
lea    0x2eff(%rip),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <comma_print@plt>
lea    0xee2(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <aprintf@plt>
test   %r14d,%r14d
jne    1176 <mem_warn+0x46>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xef2(%rip),%rdi
xor    %eax,%eax
call   1030 <aprintf@plt>
mov    %r14d,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@mem_warn.buf = internal global [128 x i8] zeroinitializer
@.str = [68 x i8] c"\0A\1B[1m\1B[31m\07Cannot allocate enough memory for function %s.\1B[0m\1B[37m\0A\00"
@.str.1 = [43 x i8] c" \1B[1m\1B[31m(Needed %s bytes.)\1B[0m\1B[37m\0A\0A\00"
@.str.2 = [44 x i8] c" \1B[1m\1B[31mProgram terminated.\1B[0m\1B[37m\0A\0A\00"
define void @mem_warn(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i8*, i8** %4
%8 = call i32 (i8*, ...) @aprintf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* %5
%10 = call i32 @comma_print(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mem_warn.buf, i64 0, i64 0), i32 %9)
%11 = call i32 (i8*, ...) @aprintf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mem_warn.buf, i64 0, i64 0))
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = call i32 (i8*, ...) @aprintf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* %6
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %3
ret void
}

LLVM IR (-O2):
@mem_warn.buf = internal global [128 x i8] zeroinitializer
@.str = [68 x i8] c"\0A\1B[1m\1B[31m\07Cannot allocate enough memory for function %s.\1B[0m\1B[37m\0A\00"
@.str.1 = [43 x i8] c" \1B[1m\1B[31m(Needed %s bytes.)\1B[0m\1B[37m\0A\0A\00"
@.str.2 = [44 x i8] c" \1B[1m\1B[31mProgram terminated.\1B[0m\1B[37m\0A\0A\00"
define void @mem_warn(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @aprintf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = tail call i32 @comma_print(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mem_warn.buf, i64 0, i64 0), i32 %1)
%6 = tail call i32 (i8*, ...) @aprintf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([128 x i8], [128 x i8]* @mem_warn.buf, i64 0, i64 0))
%7 = icmp eq i32 %2, 0
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = tail call i32 (i8*, ...) @aprintf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @exit(i32 %2)
unreachable
11: ; preds = %3
ret void
}