#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(size_t, size_t);
int /*<<< orphan*/ printf(char *, void *, size_t, size_t);
int main() {
  void *ptr;
  size_t size, align;
  size = 8;
  align = 128;
  ptr = aligned_malloc(size, align);
  aligned_free(ptr);
  if ((size_t)ptr % align)
    printf("WARNING: alignment not ok: size: %lu, align: %lu\n", ptr, size,
           align);
  else
    printf("OK: alignment is correct: %p, size: %lu, align: %lu\n", ptr, size,
           align);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x8,-0x18(%rbp)
movq   $0x80,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <aligned_malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <aligned_free@plt>
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
cmp    $0x0,%rdx
je     119c <main+0x6c>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
jmp    11b4 <main+0x84>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x8,%edi
mov    $0x80,%esi
call   1050 <aligned_malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <aligned_free@plt>
test   $0x7f,%bl
lea    0xedd(%rip),%rax
lea    0xea4(%rip),%rdi
cmove  %rax,%rdi
mov    $0x8,%edx
mov    $0x80,%ecx
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [50 x i8] c"WARNING: alignment not ok: size: %lu, align: %lu\0A\00"
@.str.1 = [53 x i8] c"OK: alignment is correct: %p, size: %lu, align: %lu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
store i32 0, i32* %1
store i64 8, i64* %3
store i64 128, i64* %4
%5 = load i64, i64* %3
%6 = load i64, i64* %4
%7 = call i8* @aligned_malloc(i64 %5, i64 %6)
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @aligned_free(i8* %8)
%10 = load i8*, i8** %2
%11 = ptrtoint i8* %10 to i64
%12 = load i64, i64* %4
%13 = urem i64 %11, %12
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %0
%16 = load i8*, i8** %2
%17 = load i64, i64* %3
%18 = load i64, i64* %4
%19 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %16, i64 %17, i64 %18)
br label %25
20: ; preds = %0
%21 = load i8*, i8** %2
%22 = load i64, i64* %3
%23 = load i64, i64* %4
%24 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %21, i64 %22, i64 %23)
br label %25
25: ; preds = %20, %15
ret i32 0
}

LLVM IR (-O2):
@.str = [50 x i8] c"WARNING: alignment not ok: size: %lu, align: %lu\0A\00"
@.str.1 = [53 x i8] c"OK: alignment is correct: %p, size: %lu, align: %lu\0A\00"
define i32 @main() {
%1 = tail call i8* @aligned_malloc(i64 8, i64 128)
%2 = tail call i32 @aligned_free(i8* %1)
%3 = ptrtoint i8* %1 to i64
%4 = and i64 %3, 127
%5 = icmp eq i64 %4, 0
%6 = select i1 %5, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0)
%7 = tail call i32 @printf(i8* %6, i8* %1, i64 8, i64 128)
ret i32 0
}