#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 /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ ENOMEM;
int /*<<< orphan*/ errno;
void *aligned_alloc(size_t align, size_t size) {
  if ((align & (align - 1)) || (size & (align - 1))) {
    errno = EINVAL;
    return NULL;
  }
  if (size > 0)
    errno = ENOMEM;
  return NULL;
}


x86 assembly (clang, -O0):
<aligned_alloc>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
jne    113e <aligned_alloc+0x3e>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     115d <aligned_alloc+0x5d>
mov    0x2e8b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e8a(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    1182 <aligned_alloc+0x82>
cmpq   $0x0,-0x18(%rbp)
jbe    117a <aligned_alloc+0x7a>
mov    0x2e71(%rip),%rax
mov    (%rax),%ecx
mov    0x2e60(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<aligned_alloc>:
lea    -0x1(%rdi),%rcx
mov    0x2ec5(%rip),%rax
test   %rcx,%rdi
jne    1121 <aligned_alloc+0x21>
test   %rsi,%rcx
jne    1121 <aligned_alloc+0x21>
test   %rsi,%rsi
je     112c <aligned_alloc+0x2c>
mov    0x2ebf(%rip),%rax
mov    (%rax),%eax
mov    0x2eae(%rip),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
@ENOMEM = global i32 0
define i8* @aligned_alloc(i64 %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
%6 = load i64, i64* %4
%7 = load i64, i64* %4
%8 = sub i64 %7, 1
%9 = and i64 %6, %8
%10 = icmp ne i64 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %2
%12 = load i64, i64* %5
%13 = load i64, i64* %4
%14 = sub i64 %13, 1
%15 = and i64 %12, %14
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11, %2
%18 = load i32, i32* @EINVAL
store i32 %18, i32* @errno
store i8* null, i8** %3
br label %25
19: ; preds = %11
%20 = load i64, i64* %5
%21 = icmp ugt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load i32, i32* @ENOMEM
store i32 %23, i32* @errno
br label %24
24: ; preds = %22, %19
store i8* null, i8** %3
br label %25
25: ; preds = %24, %17
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
@ENOMEM = global i32 0
define noalias i8* @aligned_alloc(i64 %0, i64 %1) {
%3 = tail call i64 @llvm.ctpop.i64(i64 %0)
%4 = icmp ult i64 %3, 2
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = add i64 %0, -1
%7 = and i64 %6, %1
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = icmp eq i64 %1, 0
br i1 %10, label %14, label %11
11: ; preds = %9, %2, %5
%12 = phi i32* [ @EINVAL, %5 ], [ @EINVAL, %2 ], [ @ENOMEM, %9 ]
%13 = load i32, i32* %12
store i32 %13, i32* @errno
br label %14
14: ; preds = %11, %9
ret i8* null
}