#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*/ assert(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ stderr;
void *Malloc(size_t size) {
  void *new;
  int *p;
  assert(size > 0 && size <= INT_MAX);
  ;
  p = (int *)malloc(size + 2 * sizeof(int));
  ;
  if (!p) {
    fprintf(stderr, "Malloc(%ld) failed\n", (long)size);
    exit(1);
  }
  p[0] = 0x42;
  p[1] = size;
  new = &p[2];
  memset(new, 0, size);
  return new;
}


x86 assembly (clang, -O0):
<Malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x19(%rbp)
jbe    1180 <Malloc+0x30>
mov    -0x8(%rbp),%rax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rax
setbe  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
add    $0x8,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cc <Malloc+0x7c>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe43(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rax
movl   $0x42,(%rax)
mov    -0x8(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Malloc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
setne  %al
mov    0x2e84(%rip),%rcx
cmp    %rdi,(%rcx)
setae  %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
lea    0x8(%r14),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11ab <Malloc+0x5b>
mov    %rax,%rbx
movl   $0x42,(%rax)
mov    %r14d,0x4(%rax)
add    $0x8,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@INT_MAX = global i64 0
@stderr = global i32 0
@.str = [20 x i8] c"Malloc(%ld) failed\0A\00"
define i8* @Malloc(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32*
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = icmp ugt i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i64, i64* %2
%9 = load i64, i64* @INT_MAX
%10 = icmp ule i64 %8, %9
br label %11
11: ; preds = %7, %1
%12 = phi i1 [ false, %1 ], [ %10, %7 ]
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i64, i64* %2
%16 = add i64 %15, 8
%17 = call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i32*
store i32* %18, i32** %4
%19 = load i32*, i32** %4
%20 = icmp ne i32* %19, null
br i1 %20, label %26, label %21
21: ; preds = %11
%22 = load i32, i32* @stderr
%23 = load i64, i64* %2
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i64 %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %11
%27 = load i32*, i32** %4
%28 = getelementptr inbounds i32, i32* %27, i64 0
store i32 66, i32* %28
%29 = load i64, i64* %2
%30 = trunc i64 %29 to i32
%31 = load i32*, i32** %4
%32 = getelementptr inbounds i32, i32* %31, i64 1
store i32 %30, i32* %32
%33 = load i32*, i32** %4
%34 = getelementptr inbounds i32, i32* %33, i64 2
%35 = bitcast i32* %34 to i8*
store i8* %35, i8** %3
%36 = load i8*, i8** %3
%37 = load i64, i64* %2
%38 = call i32 @memset(i8* %36, i32 0, i64 %37)
%39 = load i8*, i8** %3
ret i8* %39
}

LLVM IR (-O2):
@INT_MAX = global i64 0
@stderr = global i32 0
@.str = [20 x i8] c"Malloc(%ld) failed\0A\00"
define i8* @Malloc(i64 %0) {
%2 = icmp ne i64 %0, 0
%3 = load i64, i64* @INT_MAX
%4 = icmp uge i64 %3, %0
%5 = select i1 %2, i1 %4, i1 false
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = add i64 %0, 8
%9 = tail call i64 @malloc(i64 %8)
%10 = inttoptr i64 %9 to i32*
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i64 %0)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %1
store i32 66, i32* %10
%17 = trunc i64 %0 to i32
%18 = getelementptr inbounds i32, i32* %10, i64 1
store i32 %17, i32* %18
%19 = getelementptr inbounds i32, i32* %10, i64 2
%20 = bitcast i32* %19 to i8*
%21 = tail call i32 @memset(i8* %20, i32 0, i64 %0)
ret i8* %20
}