#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 */
scalar_t__ check_align(unsigned char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int ptr2long(unsigned char *);
int /*<<< orphan*/ set_value(unsigned char *, int);
int main() {
  unsigned char buff[1000];
  unsigned char *ptr = buff + (16 - (ptr2long(buff) % 16));
  int i;
  memset(buff, 0, 1000);
  printf("Base pointer: %p\n", ptr);
  for (i = 0; i < 20; i++)
    set_value(ptr + 16 * i, 1);
  for (i = 0; i < 1000; i++) {
    if (buff[i] && check_align(&buff[i])) {
      printf("Align check failed on %p\n", &buff[i]);
      exit(1);
    }
  }
  printf("Align check ok\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x3f0(%rbp),%rax
mov    %rax,-0x408(%rbp)
lea    -0x3f0(%rbp),%rdi
call   1040 <ptr2long@plt>
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    -0x408(%rbp),%rax
mov    $0x10,%ecx
sub    %edx,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x3f8(%rbp)
lea    -0x3f0(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1070 <memset@plt>
mov    -0x3f8(%rbp),%rsi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x3fc(%rbp)
cmpl   $0x14,-0x3fc(%rbp)
jge    1221 <main+0xc1>
mov    -0x3f8(%rbp),%rdi
mov    -0x3fc(%rbp),%eax
shl    $0x4,%eax
cltq
add    %rax,%rdi
mov    $0x1,%esi
call   1060 <set_value@plt>
mov    -0x3fc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3fc(%rbp)
jmp    11e1 <main+0x81>
movl   $0x0,-0x3fc(%rbp)
cmpl   $0x3e8,-0x3fc(%rbp)
jge    12b5 <main+0x155>
movslq -0x3fc(%rbp),%rax
movzbl -0x3f0(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     129c <main+0x13c>
movslq -0x3fc(%rbp),%rax
lea    -0x3f0(%rbp),%rdi
add    %rax,%rdi
call   1030 <check_align@plt>
cmp    $0x0,%rax
je     129c <main+0x13c>
movslq -0x3fc(%rbp),%rax
lea    -0x3f0(%rbp),%rsi
add    %rax,%rsi
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    12a1 <main+0x141>
mov    -0x3fc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3fc(%rbp)
jmp    122b <main+0xcb>
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3e8,%rsp
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <ptr2long@plt>
lea    0xf(%rax),%ebx
test   %eax,%eax
cmovns %eax,%ebx
and    $0xfffffff0,%ebx
sub    %eax,%ebx
add    $0x10,%ebx
lea    (%rsp,%rbx,1),%r12
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1080 <memset@plt>
lea    0xe4a(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x10,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x20,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x30,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x40,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x50,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x60,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x70,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x80,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x90,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0xa0,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0xb0,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0xc0,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0xd0,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0xe0,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0xf0,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x100,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x110,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x120,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x130,%rdi
mov    $0x1,%esi
call   1070 <set_value@plt>
jmp    135d <main+0x1ed>
nopl   0x0(%rax)
add    $0x1,%r15
cmp    $0x3e8,%r15
je     1390 <main+0x220>
cmpb   $0x0,(%rsp,%r15,1)
je     1350 <main+0x1e0>
lea    (%rsp,%r15,1),%rbx
mov    %rbx,%rdi
call   1030 <check_align@plt>
test   %rax,%rax
je     1350 <main+0x1e0>
lea    0xc96(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xc95(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Base pointer: %p\0A\00"
@.str.1 = [26 x i8] c"Align check failed on %p\0A\00"
@.str.2 = [16 x i8] c"Align check ok\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%7 = call i32 @ptr2long(i8* %6)
%8 = srem i32 %7, 16
%9 = sub nsw i32 16, %8
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %5, i64 %10
store i8* %11, i8** %3
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 1000)
%14 = load i8*, i8** %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 0, i32* %4
br label %16
16: ; preds = %26, %0
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 20
br i1 %18, label %19, label %29
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = mul nsw i32 16, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = call i32 @set_value(i8* %24, i32 1)
br label %26
26: ; preds = %19
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %16
29: ; preds = %16
store i32 0, i32* %4
br label %30
30: ; preds = %53, %29
%31 = load i32, i32* %4
%32 = icmp slt i32 %31, 1000
br i1 %32, label %33, label %56
33: ; preds = %30
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %52
40: ; preds = %33
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %42
%44 = call i64 @check_align(i8* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %40
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %40, %33
br label %53
53: ; preds = %52
%54 = load i32, i32* %4
%55 = add nsw i32 %54, 1
store i32 %55, i32* %4
br label %30
56: ; preds = %30
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%58 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [18 x i8] c"Base pointer: %p\0A\00"
@.str.1 = [26 x i8] c"Align check failed on %p\0A\00"
@str = [15 x i8] c"Align check ok\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = call i32 @ptr2long(i8* %2)
%4 = srem i32 %3, 16
%5 = sub nsw i32 16, %4
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %6
%8 = call i32 @memset(i8* %2, i32 0, i32 1000)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
%10 = call i32 @set_value(i8* %7, i32 1)
%11 = getelementptr inbounds i8, i8* %7, i64 16
%12 = call i32 @set_value(i8* %11, i32 1)
%13 = getelementptr inbounds i8, i8* %7, i64 32
%14 = call i32 @set_value(i8* %13, i32 1)
%15 = getelementptr inbounds i8, i8* %7, i64 48
%16 = call i32 @set_value(i8* %15, i32 1)
%17 = getelementptr inbounds i8, i8* %7, i64 64
%18 = call i32 @set_value(i8* %17, i32 1)
%19 = getelementptr inbounds i8, i8* %7, i64 80
%20 = call i32 @set_value(i8* %19, i32 1)
%21 = getelementptr inbounds i8, i8* %7, i64 96
%22 = call i32 @set_value(i8* %21, i32 1)
%23 = getelementptr inbounds i8, i8* %7, i64 112
%24 = call i32 @set_value(i8* %23, i32 1)
%25 = getelementptr inbounds i8, i8* %7, i64 128
%26 = call i32 @set_value(i8* %25, i32 1)
%27 = getelementptr inbounds i8, i8* %7, i64 144
%28 = call i32 @set_value(i8* %27, i32 1)
%29 = getelementptr inbounds i8, i8* %7, i64 160
%30 = call i32 @set_value(i8* %29, i32 1)
%31 = getelementptr inbounds i8, i8* %7, i64 176
%32 = call i32 @set_value(i8* %31, i32 1)
%33 = getelementptr inbounds i8, i8* %7, i64 192
%34 = call i32 @set_value(i8* %33, i32 1)
%35 = getelementptr inbounds i8, i8* %7, i64 208
%36 = call i32 @set_value(i8* %35, i32 1)
%37 = getelementptr inbounds i8, i8* %7, i64 224
%38 = call i32 @set_value(i8* %37, i32 1)
%39 = getelementptr inbounds i8, i8* %7, i64 240
%40 = call i32 @set_value(i8* %39, i32 1)
%41 = getelementptr inbounds i8, i8* %7, i64 256
%42 = call i32 @set_value(i8* %41, i32 1)
%43 = getelementptr inbounds i8, i8* %7, i64 272
%44 = call i32 @set_value(i8* %43, i32 1)
%45 = getelementptr inbounds i8, i8* %7, i64 288
%46 = call i32 @set_value(i8* %45, i32 1)
%47 = getelementptr inbounds i8, i8* %7, i64 304
%48 = call i32 @set_value(i8* %47, i32 1)
br label %49
49: ; preds = %0, %60
%50 = phi i64 [ 0, %0 ], [ %61, %60 ]
%51 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = icmp eq i8 %52, 0
br i1 %53, label %60, label %54
54: ; preds = %49
%55 = call i64 @check_align(i8* %51)
%56 = icmp eq i64 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %54
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %51)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %49, %54
%61 = add nuw nsw i64 %50, 1
%62 = icmp eq i64 %61, 1000
br i1 %62, label %63, label %49
63: ; preds = %60
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%65 = call i32 @exit(i32 0)
unreachable
}