#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 */
size_t INT_MAX;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ log_oom(char const *, int, char const *);
scalar_t__ malloc(size_t);
void malloc_assert_failed(char *, char const *, int, char const *, char *);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
void *slurm_xmalloc(size_t size, const char *file, int line, const char *func) {
  void *new;
  int *p;
  (void)({
    (size >= 0 && size <= INT_MAX)
        ? ((void)(0))
        : malloc_assert_failed("size >= 0 && size <= INT_MAX", file, line, func,
                               "");
  });
  ;
  p = (int *)malloc(size + 2 * sizeof(int));
  ;
  if (!p) {
    log_oom(file, line, func);
    abort();
  }
  p[0] = 0x42;
  p[1] = (int)size;
  new = &p[2];
  memset(new, 0, size);
  return new;
}


x86 assembly (clang, -O0):
<slurm_xmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
jb     118b <slurm_xmalloc+0x3b>
mov    -0x8(%rbp),%rax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%rax
ja     118b <slurm_xmalloc+0x3b>
jmp    11a9 <slurm_xmalloc+0x59>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    0xe63(%rip),%rdi
lea    0xe78(%rip),%r8
call   1040 <malloc_assert_failed@plt>
mov    -0x8(%rbp),%rdi
add    $0x8,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11dc <slurm_xmalloc+0x8c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1060 <log_oom@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x30(%rbp),%rax
movl   $0x42,(%rax)
mov    -0x8(%rbp),%rax
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slurm_xmalloc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x2e7d(%rip),%rax
cmp    %rdi,(%rax)
jae    118c <slurm_xmalloc+0x3c>
lea    0xe89(%rip),%rdi
lea    0xe9e(%rip),%r8
mov    %r12,%rsi
mov    %r15d,%edx
mov    %r14,%rcx
call   1040 <malloc_assert_failed@plt>
lea    0x8(%rbx),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     11c3 <slurm_xmalloc+0x73>
mov    %rax,%rbp
movl   $0x42,(%rax)
mov    %ebx,0x4(%rax)
add    $0x8,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1060 <log_oom@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@INT_MAX = global i64 0
@.str = [29 x i8] c"size >= 0 && size <= INT_MAX\00"
@.str.1 = [1 x i8] zeroinitializer
define i8* @slurm_xmalloc(i64 %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
store i64 %0, i64* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%11 = load i64, i64* %5
%12 = icmp uge i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = load i64, i64* %5
%15 = load i64, i64* @INT_MAX
%16 = icmp ule i64 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %13
br label %22
18: ; preds = %13, %4
%19 = load i8*, i8** %6
%20 = load i32, i32* %7
%21 = load i8*, i8** %8
br label %22
22: ; preds = %18, %17
%23 = load i64, i64* %5
%24 = add i64 %23, 8
%25 = call i64 @malloc(i64 %24)
%26 = inttoptr i64 %25 to i32*
store i32* %26, i32** %10
%27 = load i32*, i32** %10
%28 = icmp ne i32* %27, null
br i1 %28, label %35, label %29
29: ; preds = %22
%30 = load i8*, i8** %6
%31 = load i32, i32* %7
%32 = load i8*, i8** %8
%33 = call i32 @log_oom(i8* %30, i32 %31, i8* %32)
%34 = call i32 (...) @abort()
unreachable
35: ; preds = %22
%36 = load i32*, i32** %10
%37 = getelementptr inbounds i32, i32* %36, i64 0
store i32 66, i32* %37
%38 = load i64, i64* %5
%39 = trunc i64 %38 to i32
%40 = load i32*, i32** %10
%41 = getelementptr inbounds i32, i32* %40, i64 1
store i32 %39, i32* %41
%42 = load i32*, i32** %10
%43 = getelementptr inbounds i32, i32* %42, i64 2
%44 = bitcast i32* %43 to i8*
store i8* %44, i8** %9
%45 = load i8*, i8** %9
%46 = load i64, i64* %5
%47 = call i32 @memset(i8* %45, i32 0, i64 %46)
%48 = load i8*, i8** %9
ret i8* %48
}

LLVM IR (-O2):
@INT_MAX = global i64 0
@.str = [29 x i8] c"size >= 0 && size <= INT_MAX\00"
@.str.1 = [1 x i8] zeroinitializer
define i8* @slurm_xmalloc(i64 %0, i8* %1, i32 %2, i8* %3) {
%5 = load i64, i64* @INT_MAX
%6 = icmp ult i64 %5, %0
br i1 %6, label %7, label %8
7: ; preds = %4
tail call void @malloc_assert_failed(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %2, i8* %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %4, %7
%9 = add i64 %0, 8
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i32*
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = tail call i32 @log_oom(i8* %1, i32 %2, i8* %3)
%15 = tail call i32 (...) @abort()
unreachable
16: ; preds = %8
store i32 66, i32* %11
%17 = trunc i64 %0 to i32
%18 = getelementptr inbounds i32, i32* %11, i64 1
store i32 %17, i32* %18
%19 = getelementptr inbounds i32, i32* %11, i64 2
%20 = bitcast i32* %19 to i8*
%21 = tail call i32 @memset(i8* %20, i32 0, i64 %0)
ret i8* %20
}