#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*/ exit(int);
int getpagesize();
int munmap(char *, int);
void deallocate_protected_space(char *p, int size) {
  int page = getpagesize();
  int status;
  int aligned_size = ((size + page - 1) / page) * page;
  status = munmap(p - page, aligned_size + 2 * page);
  if (status != 0) {
    exit(1);
  }
}


x86 assembly (clang, -O0):
<deallocate_protected_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getpagesize@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
sub    $0x1,%eax
cltd
idivl  -0x10(%rbp)
imul   -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
add    %eax,%esi
call   1030 <munmap@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1194 <deallocate_protected_space+0x64>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deallocate_protected_space>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <getpagesize@plt>
mov    %eax,%ecx
lea    (%r14,%rcx,1),%esi
add    $0xffffffff,%esi
mov    %esi,%eax
cltd
idiv   %ecx
sub    %edx,%esi
movslq %ecx,%rax
sub    %rax,%rbx
lea    (%rsi,%rcx,2),%esi
mov    %rbx,%rdi
call   1030 <munmap@plt>
test   %eax,%eax
jne    116e <deallocate_protected_space+0x3e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
define void @deallocate_protected_space(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = call i32 (...) @getpagesize()
store i32 %8, i32* %5
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = add nsw i32 %9, %10
%12 = sub nsw i32 %11, 1
%13 = load i32, i32* %5
%14 = sdiv i32 %12, %13
%15 = load i32, i32* %5
%16 = mul nsw i32 %14, %15
store i32 %16, i32* %7
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = sub i64 0, %19
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = load i32, i32* %7
%23 = load i32, i32* %5
%24 = mul nsw i32 2, %23
%25 = add nsw i32 %22, %24
%26 = call i32 @munmap(i8* %21, i32 %25)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %2
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %2
ret void
}

LLVM IR (-O2):
define void @deallocate_protected_space(i8* %0, i32 %1) {
%3 = tail call i32 (...) @getpagesize()
%4 = add i32 %1, -1
%5 = add i32 %4, %3
%6 = srem i32 %5, %3
%7 = sub i32 %5, %6
%8 = sext i32 %3 to i64
%9 = sub nsw i64 0, %8
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = shl nsw i32 %3, 1
%12 = add nsw i32 %7, %11
%13 = tail call i32 @munmap(i8* %10, i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
ret void
}