#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 scalar_t__ bp;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void checkblock(void *bp) {
  if ((size_t)bp % 8)
    printf("Error: %p is not doubleword aligned\n", bp);
  if ((*(unsigned int *)(((char *)(bp)-4))) !=
      (*(unsigned int *)(((char *)(bp) +
                          ((*(unsigned int *)(((char *)(bp)-4))) & ~0x7) - 8))))
    printf("Error: header does not match footer\n");
}


x86 assembly (clang, -O0):
<checkblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
je     1140 <checkblock+0x30>
mov    -0x8(%rbp),%rsi
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x4(%rax),%eax
mov    -0x8(%rbp),%rcx
mov    -0x8(%rbp),%rdx
mov    -0x4(%rdx),%edx
and    $0xfffffff8,%edx
mov    %edx,%edx
cmp    -0x8(%rcx,%rdx,1),%eax
je     116f <checkblock+0x5f>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkblock>:
push   %rbx
mov    %rdi,%rbx
test   $0x7,%bl
je     113a <checkblock+0x1a>
lea    0xed0(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x4(%rbx),%eax
mov    %eax,%ecx
and    $0xfffffff8,%ecx
cmp    -0x8(%rbx,%rcx,1),%eax
jne    114a <checkblock+0x2a>
pop    %rbx
ret
lea    0xed4(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"Error: %p is not doubleword aligned\0A\00"
@.str.1 = [37 x i8] c"Error: header does not match footer\0A\00"
define void @checkblock(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = ptrtoint i8* %3 to i64
%5 = urem i64 %4, 8
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %7, %1
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 -4
%13 = bitcast i8* %12 to i32*
%14 = load i32, i32* %13
%15 = load i8*, i8** %2
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i64 -4
%18 = bitcast i8* %17 to i32*
%19 = load i32, i32* %18
%20 = and i32 %19, -8
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %15, i64 %21
%23 = getelementptr inbounds i8, i8* %22, i64 -8
%24 = bitcast i8* %23 to i32*
%25 = load i32, i32* %24
%26 = icmp ne i32 %14, %25
br i1 %26, label %27, label %29
27: ; preds = %10
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %10
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"Error: %p is not doubleword aligned\0A\00"
@str = [36 x i8] c"Error: header does not match footer\00"
define void @checkblock(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = and i64 %2, 7
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %7
7: ; preds = %5, %1
%8 = getelementptr inbounds i8, i8* %0, i64 -4
%9 = bitcast i8* %8 to i32*
%10 = load i32, i32* %9
%11 = and i32 %10, -8
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = getelementptr inbounds i8, i8* %13, i64 -8
%15 = bitcast i8* %14 to i32*
%16 = load i32, i32* %15
%17 = icmp eq i32 %10, %16
br i1 %17, label %20, label %18
18: ; preds = %7
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %18, %7
ret void
}