#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 MAP_ANON;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
void *calloc(int, size_t);
void *mmap(int /*<<< orphan*/ *, size_t, int, int, int, int /*<<< orphan*/);
void *xmm_new(size_t size) {
  void *m = NULL;
  if (size > 0) {
    if (size < 4096)
      m = calloc(1, size);
    else {
      m = mmap(NULL, (((size / 4096) + ((size % 4096) != 0)) * 4096),
               PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
      if (m == NULL || m == (void *)-1)
        m = NULL;
    }
  }
  return m;
}


x86 assembly (clang, -O0):
<xmm_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jbe    11f3 <xmm_new+0xd3>
cmpq   $0x1000,-0x8(%rbp)
jae    1164 <xmm_new+0x44>
mov    -0x8(%rbp),%rsi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
jmp    11ee <xmm_new+0xce>
mov    -0x8(%rbp),%rsi
shr    $0xc,%rsi
mov    -0x8(%rbp),%rax
and    $0xfff,%rax
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
cltq
add    %rax,%rsi
shl    $0xc,%rsi
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
mov    0x2e3d(%rip),%rax
or     (%rax),%edx
mov    0x2e2c(%rip),%rax
mov    (%rax),%ecx
mov    0x2e1b(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e1 <xmm_new+0xc1>
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x10(%rbp)
jne    11e9 <xmm_new+0xc9>
movq   $0x0,-0x10(%rbp)
jmp    11ee <xmm_new+0xce>
jmp    11f3 <xmm_new+0xd3>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xmm_new>:
test   %rdi,%rdi
je     113e <xmm_new+0x1e>
mov    %rdi,%rax
cmp    $0xfff,%rdi
ja     1141 <xmm_new+0x21>
mov    $0x1,%edi
mov    %rax,%rsi
jmp    1040 <calloc@plt>
xor    %eax,%eax
ret
push   %rbx
xor    %esi,%esi
test   $0xfff,%eax
setne  %sil
shl    $0xc,%rsi
add    %rax,%rsi
and    $0xfffffffffffff000,%rsi
mov    0x2e96(%rip),%rax
mov    0x2e6f(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e5c(%rip),%rax
mov    0x2e4d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %ebx,%ebx
xor    %edi,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rcx
cmp    $0xffffffffffffffff,%rax
cmove  %rbx,%rax
test   %rcx,%rcx
cmove  %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANON = global i32 0
@MAP_PRIVATE = global i32 0
define i8* @xmm_new(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
store i64 %0, i64* %2
store i8* null, i8** %3
%4 = load i64, i64* %2
%5 = icmp ugt i64 %4, 0
br i1 %5, label %6, label %37
6: ; preds = %1
%7 = load i64, i64* %2
%8 = icmp ult i64 %7, 4096
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i64, i64* %2
%11 = call i8* @calloc(i32 1, i64 %10)
store i8* %11, i8** %3
br label %36
12: ; preds = %6
%13 = load i64, i64* %2
%14 = udiv i64 %13, 4096
%15 = load i64, i64* %2
%16 = urem i64 %15, 4096
%17 = icmp ne i64 %16, 0
%18 = zext i1 %17 to i32
%19 = sext i32 %18 to i64
%20 = add i64 %14, %19
%21 = mul i64 %20, 4096
%22 = load i32, i32* @PROT_READ
%23 = load i32, i32* @PROT_WRITE
%24 = or i32 %22, %23
%25 = load i32, i32* @MAP_ANON
%26 = load i32, i32* @MAP_PRIVATE
%27 = or i32 %25, %26
%28 = call i8* @mmap(i32* null, i64 %21, i32 %24, i32 %27, i32 -1, i32 0)
store i8* %28, i8** %3
%29 = load i8*, i8** %3
%30 = icmp eq i8* %29, null
br i1 %30, label %34, label %31
31: ; preds = %12
%32 = load i8*, i8** %3
%33 = icmp eq i8* %32, inttoptr (i64 -1 to i8*)
br i1 %33, label %34, label %35
34: ; preds = %31, %12
store i8* null, i8** %3
br label %35
35: ; preds = %34, %31
br label %36
36: ; preds = %35, %9
br label %37
37: ; preds = %36, %1
%38 = load i8*, i8** %3
ret i8* %38
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANON = global i32 0
@MAP_PRIVATE = global i32 0
define i8* @xmm_new(i64 %0) {
%2 = icmp eq i64 %0, 0
br i1 %2, label %24, label %3
3: ; preds = %1
%4 = icmp ult i64 %0, 4096
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i8* @calloc(i32 1, i64 %0)
br label %24
7: ; preds = %3
%8 = and i64 %0, 4095
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i64 0, i64 4096
%11 = add i64 %10, %0
%12 = and i64 %11, -4096
%13 = load i32, i32* @PROT_READ
%14 = load i32, i32* @PROT_WRITE
%15 = or i32 %14, %13
%16 = load i32, i32* @MAP_ANON
%17 = load i32, i32* @MAP_PRIVATE
%18 = or i32 %17, %16
%19 = tail call i8* @mmap(i32* null, i64 %12, i32 %15, i32 %18, i32 -1, i32 0)
%20 = icmp eq i8* %19, null
%21 = icmp eq i8* %19, inttoptr (i64 -1 to i8*)
%22 = or i1 %20, %21
%23 = select i1 %22, i8* null, i8* %19
br label %24
24: ; preds = %7, %5, %1
%25 = phi i8* [ %6, %5 ], [ %23, %7 ], [ null, %1 ]
ret i8* %25
}