#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 */
typedef int ptrdiff_t;

/* Variables and functions */
int /*<<< orphan*/ _mm_free(void *);
void *_mm_malloc(int, int);
int /*<<< orphan*/ abort();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ memcmp(void *, char const *, int);
int /*<<< orphan*/ memcpy(void *, char const *, int);
int main() {
  int alignment, n;
  void *ptr;
  int errors = 0;
  const char test[] = "This is a test.";
  for (alignment = 1; alignment <= (1 << 20); alignment += alignment) {
    ptr = _mm_malloc(alignment, alignment);
    if (((ptrdiff_t)ptr) & (alignment - 1))
      abort();
    if (ptr) {
      n = alignment > sizeof test ? sizeof test : alignment;
      memcpy(ptr, test, n);
      if (memcmp(ptr, test, n) != 0)
        errors++;
      _mm_free(ptr);
    } else
      errors++;
  }
  if (errors != 0)
    abort();
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0xe83(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe80(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0x100000,-0x8(%rbp)
jg     125e <main+0xfe>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1070 <_mm_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11cb <main+0x6b>
mov    $0x0,%al
call   1030 <abort@plt>
cmpq   $0x0,-0x18(%rbp)
je     1242 <main+0xe2>
movslq -0x8(%rbp),%rax
cmp    $0x10,%rax
jbe    11f2 <main+0x92>
mov    $0x10,%eax
mov    %rax,-0x38(%rbp)
jmp    11fa <main+0x9a>
movslq -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     1234 <main+0xd4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <_mm_free@plt>
jmp    124b <main+0xeb>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1250 <main+0xf0>
mov    -0x8(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1193 <main+0x33>
cmpl   $0x0,-0x1c(%rbp)
je     126f <main+0x10f>
mov    $0x0,%al
call   1030 <abort@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movaps 0xe8d(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    $0x1,%r15d
xor    %r12d,%r12d
mov    %rsp,%r14
jmp    11db <main+0x7b>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x10,%r15d
mov    $0x10,%ebp
cmovb  %r15d,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <memcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %rbx,%rdi
call   1080 <_mm_free@plt>
add    %ebp,%r12d
lea    (%r15,%r15,1),%eax
cmp    $0x80001,%r15d
mov    %eax,%r15d
jge    11fd <main+0x9d>
mov    %r15d,%edi
mov    %r15d,%esi
call   1070 <_mm_malloc@plt>
mov    %rax,%rbx
lea    -0x1(%r15),%eax
test   %ebx,%eax
jne    1209 <main+0xa9>
test   %rbx,%rbx
jne    1190 <main+0x30>
mov    $0x1,%ebp
jmp    11c8 <main+0x68>
test   %r12d,%r12d
jne    1209 <main+0xa9>
xor    %edi,%edi
call   1060 <exit@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@__const.main.test = [16 x i8] c"This is a test.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [16 x i8]
store i32 0, i32* %1
store i32 0, i32* %5
%7 = bitcast [16 x i8]* %6 to i8*
store i32 1, i32* %2
br label %8
8: ; preds = %56, %0
%9 = load i32, i32* %2
%10 = icmp sle i32 %9, 1048576
br i1 %10, label %11, label %60
11: ; preds = %8
%12 = load i32, i32* %2
%13 = load i32, i32* %2
%14 = call i8* @_mm_malloc(i32 %12, i32 %13)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = ptrtoint i8* %15 to i32
%17 = load i32, i32* %2
%18 = sub nsw i32 %17, 1
%19 = and i32 %16, %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %11
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %11
%24 = load i8*, i8** %4
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %52
26: ; preds = %23
%27 = load i32, i32* %2
%28 = sext i32 %27 to i64
%29 = icmp ugt i64 %28, 16
br i1 %29, label %30, label %31
30: ; preds = %26
br label %34
31: ; preds = %26
%32 = load i32, i32* %2
%33 = sext i32 %32 to i64
br label %34
34: ; preds = %31, %30
%35 = phi i64 [ 16, %30 ], [ %33, %31 ]
%36 = trunc i64 %35 to i32
store i32 %36, i32* %3
%37 = load i8*, i8** %4
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%39 = load i32, i32* %3
%40 = call i32 @memcpy(i8* %37, i8* %38, i32 %39)
%41 = load i8*, i8** %4
%42 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%43 = load i32, i32* %3
%44 = call i64 @memcmp(i8* %41, i8* %42, i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %34
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
store i32 %48, i32* %5
br label %49
49: ; preds = %46, %34
%50 = load i8*, i8** %4
%51 = call i32 @_mm_free(i8* %50)
br label %55
52: ; preds = %23
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %55
55: ; preds = %52, %49
br label %56
56: ; preds = %55
%57 = load i32, i32* %2
%58 = load i32, i32* %2
%59 = add nsw i32 %58, %57
store i32 %59, i32* %2
br label %8
60: ; preds = %8
%61 = load i32, i32* %5
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %60
%64 = call i32 (...) @abort()
unreachable
65: ; preds = %60
%66 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@__const.main.test = [16 x i8] c"This is a test.\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %24
%4 = phi i32 [ 0, %0 ], [ %26, %24 ]
%5 = phi i32 [ 1, %0 ], [ %27, %24 ]
%6 = call i8* @_mm_malloc(i32 %5, i32 %5)
%7 = ptrtoint i8* %6 to i64
%8 = trunc i64 %7 to i32
%9 = add nsw i32 %5, -1
%10 = and i32 %9, %8
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i32 (...) @abort()
unreachable
14: ; preds = %3
%15 = icmp eq i8* %6, null
br i1 %15, label %24, label %16
16: ; preds = %14
%17 = icmp ult i32 %5, 16
%18 = select i1 %17, i32 %5, i32 16
%19 = call i32 @memcpy(i8* %6, i8* %2, i32 %18)
%20 = call i64 @memcmp(i8* %6, i8* %2, i32 %18)
%21 = icmp ne i64 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @_mm_free(i8* %6)
br label %24
24: ; preds = %14, %16
%25 = phi i32 [ %22, %16 ], [ 1, %14 ]
%26 = add nuw nsw i32 %25, %4
%27 = shl nsw i32 %5, 1
%28 = icmp slt i32 %5, 524289
br i1 %28, label %3, label %29
29: ; preds = %24
%30 = icmp eq i32 %26, 0
br i1 %30, label %33, label %31
31: ; preds = %29
%32 = call i32 (...) @abort()
unreachable
33: ; preds = %29
%34 = call i32 @exit(i32 0)
unreachable
}