#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*/ aligned_free(void *);
void *aligned_malloc(int, int);
int test_aligned_malloc() {
  void *ptr2 = aligned_malloc(100, 2);
  void *ptr8 = aligned_malloc(100, 8);
  void *ptr16 = aligned_malloc(100, 16);
  void *ptr128 = aligned_malloc(100, 128);
  void *ptr1024 = aligned_malloc(100, 1024);
  int ret = 0 == (((size_t)ptr2) % 2) && 0 == (((size_t)ptr8) % 8) &&
            0 == (((size_t)ptr16) % 16) && 0 == (((size_t)ptr128) % 128) &&
            0 == (((size_t)ptr1024) % 1024);
  aligned_free(ptr2);
  aligned_free(ptr8);
  aligned_free(ptr16);
  aligned_free(ptr128);
  aligned_free(ptr1024);
  return ret;
}


x86 assembly (clang, -O0):
<test_aligned_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x64,%edi
mov    $0x2,%esi
call   1040 <aligned_malloc@plt>
mov    %rax,-0x8(%rbp)
mov    $0x64,%edi
mov    $0x8,%esi
call   1040 <aligned_malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x64,%edi
mov    $0x10,%esi
call   1040 <aligned_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x64,%edi
mov    $0x80,%esi
call   1040 <aligned_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x64,%edi
mov    $0x400,%esi
call   1040 <aligned_malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdx
and    $0x1,%rdx
xor    %eax,%eax
xor    %ecx,%ecx
cmp    %rdx,%rcx
mov    %al,-0x2d(%rbp)
jne    11fd <test_aligned_malloc+0xdd>
mov    -0x10(%rbp),%rdx
and    $0x7,%rdx
xor    %eax,%eax
xor    %ecx,%ecx
cmp    %rdx,%rcx
mov    %al,-0x2d(%rbp)
jne    11fd <test_aligned_malloc+0xdd>
mov    -0x18(%rbp),%rdx
and    $0xf,%rdx
xor    %eax,%eax
xor    %ecx,%ecx
cmp    %rdx,%rcx
mov    %al,-0x2d(%rbp)
jne    11fd <test_aligned_malloc+0xdd>
mov    -0x20(%rbp),%rdx
and    $0x7f,%rdx
xor    %eax,%eax
xor    %ecx,%ecx
cmp    %rdx,%rcx
mov    %al,-0x2d(%rbp)
jne    11fd <test_aligned_malloc+0xdd>
mov    -0x28(%rbp),%rcx
and    $0x3ff,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <aligned_free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <aligned_free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <aligned_free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <aligned_free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <aligned_free@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_aligned_malloc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x64,%edi
mov    $0x2,%esi
call   1040 <aligned_malloc@plt>
mov    %rax,%r14
mov    $0x64,%edi
mov    $0x8,%esi
call   1040 <aligned_malloc@plt>
mov    %rax,%r15
mov    $0x64,%edi
mov    $0x10,%esi
call   1040 <aligned_malloc@plt>
mov    %rax,%r12
mov    $0x64,%edi
mov    $0x80,%esi
call   1040 <aligned_malloc@plt>
mov    %rax,%r13
mov    $0x64,%edi
mov    $0x400,%esi
call   1040 <aligned_malloc@plt>
mov    %rax,%rbx
mov    %r14d,%eax
and    $0x1,%eax
mov    %r15d,%ecx
and    $0x7,%ecx
or     %rax,%rcx
mov    %r12d,%eax
and    $0xf,%eax
mov    %r13d,%edx
and    $0x7f,%edx
or     %rax,%rdx
or     %rcx,%rdx
mov    %ebx,%eax
and    $0x3ff,%eax
xor    %ebp,%ebp
or     %rdx,%rax
sete   %bpl
mov    %r14,%rdi
call   1030 <aligned_free@plt>
mov    %r15,%rdi
call   1030 <aligned_free@plt>
mov    %r12,%rdi
call   1030 <aligned_free@plt>
mov    %r13,%rdi
call   1030 <aligned_free@plt>
mov    %rbx,%rdi
call   1030 <aligned_free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @test_aligned_malloc() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = call i8* @aligned_malloc(i32 100, i32 2)
store i8* %7, i8** %1
%8 = call i8* @aligned_malloc(i32 100, i32 8)
store i8* %8, i8** %2
%9 = call i8* @aligned_malloc(i32 100, i32 16)
store i8* %9, i8** %3
%10 = call i8* @aligned_malloc(i32 100, i32 128)
store i8* %10, i8** %4
%11 = call i8* @aligned_malloc(i32 100, i32 1024)
store i8* %11, i8** %5
%12 = load i8*, i8** %1
%13 = ptrtoint i8* %12 to i64
%14 = urem i64 %13, 2
%15 = icmp eq i64 0, %14
br i1 %15, label %16, label %36
16: ; preds = %0
%17 = load i8*, i8** %2
%18 = ptrtoint i8* %17 to i64
%19 = urem i64 %18, 8
%20 = icmp eq i64 0, %19
br i1 %20, label %21, label %36
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = ptrtoint i8* %22 to i64
%24 = urem i64 %23, 16
%25 = icmp eq i64 0, %24
br i1 %25, label %26, label %36
26: ; preds = %21
%27 = load i8*, i8** %4
%28 = ptrtoint i8* %27 to i64
%29 = urem i64 %28, 128
%30 = icmp eq i64 0, %29
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = load i8*, i8** %5
%33 = ptrtoint i8* %32 to i64
%34 = urem i64 %33, 1024
%35 = icmp eq i64 0, %34
br label %36
36: ; preds = %31, %26, %21, %16, %0
%37 = phi i1 [ false, %26 ], [ false, %21 ], [ false, %16 ], [ false, %0 ], [ %35, %31 ]
%38 = zext i1 %37 to i32
store i32 %38, i32* %6
%39 = load i8*, i8** %1
%40 = call i32 @aligned_free(i8* %39)
%41 = load i8*, i8** %2
%42 = call i32 @aligned_free(i8* %41)
%43 = load i8*, i8** %3
%44 = call i32 @aligned_free(i8* %43)
%45 = load i8*, i8** %4
%46 = call i32 @aligned_free(i8* %45)
%47 = load i8*, i8** %5
%48 = call i32 @aligned_free(i8* %47)
%49 = load i32, i32* %6
ret i32 %49
}

LLVM IR (-O2):
define i32 @test_aligned_malloc() {
%1 = tail call i8* @aligned_malloc(i32 100, i32 2)
%2 = tail call i8* @aligned_malloc(i32 100, i32 8)
%3 = tail call i8* @aligned_malloc(i32 100, i32 16)
%4 = tail call i8* @aligned_malloc(i32 100, i32 128)
%5 = tail call i8* @aligned_malloc(i32 100, i32 1024)
%6 = ptrtoint i8* %1 to i64
%7 = and i64 %6, 1
%8 = icmp eq i64 %7, 0
%9 = ptrtoint i8* %2 to i64
%10 = and i64 %9, 7
%11 = icmp eq i64 %10, 0
%12 = select i1 %8, i1 %11, i1 false
%13 = ptrtoint i8* %3 to i64
%14 = and i64 %13, 15
%15 = icmp eq i64 %14, 0
%16 = select i1 %12, i1 %15, i1 false
%17 = ptrtoint i8* %4 to i64
%18 = and i64 %17, 127
%19 = icmp eq i64 %18, 0
%20 = select i1 %16, i1 %19, i1 false
%21 = ptrtoint i8* %5 to i64
%22 = and i64 %21, 1023
%23 = icmp eq i64 %22, 0
%24 = select i1 %20, i1 %23, i1 false
%25 = zext i1 %24 to i32
%26 = tail call i32 @aligned_free(i8* %1)
%27 = tail call i32 @aligned_free(i8* %2)
%28 = tail call i32 @aligned_free(i8* %3)
%29 = tail call i32 @aligned_free(i8* %4)
%30 = tail call i32 @aligned_free(i8* %5)
ret i32 %25
}