#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*/ debug_warning(char *, void *);
int h_check_padding(void *ptr, size_t size) {
  char *c_ptr = (char *)ptr;
  int check_success = 1;
  check_success &= *(c_ptr - 1) == 32;
  check_success &= *(c_ptr + size) == 32;
  if (!check_success) {
    debug_warning("[h_check_padding] memory padding check failed for ptr %X, "
                  "beware of memory corruption",
                  ptr);
  }
  return check_success;
}


x86 assembly (clang, -O0):
<h_check_padding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x20,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    117f <h_check_padding+0x6f>
mov    -0x8(%rbp),%rsi
lea    0xe86(%rip),%rdi
call   1030 <debug_warning@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<h_check_padding>:
push   %rbp
push   %rbx
push   %rax
mov    -0x1(%rdi),%cl
xor    $0x20,%cl
mov    (%rdi,%rsi,1),%dl
xor    $0x20,%dl
xor    %ebx,%ebx
or     %cl,%dl
sete   %bpl
je     113b <h_check_padding+0x2b>
mov    %rdi,%rax
lea    0xecd(%rip),%rdi
mov    %rax,%rsi
call   1030 <debug_warning@plt>
mov    %bpl,%bl
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [86 x i8] c"[h_check_padding] memory padding check failed for ptr %X, beware of memory corruption\00"
define i32 @h_check_padding(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i8*, i8** %3
store i8* %7, i8** %5
store i32 1, i32* %6
%8 = load i8*, i8** %5
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 32
%13 = zext i1 %12 to i32
%14 = load i32, i32* %6
%15 = and i32 %14, %13
store i32 %15, i32* %6
%16 = load i8*, i8** %5
%17 = load i64, i64* %4
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 32
%22 = zext i1 %21 to i32
%23 = load i32, i32* %6
%24 = and i32 %23, %22
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %2
%28 = load i8*, i8** %3
%29 = call i32 @debug_warning(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %2
%31 = load i32, i32* %6
ret i32 %31
}

LLVM IR (-O2):
@.str = [86 x i8] c"[h_check_padding] memory padding check failed for ptr %X, beware of memory corruption\00"
define i32 @h_check_padding(i8* %0, i64 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 -1
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 32
%6 = getelementptr inbounds i8, i8* %0, i64 %1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 32
%9 = and i1 %5, %8
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @debug_warning(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %10, %2
%13 = zext i1 %9 to i32
ret i32 %13
}