#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*/ __bound_new_region(void *, size_t);
int /*<<< orphan*/ install_malloc_hooks();
void *memalign(size_t, size_t);
int /*<<< orphan*/ restore_malloc_hooks();
void *__bound_memalign(size_t size, size_t align, const void *caller) {
  void *ptr;
  restore_malloc_hooks();
  ptr = memalign(size + 1, align);
  install_malloc_hooks();
  if (!ptr)
    return NULL;
  __bound_new_region(ptr, size);
  return ptr;
}


x86 assembly (clang, -O0):
<__bound_memalign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x0,%al
call   1030 <restore_malloc_hooks@plt>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1050 <memalign@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <install_malloc_hooks@plt>
cmpq   $0x0,-0x28(%rbp)
jne    118f <__bound_memalign+0x4f>
movq   $0x0,-0x8(%rbp)
jmp    11a4 <__bound_memalign+0x64>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <__bound_new_region@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__bound_memalign>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <restore_malloc_hooks@plt>
lea    0x1(%r14),%rdi
mov    %rbx,%rsi
call   1050 <memalign@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <install_malloc_hooks@plt>
test   %rbx,%rbx
je     1177 <__bound_memalign+0x37>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <__bound_new_region@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @__bound_memalign(i64 %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
store i64 %0, i64* %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%9 = call i32 (...) @restore_malloc_hooks()
%10 = load i64, i64* %5
%11 = add i64 %10, 1
%12 = load i64, i64* %6
%13 = call i8* @memalign(i64 %11, i64 %12)
store i8* %13, i8** %8
%14 = call i32 (...) @install_malloc_hooks()
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %3
store i8* null, i8** %4
br label %23
18: ; preds = %3
%19 = load i8*, i8** %8
%20 = load i64, i64* %5
%21 = call i32 @__bound_new_region(i8* %19, i64 %20)
%22 = load i8*, i8** %8
store i8* %22, i8** %4
br label %23
23: ; preds = %18, %17
%24 = load i8*, i8** %4
ret i8* %24
}

LLVM IR (-O2):
define i8* @__bound_memalign(i64 %0, i64 %1, i8* nocapture readnone %2) {
%4 = tail call i32 (...) @restore_malloc_hooks()
%5 = add i64 %0, 1
%6 = tail call i8* @memalign(i64 %5, i64 %1)
%7 = tail call i32 (...) @install_malloc_hooks()
%8 = icmp eq i8* %6, null
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = tail call i32 @__bound_new_region(i8* %6, i64 %0)
br label %11
11: ; preds = %3, %9
ret i8* %6
}