#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;
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_try_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) {
    return NULL;
  }
  p[0] = 0x42;
  p[1] = (int)size;
  new = &p[2];
  memset(new, 0, size);
  return new;
}


x86 assembly (clang, -O0):
<slurm_try_xmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jb     116b <slurm_try_xmalloc+0x3b>
mov    -0x10(%rbp),%rax
mov    0x2e8b(%rip),%rcx
cmp    (%rcx),%rax
ja     116b <slurm_try_xmalloc+0x3b>
jmp    1189 <slurm_try_xmalloc+0x59>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
lea    0xe83(%rip),%rdi
lea    0xe98(%rip),%r8
call   1030 <malloc_assert_failed@plt>
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11b2 <slurm_try_xmalloc+0x82>
movq   $0x0,-0x8(%rbp)
jmp    11ec <slurm_try_xmalloc+0xbc>
mov    -0x38(%rbp),%rax
movl   $0x42,(%rax)
mov    -0x10(%rbp),%rax
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x38(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slurm_try_xmalloc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eaa(%rip),%rax
cmp    %rdi,(%rax)
jae    1156 <slurm_try_xmalloc+0x26>
lea    0xeb6(%rip),%rdi
lea    0xecb(%rip),%r8
call   1030 <malloc_assert_failed@plt>
lea    0x8(%r14),%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     1184 <slurm_try_xmalloc+0x54>
mov    %rax,%rbx
movl   $0x42,(%rax)
mov    %r14d,0x4(%rax)
add    $0x8,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1040 <memset@plt>
jmp    1186 <slurm_try_xmalloc+0x56>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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_try_xmalloc(i64 %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
store i64 %0, i64* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%12 = load i64, i64* %6
%13 = icmp uge i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %4
%15 = load i64, i64* %6
%16 = load i64, i64* @INT_MAX
%17 = icmp ule i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14
br label %23
19: ; preds = %14, %4
%20 = load i8*, i8** %7
%21 = load i32, i32* %8
%22 = load i8*, i8** %9
br label %23
23: ; preds = %19, %18
%24 = load i64, i64* %6
%25 = add i64 %24, 8
%26 = call i64 @malloc(i64 %25)
%27 = inttoptr i64 %26 to i32*
store i32* %27, i32** %11
%28 = load i32*, i32** %11
%29 = icmp ne i32* %28, null
br i1 %29, label %31, label %30
30: ; preds = %23
store i8* null, i8** %5
br label %45
31: ; preds = %23
%32 = load i32*, i32** %11
%33 = getelementptr inbounds i32, i32* %32, i64 0
store i32 66, i32* %33
%34 = load i64, i64* %6
%35 = trunc i64 %34 to i32
%36 = load i32*, i32** %11
%37 = getelementptr inbounds i32, i32* %36, i64 1
store i32 %35, i32* %37
%38 = load i32*, i32** %11
%39 = getelementptr inbounds i32, i32* %38, i64 2
%40 = bitcast i32* %39 to i8*
store i8* %40, i8** %10
%41 = load i8*, i8** %10
%42 = load i64, i64* %6
%43 = call i32 @memset(i8* %41, i32 0, i64 %42)
%44 = load i8*, i8** %10
store i8* %44, i8** %5
br label %45
45: ; preds = %31, %30
%46 = load i8*, i8** %5
ret i8* %46
}

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_try_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 %19, label %13
13: ; preds = %8
store i32 66, i32* %11
%14 = trunc i64 %0 to i32
%15 = getelementptr inbounds i32, i32* %11, i64 1
store i32 %14, i32* %15
%16 = getelementptr inbounds i32, i32* %11, i64 2
%17 = bitcast i32* %16 to i8*
%18 = tail call i32 @memset(i8* %17, i32 0, i64 %0)
br label %19
19: ; preds = %8, %13
%20 = phi i8* [ %17, %13 ], [ null, %8 ]
ret i8* %20
}