#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 ENOMEM;
int /*<<< orphan*/ __asan_poison(void *, size_t, char);
int /*<<< orphan*/ assert(int);
int posix_memalign(void **, size_t, size_t);
void *__asan_malloc(size_t size) {
  ;
  size_t padding =
      ((((uintptr_t)(size) % ((size_t)1 << (3))) == 0))
          ? 0
          : ((size_t)1 << (3)) - ((uintptr_t)(size) % ((size_t)1 << (3)));
  size_t rz_left_size = (32);
  size_t rz_right_size = (32) + padding;
  void *rz_left;
  int err = posix_memalign(&rz_left, ((size_t)1 << (3)),
                           rz_left_size + size + rz_right_size);
  if (err != 0) {
    assert(err == ENOMEM);
    return NULL;
  }
  void *ret = rz_left + rz_left_size;
  void *rz_right = ret + size;
  __asan_poison(rz_left, rz_left_size, ((char)-2));
  __asan_poison(rz_right, rz_right_size, ((char)-2));
  *(void **)rz_left = rz_right;
  *(size_t *)rz_right = rz_right_size;
  assert((uintptr_t)ret % 8 == 0);
  return ret;
}


x86 assembly (clang, -O0):
<__asan_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    1159 <__asan_malloc+0x29>
xor    %eax,%eax
mov    %rax,-0x50(%rbp)
jmp    116d <__asan_malloc+0x3d>
mov    -0x10(%rbp),%rcx
and    $0x7,%rcx
mov    $0x8,%eax
sub    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x20,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdx
add    -0x10(%rbp),%rdx
add    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rdi
mov    $0x8,%esi
call   1050 <posix_memalign@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11d6 <__asan_malloc+0xa6>
mov    -0x34(%rbp),%eax
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movq   $0x0,-0x8(%rbp)
jmp    1249 <__asan_malloc+0x119>
mov    -0x30(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0xfffffffe,%edx
call   1040 <__asan_poison@plt>
mov    -0x48(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0xfffffffe,%edx
call   1040 <__asan_poison@plt>
mov    -0x48(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x48(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__asan_malloc>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
mov    %r15d,%eax
and    $0x7,%eax
mov    $0x28,%ecx
sub    %rax,%rcx
test   %rax,%rax
mov    $0x20,%ebx
cmovne %rcx,%rbx
lea    (%rdi,%rbx,1),%rdx
add    $0x20,%rdx
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
call   1050 <posix_memalign@plt>
test   %eax,%eax
je     1186 <__asan_malloc+0x56>
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
xor    %r14d,%r14d
jmp    11ce <__asan_malloc+0x9e>
mov    0x8(%rsp),%r12
lea    0x20(%r12),%r14
lea    (%r12,%r15,1),%r13
add    $0x20,%r13
mov    $0x20,%esi
mov    %r12,%rdi
mov    $0xfffffffe,%edx
call   1040 <__asan_poison@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0xfffffffe,%edx
call   1040 <__asan_poison@plt>
mov    0x8(%rsp),%rax
mov    %r13,(%rax)
mov    %rbx,0x20(%r12,%r15,1)
test   $0x7,%r14b
sete   %al
movzbl %al,%edi
call   1030 <assert@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ENOMEM = global i32 0
define i8* @__asan_malloc(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i64 %0, i64* %3
%11 = load i64, i64* %3
%12 = urem i64 %11, 8
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
br label %19
15: ; preds = %1
%16 = load i64, i64* %3
%17 = urem i64 %16, 8
%18 = sub i64 8, %17
br label %19
19: ; preds = %15, %14
%20 = phi i64 [ 0, %14 ], [ %18, %15 ]
store i64 %20, i64* %4
store i64 32, i64* %5
%21 = load i64, i64* %4
%22 = add i64 32, %21
store i64 %22, i64* %6
%23 = load i64, i64* %5
%24 = load i64, i64* %3
%25 = add i64 %23, %24
%26 = load i64, i64* %6
%27 = add i64 %25, %26
%28 = call i32 @posix_memalign(i8** %7, i64 8, i64 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %19
%32 = load i32, i32* %8
%33 = load i32, i32* @ENOMEM
%34 = icmp eq i32 %32, %33
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
store i8* null, i8** %2
br label %63
37: ; preds = %19
%38 = load i8*, i8** %7
%39 = load i64, i64* %5
%40 = getelementptr i8, i8* %38, i64 %39
store i8* %40, i8** %9
%41 = load i8*, i8** %9
%42 = load i64, i64* %3
%43 = getelementptr i8, i8* %41, i64 %42
store i8* %43, i8** %10
%44 = load i8*, i8** %7
%45 = load i64, i64* %5
%46 = call i32 @__asan_poison(i8* %44, i64 %45, i8 signext -2)
%47 = load i8*, i8** %10
%48 = load i64, i64* %6
%49 = call i32 @__asan_poison(i8* %47, i64 %48, i8 signext -2)
%50 = load i8*, i8** %10
%51 = load i8*, i8** %7
%52 = bitcast i8* %51 to i8**
store i8* %50, i8** %52
%53 = load i64, i64* %6
%54 = load i8*, i8** %10
%55 = bitcast i8* %54 to i64*
store i64 %53, i64* %55
%56 = load i8*, i8** %9
%57 = ptrtoint i8* %56 to i64
%58 = urem i64 %57, 8
%59 = icmp eq i64 %58, 0
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = load i8*, i8** %9
store i8* %62, i8** %2
br label %63
63: ; preds = %37, %31
%64 = load i8*, i8** %2
ret i8* %64
}

LLVM IR (-O2):
@ENOMEM = global i32 0
define i8* @__asan_malloc(i64 %0) {
%2 = alloca i8*
%3 = and i64 %0, 7
%4 = icmp eq i64 %3, 0
%5 = sub nuw nsw i64 40, %3
%6 = select i1 %4, i64 32, i64 %5
%7 = bitcast i8** %2 to i8*
%8 = add i64 %0, 32
%9 = add i64 %8, %6
%10 = call i32 @posix_memalign(i8** %2, i64 8, i64 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i32, i32* @ENOMEM
%14 = icmp eq i32 %10, %13
br label %27
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = getelementptr i8, i8* %16, i64 32
%18 = getelementptr i8, i8* %17, i64 %0
%19 = call i32 @__asan_poison(i8* %16, i64 32, i8 signext -2)
%20 = call i32 @__asan_poison(i8* %18, i64 %6, i8 signext -2)
%21 = bitcast i8** %2 to i8***
%22 = load i8**, i8*** %21
store i8* %18, i8** %22
%23 = bitcast i8* %18 to i64*
store i64 %6, i64* %23
%24 = ptrtoint i8* %17 to i64
%25 = and i64 %24, 7
%26 = icmp eq i64 %25, 0
br label %27
27: ; preds = %15, %12
%28 = phi i1 [ %26, %15 ], [ %14, %12 ]
%29 = phi i8* [ %17, %15 ], [ null, %12 ]
%30 = zext i1 %28 to i32
%31 = call i32 @assert(i32 %30)
ret i8* %29
}